dml: Fix some const-correctness problems

This commit is contained in:
Joshua Scott 2018-04-20 01:41:33 +01:00
parent 3922ca4b39
commit 802dfeba29
2 changed files with 26 additions and 3 deletions

View File

@ -34,7 +34,23 @@ 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; FieldBase *get_field(std::string name);
const FieldBase *get_field(std::string name) const;
/**
* Returns a previously added field with the specified name
* and type.
*
* If the field was not previously added, then a nullptr is
* returned.
*/
template <typename ValueT>
Field<ValueT> *get_field(std::string name)
{
if (has_field<ValueT>(name))
return dynamic_cast<Field<ValueT> *>(m_field_map.at(name));
return nullptr;
}
/** /**
* Returns a previously added field with the specified name * Returns a previously added field with the specified name
@ -44,7 +60,7 @@ namespace dml
* returned. * returned.
*/ */
template <typename ValueT> template <typename ValueT>
Field<ValueT> *get_field(std::string name) const const Field<ValueT> *get_field(std::string name) const
{ {
if (has_field<ValueT>(name)) if (has_field<ValueT>(name))
return dynamic_cast<Field<ValueT> *>(m_field_map.at(name)); return dynamic_cast<Field<ValueT> *>(m_field_map.at(name));

View File

@ -30,7 +30,14 @@ namespace dml
return m_field_map.count(name); return m_field_map.count(name);
} }
FieldBase *Record::get_field(std::string name) const FieldBase *Record::get_field(std::string name)
{
if (has_field(name))
return m_field_map.at(name);
return nullptr;
}
const FieldBase *Record::get_field(std::string name) const
{ {
if (has_field(name)) if (has_field(name))
return m_field_map.at(name); return m_field_map.at(name);