diff --git a/include/ki/dml/Field.h b/include/ki/dml/Field.h index b288909..6facc9a 100644 --- a/include/ki/dml/Field.h +++ b/include/ki/dml/Field.h @@ -116,6 +116,9 @@ namespace dml if (!value.empty()) set_value_from_string(value); } + + std::string get_value_string() const override final; + void set_value_from_string(std::string value) override final; private: ValueT m_value; @@ -126,7 +129,7 @@ namespace dml Field *clone() const override final { auto *clone = new Field(m_name); - clone->m_transferable = true; + clone->m_transferable = m_transferable; clone->m_value = m_value; return clone; } @@ -151,9 +154,6 @@ namespace dml throw value_error(oss.str()); } } - - std::string get_value_string() const; - void set_value_from_string(std::string value); }; typedef Field BytField; @@ -183,6 +183,18 @@ namespace dml iss >> m_value; } + template <> + std::string BytField::get_value_string() const; + + template <> + void BytField::set_value_from_string(std::string value); + + template <> + std::string UBytField::get_value_string() const; + + template <> + void UBytField::set_value_from_string(std::string value); + template <> std::string StrField::get_value_string() const; diff --git a/include/ki/dml/FieldBase.h b/include/ki/dml/FieldBase.h index 6f7cc6d..509bebe 100644 --- a/include/ki/dml/FieldBase.h +++ b/include/ki/dml/FieldBase.h @@ -53,6 +53,9 @@ namespace dml * Creates a new Field from XML data. */ static FieldBase *create_from_xml(const rapidxml::xml_node<> *node); + + virtual std::string get_value_string() const = 0; + virtual void set_value_from_string(std::string value) = 0; protected: std::string m_name; bool m_transferable; diff --git a/src/dml/types/BytField.cpp b/src/dml/types/BytField.cpp index a2b088d..7b0a0f4 100644 --- a/src/dml/types/BytField.cpp +++ b/src/dml/types/BytField.cpp @@ -38,5 +38,22 @@ namespace dml { return "BYT"; } + + template <> + std::string BytField::get_value_string() const + { + std::ostringstream oss; + oss << (int16_t)m_value; + return oss.str(); + } + + template <> + void BytField::set_value_from_string(std::string value) + { + std::istringstream iss(value); + int16_t temp = 0; + iss >> temp; + m_value = temp & 0xFF; + } } } \ No newline at end of file diff --git a/src/dml/types/UBytField.cpp b/src/dml/types/UBytField.cpp index e470230..0534c80 100644 --- a/src/dml/types/UBytField.cpp +++ b/src/dml/types/UBytField.cpp @@ -38,5 +38,22 @@ namespace dml { return "UBYT"; } + + template <> + std::string UBytField::get_value_string() const + { + std::ostringstream oss; + oss << (uint16_t)m_value; + return oss.str(); + } + + template <> + void UBytField::set_value_from_string(std::string value) + { + std::istringstream iss(value); + uint16_t temp = 0; + iss >> temp; + m_value = temp & 0xFF; + } } }