dml: Fix bug with BYT/UBYT fields in XML

also made get_value_string and set_value_from_string public and part of the abstract base class.
This commit is contained in:
Joshua Scott 2018-04-05 17:37:59 +01:00
parent e2f6bd1655
commit 8d7348aa81
4 changed files with 53 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

@ -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;
}
} }
} }