Merge branch 'master' into messaging

This commit is contained in:
Joshua Scott 2018-04-06 04:15:12 +01:00
commit 0a2997e3d7
6 changed files with 65 additions and 4 deletions

View File

@ -116,6 +116,9 @@ namespace dml
if (!value.empty()) if (!value.empty())
set_value_from_string(value); set_value_from_string(value);
} }
std::string get_value_string() const override final;
void set_value_from_string(std::string value) override final;
private: private:
ValueT m_value; ValueT m_value;
@ -126,7 +129,7 @@ namespace dml
Field<ValueT> *clone() const override final Field<ValueT> *clone() const override final
{ {
auto *clone = new Field<ValueT>(m_name); auto *clone = new Field<ValueT>(m_name);
clone->m_transferable = true; clone->m_transferable = m_transferable;
clone->m_value = m_value; clone->m_value = m_value;
return clone; return clone;
} }
@ -151,9 +154,6 @@ namespace dml
throw value_error(oss.str()); throw value_error(oss.str());
} }
} }
std::string get_value_string() const;
void set_value_from_string(std::string value);
}; };
typedef Field<BYT> BytField; typedef Field<BYT> BytField;
@ -183,6 +183,18 @@ namespace dml
iss >> m_value; 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 <> template <>
std::string StrField::get_value_string() const; std::string StrField::get_value_string() const;

View File

@ -53,6 +53,9 @@ namespace dml
* Creates a new Field from XML data. * Creates a new Field from XML data.
*/ */
static FieldBase *create_from_xml(const rapidxml::xml_node<> *node); 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: protected:
std::string m_name; std::string m_name;
bool m_transferable; bool m_transferable;

View File

@ -34,6 +34,8 @@ namespace dml
return m_field_map.at(name)->is_type<ValueT>(); return m_field_map.at(name)->is_type<ValueT>();
} }
FieldBase *get_field(std::string name) const;
/** /**
* Returns a previously added field with the specified name * Returns a previously added field with the specified name
* and type. * and type.

View File

@ -30,6 +30,13 @@ namespace dml
return m_field_map.count(name); return m_field_map.count(name);
} }
FieldBase *Record::get_field(std::string name) const
{
if (has_field(name))
return m_field_map.at(name);
return nullptr;
}
size_t Record::get_field_count() const size_t Record::get_field_count() const
{ {
return m_fields.size(); return m_fields.size();
@ -103,6 +110,9 @@ namespace dml
for (auto *field_node = node->first_node(); for (auto *field_node = node->first_node();
field_node; field_node = field_node->next_sibling()) field_node; field_node = field_node->next_sibling())
{ {
if (field_node->type() != rapidxml::node_type::node_element)
continue;
FieldBase *field = FieldBase::create_from_xml(field_node); FieldBase *field = FieldBase::create_from_xml(field_node);
if (has_field(field->get_name())) if (has_field(field->get_name()))
{ {

View File

@ -38,5 +38,22 @@ namespace dml
{ {
return "BYT"; 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;
}
} }
} }

View File

@ -38,5 +38,22 @@ namespace dml
{ {
return "UBYT"; 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;
}
} }
} }