From 6883cae2ae86cb7a0b893a765fc72244b4a3482c Mon Sep 17 00:00:00 2001 From: Joshua Scott Date: Fri, 30 Mar 2018 21:34:06 +0100 Subject: [PATCH] dml: Documentation There's really not a lot worth documenting though. --- include/ki/dml/Field.h | 4 ++++ include/ki/dml/FieldBase.h | 7 +++++++ include/ki/dml/Record.h | 28 ++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/include/ki/dml/Field.h b/include/ki/dml/Field.h index 31e15c9..901c42b 100644 --- a/include/ki/dml/Field.h +++ b/include/ki/dml/Field.h @@ -36,6 +36,10 @@ namespace dml private: ValueT m_value; + /** + * Returns a new Field with the same name, transferability, + * type, and value but with a different owner Record. + */ Field *clone(const Record &record) const final { auto *clone = new Field(m_name, record); diff --git a/include/ki/dml/FieldBase.h b/include/ki/dml/FieldBase.h index 6969742..a9e789f 100644 --- a/include/ki/dml/FieldBase.h +++ b/include/ki/dml/FieldBase.h @@ -11,6 +11,9 @@ namespace dml { class Record; + /** + * An abstract base class for DML fields. + */ class FieldBase : public util::Serializable { friend Record; @@ -33,6 +36,10 @@ namespace dml FieldBase(std::string name, const Record& record); + /** + * Returns a new Field with the same name, transferability + * and value but with a different owner Record. + */ virtual FieldBase *clone(const Record &record) const = 0; private: const Record &m_record; diff --git a/include/ki/dml/Record.h b/include/ki/dml/Record.h index d3dd046..f48695d 100644 --- a/include/ki/dml/Record.h +++ b/include/ki/dml/Record.h @@ -6,6 +6,9 @@ namespace ki { namespace dml { + /** + * An ordered collection of DML fields. + */ class Record final : public util::Serializable { public: @@ -13,8 +16,16 @@ namespace dml Record(const Record &record); virtual ~Record(); + /** + * Returns true if a field of any type has the name + * specified. + */ bool has_field(std::string name) const; + /** + * Returns true if a field exists with the specified + * name and type. + */ template bool has_field(std::string name) const { @@ -23,6 +34,13 @@ namespace dml return m_field_map.at(name)->is_type(); } + /** + * Returns a previously added field with the specified name + * and type. + * + * If the field was not previously added, then a nullptr is + * returned. + */ template Field *get_field(std::string name) const { @@ -31,6 +49,16 @@ namespace dml return nullptr; } + /** + * Adds a new field to the record with the specified name, type, + * and transferability, and returns the newly created field. + * + * If a field already exists with the specified name and type, + * then the previously added field is returned. + * + * If a field already exists with the specified name, but the type + * differs, then a nullptr is returned. + */ template Field *add_field(std::string name, bool transferable = true) {