2018-03-26 20:39:10 +00:00
|
|
|
#pragma once
|
|
|
|
#include "FieldBase.h"
|
|
|
|
#include "Field.h"
|
|
|
|
|
|
|
|
namespace ki
|
|
|
|
{
|
|
|
|
namespace dml
|
|
|
|
{
|
2018-03-29 15:06:20 +00:00
|
|
|
class Record final : public util::Serializable
|
2018-03-26 20:39:10 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Record();
|
|
|
|
Record(const Record &record);
|
2018-03-29 15:06:20 +00:00
|
|
|
virtual ~Record();
|
2018-03-26 20:39:10 +00:00
|
|
|
|
|
|
|
bool has_field(std::string name) const;
|
|
|
|
|
|
|
|
template <typename ValueT>
|
|
|
|
bool has_field(std::string name) const
|
|
|
|
{
|
|
|
|
if (!has_field(name))
|
|
|
|
return false;
|
2018-03-29 15:06:20 +00:00
|
|
|
return m_field_map.at(name)->is_type<ValueT>();
|
2018-03-26 20:39:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ValueT>
|
2018-03-29 15:06:20 +00:00
|
|
|
Field<ValueT> *get_field(std::string name) const
|
2018-03-26 20:39:10 +00:00
|
|
|
{
|
|
|
|
if (has_field<ValueT>(name))
|
2018-03-29 15:06:20 +00:00
|
|
|
return dynamic_cast<Field<ValueT> *>(m_field_map.at(name));
|
2018-03-26 20:39:10 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ValueT>
|
2018-03-29 15:06:20 +00:00
|
|
|
Field<ValueT> *add_field(std::string name, bool transferable = true)
|
2018-03-26 20:39:10 +00:00
|
|
|
{
|
2018-03-29 15:06:20 +00:00
|
|
|
// Does this field already exist?
|
2018-03-26 20:39:10 +00:00
|
|
|
if (has_field<ValueT>(name))
|
2018-03-29 15:06:20 +00:00
|
|
|
return get_field<ValueT>(name);
|
|
|
|
|
|
|
|
// Create the field
|
|
|
|
auto *field = new Field<ValueT>(name, *this);
|
|
|
|
field->m_transferable = transferable;
|
|
|
|
add_field(field);
|
2018-03-26 20:39:10 +00:00
|
|
|
return field;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t get_field_count() const;
|
|
|
|
|
2018-03-29 15:06:20 +00:00
|
|
|
FieldList::const_iterator fields_begin() const;
|
|
|
|
FieldList::const_iterator fields_end() const;
|
2018-03-26 20:39:10 +00:00
|
|
|
|
|
|
|
void write_to(std::ostream &ostream) const;
|
|
|
|
void read_from(std::istream &istream);
|
|
|
|
size_t get_size() const;
|
|
|
|
private:
|
|
|
|
FieldList m_fields;
|
|
|
|
FieldNameMap m_field_map;
|
2018-03-29 15:06:20 +00:00
|
|
|
|
|
|
|
void add_field(FieldBase *field);
|
2018-03-26 20:39:10 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|