From 2dad97aded5b454cdba33f072ca3891df759c8a1 Mon Sep 17 00:00:00 2001 From: Joshua Scott Date: Fri, 30 Mar 2018 16:37:17 +0100 Subject: [PATCH] dml: Don't add fields with the same name but different types --- include/ki/dml/Record.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/include/ki/dml/Record.h b/include/ki/dml/Record.h index 4cfec78..d3dd046 100644 --- a/include/ki/dml/Record.h +++ b/include/ki/dml/Record.h @@ -35,8 +35,14 @@ namespace dml Field *add_field(std::string name, bool transferable = true) { // Does this field already exist? - if (has_field(name)) - return get_field(name); + if (has_field(name)) + { + // Return nullptr if the type is not the same + auto *field = m_field_map.at(name); + if (!field->is_type()) + return nullptr; + return dynamic_cast *>(field); + } // Create the field auto *field = new Field(name, *this); @@ -50,9 +56,9 @@ namespace dml FieldList::const_iterator fields_begin() const; FieldList::const_iterator fields_end() const; - void write_to(std::ostream &ostream) const; - void read_from(std::istream &istream); - size_t get_size() const; + void write_to(std::ostream &ostream) const final; + void read_from(std::istream &istream) final; + size_t get_size() const final; private: FieldList m_fields; FieldNameMap m_field_map;