2
* Copyright (C) 2016 Canonical, Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Thomas Voß <thomas.voss@canonical.com>
20
#ifndef UTIL_CONFIGURATION_H_
21
#define UTIL_CONFIGURATION_H_
23
#include <biometry/do_not_copy_or_move.h>
24
#include <util/variant.h>
26
#include <boost/filesystem.hpp>
38
typedef std::map<std::string, Node> Children;
41
/// @brief Node represents a single named configuration value.
45
/// @brief Node constructs a new instance with the given name,
46
/// initializing the contained value to value.
47
Node(const Variant& value = Variant{});
49
/// @brief value returns an immutable reference to the contained value.
50
virtual const Variant& value() const;
51
/// @brief value adjusts the contained value.
52
virtual Node& value(const Variant& value);
54
/// @brief children returns the set of all children of this node.
55
virtual const Children& children() const;
56
/// @brief children returns a mutable reference to the children of this node.
57
virtual Children& children();
58
/// @brief Returns a mutable reference to the child with the given name.
59
Node& operator[](const std::string& name);
62
Variant value_; ///< mutable value of the Node.
63
Children children_; ///< mutable set of all children_ of this Node.
66
/// @brief children returns the set of all children of this node.
67
virtual const Children& children() const;
68
/// @brief children returns a mutable reference to the children of this node.
69
virtual Children& children();
70
/// @brief Returns a mutable reference to the child with the given name.
71
Node& operator[](const std::string& name);
73
Children children_; ///< mutable set of all children_ of this Node.
76
/// @brief ConfigurationBuilder models loading of configuration from arbitrary sources.
77
class ConfigurationBuilder : public biometry::DoNotCopyOrMove
80
/// @brief build_configuration returns a Configuration instance.
81
/// @throws in case of issues.
82
virtual Configuration build_configuration() = 0;
86
ConfigurationBuilder() = default;
90
/// @brief JsonConfigurationBuilder implements ConfigurationBuilder for sources in JSON format.
91
class JsonConfigurationBuilder : public ConfigurationBuilder
94
/// @brief JsonConfigurationBuilder creates a new instance for the given path.
95
JsonConfigurationBuilder(const boost::filesystem::path& path);
96
/// build_configuration returns a Configuration assembled from a JSON-formatted file.
97
Configuration build_configuration() override;
100
boost::filesystem::path path;
104
#endif // UTIL_CONFIGURATION_H_