mirror of https://github.com/SeanOMik/libki.git
dml: Don't add fields with the same name but different types
This commit is contained in:
parent
ade0822747
commit
2dad97aded
|
@ -35,8 +35,14 @@ namespace dml
|
||||||
Field<ValueT> *add_field(std::string name, bool transferable = true)
|
Field<ValueT> *add_field(std::string name, bool transferable = true)
|
||||||
{
|
{
|
||||||
// Does this field already exist?
|
// Does this field already exist?
|
||||||
if (has_field<ValueT>(name))
|
if (has_field(name))
|
||||||
return get_field<ValueT>(name);
|
{
|
||||||
|
// Return nullptr if the type is not the same
|
||||||
|
auto *field = m_field_map.at(name);
|
||||||
|
if (!field->is_type<ValueT>())
|
||||||
|
return nullptr;
|
||||||
|
return dynamic_cast<Field<ValueT> *>(field);
|
||||||
|
}
|
||||||
|
|
||||||
// Create the field
|
// Create the field
|
||||||
auto *field = new Field<ValueT>(name, *this);
|
auto *field = new Field<ValueT>(name, *this);
|
||||||
|
@ -50,9 +56,9 @@ namespace dml
|
||||||
FieldList::const_iterator fields_begin() const;
|
FieldList::const_iterator fields_begin() const;
|
||||||
FieldList::const_iterator fields_end() const;
|
FieldList::const_iterator fields_end() const;
|
||||||
|
|
||||||
void write_to(std::ostream &ostream) const;
|
void write_to(std::ostream &ostream) const final;
|
||||||
void read_from(std::istream &istream);
|
void read_from(std::istream &istream) final;
|
||||||
size_t get_size() const;
|
size_t get_size() const final;
|
||||||
private:
|
private:
|
||||||
FieldList m_fields;
|
FieldList m_fields;
|
||||||
FieldNameMap m_field_map;
|
FieldNameMap m_field_map;
|
||||||
|
|
Loading…
Reference in New Issue