Document

Interface

class Document : public erbsland::conf::Value

A configuration document.

Public Types

using FlatValueMap = std::map<NamePath, ConstValuePtr>

The flat map type mapping name paths to constant value pointers.

Maps each name path to the corresponding constant value in the document.

Public Functions

~Document() override = default

Default destructor.

virtual FlatValueMap toFlatValueMap() const noexcept = 0

Convert the value structure of this document into a flat map of values.

Returns:

A flat map with all sections and values of this document.

using erbsland::conf::DocumentPtr = std::shared_ptr<Document>
class DocumentBuilder

Builds Configuration Documents Programmatically

The document builder allows building the value trees of configuration documents programmatically. It expects a logical sequence of sections and values and raises exceptions on name collisions.

Details:

  • The correct document syntax is fully checked when adding values. If the resulting document would become erroneous, an Error (Syntax) is thrown.

  • Values can only be added to existing sections.

  • If you use a single name, when adding a value, it is automatically added to the last section.

  • If you use more than one name in the name path, it is added to the specified section.

  • When creating sections, this builder automatically creates intermediate sections and converts existing ones into section maps.

  • Name paths can be specified as text Name or NamePath objects.

Limitations:

  • You must not use indexes or text-indexes in name paths to access specific elements in lists.

  • This builder interface does not support adding locations to the elements.

Example usage:

DocumentPtr buildDocument() {
    DocumentBuilder builder;
    builder.addSectionMap(u8"main");
    builder.addValue(u8"value", String{"hello"});
    return builder.getDocumentAndReset();
}

Public Functions

DocumentBuilder() = default

Default constructor.

~DocumentBuilder() = default

Default destructor.

inline void addSectionMap(const NamePathLike &namePath)

Add a section map with the given name path to the document.

Parameters:

namePath – The name path of the element.

inline void addSectionList(const NamePathLike &namePath)

Add a section list with the given name path to the document.

Parameters:

namePath – The name path of the element.

template<typename T>
inline void addValue(const NamePathLike &namePath, const T &value)

Add a value to the document.

Parameters:
  • namePath – The name path of the element.

  • value – The value for the new element.

inline void addInteger(const NamePathLike &namePath, const Integer value)

Add an integer value to the document.

Parameters:
  • namePath – The name path of the element.

  • value – The integer value to add.

inline void addBoolean(const NamePathLike &namePath, const bool value)

Add a boolean value to the document.

Parameters:
  • namePath – The name path of the element.

  • value – The boolean value to add.

inline void addFloat(const NamePathLike &namePath, const Float value)

Add a float value to the document.

Parameters:
  • namePath – The name path of the element.

  • value – The floating-point value to add.

inline void addText(const NamePathLike &namePath, const String &value)

Add a text value to the document.

Parameters:
  • namePath – The name path of the element.

  • value – The text value to add.

inline void addDate(const NamePathLike &namePath, const Date &value)

Add a date value to the document.

Parameters:
  • namePath – The name path of the element.

  • value – The date value to add.

inline void addTime(const NamePathLike &namePath, const Time &value)

Add a time value to the document.

Parameters:
  • namePath – The name path of the element.

  • value – The time value to add.

inline void addDateTime(const NamePathLike &namePath, const DateTime &value)

Add a date-time value to the document.

Parameters:
  • namePath – The name path of the element.

  • value – The date-time value to add.

inline void addBytes(const NamePathLike &namePath, const Bytes &value)

Add a byte array value to the document.

Parameters:
  • namePath – The name path of the element.

  • value – The byte array value to add.

inline void addTimeDelta(const NamePathLike &namePath, const TimeDelta &value)

Add a time delta value to the document.

Parameters:
  • namePath – The name path of the element.

  • value – The time delta value to add.

inline void addRegEx(const NamePathLike &namePath, const RegEx &value)

Add a regular expression value to the document.

Parameters:
  • namePath – The name path of the element.

  • value – The regular expression to add.

inline void reset()

Reset the builder and discard the current document.

This will reset the builder into its initial state and discard any document that is currently being built.

inline DocumentPtr getDocumentAndReset()

Get the document and reset the builder.

This will finalize and return the currently built document and reset the builder into its initial state.

Returns:

The built document.