Template Class Config

Inheritance Relationships

Base Type

Class Documentation

template<typename ...FormatTs>
class uconfig::Config : public uconfig::Object

Configuration object.

tparam FormatTs

Types of the formatter to parse/emit.

Public Types

template<typename F>
using iface_type = ConfigIface<F>

Public Functions

Config(bool optional = false)

Constructor.

Parameters

[in] optional – If section considered to be optional (may be not initialized). Default false.

Config(const Config<FormatTs...> &other)

Copy constructor.

Config<FormatTs...> &operator=(const Config<FormatTs...> &other)

Copy assignment.

Config(Config<FormatTs...> &&other) noexcept

Move constructor.

Config<FormatTs...> &operator=(Config<FormatTs...> &&other) noexcept

Move assignment.

virtual ~Config() = default

Destructor.

template<typename F>
bool Parse(const F &parser, const std::string &path, const typename F::source_type *source, bool throw_on_fail = true)

Parse the config at path from source using parser.

Template Parameters

F – Type of the parser to use. Should be one of FormatTs.

Parameters
  • [in] parser – Parser instance to use.

  • [in] path – Path where the config resides in source.

  • [in] source – Source to parse from.

  • [in] throw_on_fail – Will throw an uconfig::ParseError is failed to parse all mandatory children. Default true.

Throws

uconfig::ParseError – Thrown if throw_on_fail.

Returns

true if config has been found in some form in the source, false otherwise.

template<typename F>
void Emit(const F &emitter, const std::string &path, typename F::dest_type *destination, bool throw_on_fail = true)

Emit the config at path to destination using emitter.

Template Parameters

F – Type of the emitter to use. Should be one of FormatTs.

Parameters
  • [in] emitter – Emitter instance to use.

  • [in] path – Path where the config should be in destination.

  • [in] destination – Destination to emit into.

  • [in] throw_on_fail – Will throw an uconfig::EmitError is failed to emit. Default true.

Throws

uconfig::EmitError – Thrown if throw_on_fail.

virtual bool Initialized() const noexcept override

Check if config has all mandatory values.

Returns

true if it has, false otherwise.

virtual bool Optional() const noexcept override

Check if config is marked as optional.

Returns

true if has been, false otherwise.

Protected Functions

virtual void Init(const std::string &config_path) = 0

Initialize config before parsing.

This function get called within Parse() and expected to register all variables in the config with respected paths. To register a variable call Register().

Parameters

[in] config_path – Path of this config for the Format.

template<typename F, typename T>
void Register(const std::string &element_path, T *element) noexcept

Register a child for this config.

This function should be called for all children of the config to get them parsed/emitted.

Template Parameters
Parameters
  • [in] element_path – Path of the child.

  • [in] element – Pointer to the child.

Friends

friend class ConfigIface