2018-03-26 20:39:10 +00:00
|
|
|
#pragma once
|
|
|
|
#include "FieldBase.h"
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
namespace ki
|
|
|
|
{
|
|
|
|
namespace dml
|
|
|
|
{
|
|
|
|
template <typename ValueT>
|
2018-03-29 15:06:20 +00:00
|
|
|
class Field final : public FieldBase
|
2018-03-26 20:39:10 +00:00
|
|
|
{
|
|
|
|
friend Record;
|
|
|
|
public:
|
2018-03-29 15:06:20 +00:00
|
|
|
virtual ~Field() = default;
|
2018-03-26 20:39:10 +00:00
|
|
|
|
2018-03-29 15:06:20 +00:00
|
|
|
ValueT get_value() const
|
|
|
|
{
|
|
|
|
return m_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_value(ValueT value)
|
|
|
|
{
|
|
|
|
m_value = value;
|
|
|
|
}
|
2018-03-26 20:39:10 +00:00
|
|
|
|
2018-03-29 15:06:20 +00:00
|
|
|
void write_to(std::ostream &ostream) const final;
|
|
|
|
void read_from(std::istream &istream) final;
|
|
|
|
size_t get_size() const final;
|
2018-03-26 20:39:10 +00:00
|
|
|
protected:
|
|
|
|
Field(std::string name, const Record &record)
|
|
|
|
: FieldBase(name, record)
|
|
|
|
{
|
|
|
|
m_type_hash = typeid(ValueT).hash_code();
|
|
|
|
m_value = ValueT();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
ValueT m_value;
|
2018-03-29 15:06:20 +00:00
|
|
|
|
2018-03-30 20:34:06 +00:00
|
|
|
/**
|
|
|
|
* Returns a new Field with the same name, transferability,
|
|
|
|
* type, and value but with a different owner Record.
|
|
|
|
*/
|
2018-03-29 15:06:20 +00:00
|
|
|
Field<ValueT> *clone(const Record &record) const final
|
|
|
|
{
|
|
|
|
auto *clone = new Field<ValueT>(m_name, record);
|
|
|
|
clone->m_transferable = true;
|
|
|
|
clone->m_value = m_value;
|
|
|
|
return clone;
|
|
|
|
}
|
2018-03-26 20:39:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef Field<BYT> BytField;
|
|
|
|
typedef Field<UBYT> UBytField;
|
|
|
|
typedef Field<SHRT> ShrtField;
|
|
|
|
typedef Field<USHRT> UShrtField;
|
|
|
|
typedef Field<INT> IntField;
|
|
|
|
typedef Field<UINT> UIntField;
|
|
|
|
typedef Field<STR> StrField;
|
|
|
|
typedef Field<WSTR> WStrField;
|
|
|
|
typedef Field<FLT> FltField;
|
|
|
|
typedef Field<DBL> DblField;
|
|
|
|
typedef Field<GID> GidField;
|
|
|
|
}
|
|
|
|
}
|