2018-03-26 20:39:10 +00:00
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
2018-03-29 15:06:20 +00:00
|
|
|
#include <typeinfo>
|
2018-03-31 19:22:42 +00:00
|
|
|
#include <rapidxml.hpp>
|
2018-03-26 20:39:10 +00:00
|
|
|
#include "../util/Serializable.h"
|
|
|
|
|
|
|
|
namespace ki
|
|
|
|
{
|
|
|
|
namespace dml
|
|
|
|
{
|
|
|
|
class Record;
|
|
|
|
|
2018-03-30 20:34:06 +00:00
|
|
|
/**
|
|
|
|
* An abstract base class for DML fields.
|
|
|
|
*/
|
2018-03-26 20:39:10 +00:00
|
|
|
class FieldBase : public util::Serializable
|
|
|
|
{
|
|
|
|
friend Record;
|
|
|
|
public:
|
2018-04-02 01:54:13 +00:00
|
|
|
FieldBase(std::string name);
|
2018-03-29 15:06:20 +00:00
|
|
|
virtual ~FieldBase() = default;
|
|
|
|
|
2018-03-26 20:39:10 +00:00
|
|
|
std::string get_name() const;
|
|
|
|
bool is_transferable() const;
|
|
|
|
|
|
|
|
template <typename ValueT>
|
|
|
|
bool is_type() const
|
|
|
|
{
|
|
|
|
return (typeid(ValueT).hash_code() == m_type_hash);
|
|
|
|
}
|
2018-03-31 19:22:42 +00:00
|
|
|
virtual const char *get_type_name() const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an XML node from this field's data.
|
|
|
|
*
|
|
|
|
* The document is only used to allocate necessary resources, and
|
|
|
|
* so the returned node has not been appended to the document.
|
|
|
|
*/
|
|
|
|
virtual rapidxml::xml_node<> *as_xml(rapidxml::xml_document<> &doc) const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads data from an XML Field node into this field.
|
|
|
|
* Example: <FieldName TYPE="STR">Value</FieldName>
|
|
|
|
*
|
|
|
|
* If the field in the XML data does not have the same type
|
|
|
|
* as this field, then an exception is thrown.
|
|
|
|
*/
|
|
|
|
virtual void from_xml(const rapidxml::xml_node<> *node) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new Field from XML data.
|
|
|
|
*/
|
2018-04-02 01:54:13 +00:00
|
|
|
static FieldBase *create_from_xml(const rapidxml::xml_node<> *node);
|
2018-03-26 20:39:10 +00:00
|
|
|
protected:
|
2018-03-29 15:06:20 +00:00
|
|
|
std::string m_name;
|
|
|
|
bool m_transferable;
|
2018-03-26 20:39:10 +00:00
|
|
|
size_t m_type_hash;
|
|
|
|
|
2018-03-30 20:34:06 +00:00
|
|
|
/**
|
|
|
|
* Returns a new Field with the same name, transferability
|
|
|
|
* and value but with a different owner Record.
|
|
|
|
*/
|
2018-04-02 01:54:13 +00:00
|
|
|
virtual FieldBase *clone() const = 0;
|
2018-03-31 19:22:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies the value of another Field into this one
|
|
|
|
* if the types are the same.
|
|
|
|
*/
|
|
|
|
virtual void set_value(FieldBase *other) = 0;
|
2018-03-26 20:39:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<FieldBase *> FieldList;
|
|
|
|
typedef std::map<std::string, FieldBase *> FieldNameMap;
|
|
|
|
}
|
|
|
|
}
|