~thomas-voss/biometryd/remove-obsolete-configuration-header

« back to all changes in this revision

Viewing changes to src/util/configuration.h

  • Committer: Thomas Voß
  • Date: 2016-05-04 12:21:10 UTC
  • mfrom: (1.1.1 add-run-cmd)
  • Revision ID: thomas.voss@canonical.com-20160504122110-081v992eu2yka3zw
Merge lp:~thomas-voss/biometryd/add-run-cmd

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2016 Canonical, Ltd.
3
 
 *
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.
7
 
 *
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.
12
 
 *
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/>.
15
 
 *
16
 
 * Authored by: Thomas Voß <thomas.voss@canonical.com>
17
 
 *
18
 
 */
19
 
 
20
 
#ifndef UTIL_CONFIGURATION_H_
21
 
#define UTIL_CONFIGURATION_H_
22
 
 
23
 
#include <biometry/do_not_copy_or_move.h>
24
 
#include <util/variant.h>
25
 
 
26
 
#include <boost/filesystem.hpp>
27
 
 
28
 
#include <map>
29
 
#include <string>
30
 
 
31
 
namespace util
32
 
{
33
 
class Configuration
34
 
{
35
 
public:
36
 
    /// @cond
37
 
    class Node;
38
 
    typedef std::map<std::string, Node> Children;
39
 
    /// @endcond
40
 
 
41
 
    /// @brief Node represents a single named configuration value.
42
 
    class Node
43
 
    {
44
 
    public:
45
 
        /// @brief Node constructs a new instance with the given name,
46
 
        /// initializing the contained value to value.
47
 
        Node(const Variant& value = Variant{});
48
 
 
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);
53
 
 
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);
60
 
 
61
 
    private:
62
 
        Variant value_; ///< mutable value of the Node.
63
 
        Children children_; ///< mutable set of all children_ of this Node.
64
 
    };
65
 
 
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);
72
 
private:
73
 
    Children children_; ///< mutable set of all children_ of this Node.
74
 
};
75
 
 
76
 
/// @brief ConfigurationBuilder models loading of configuration from arbitrary sources.
77
 
class ConfigurationBuilder : public biometry::DoNotCopyOrMove
78
 
{
79
 
public:
80
 
    /// @brief build_configuration returns a Configuration instance.
81
 
    /// @throws in case of issues.
82
 
    virtual Configuration build_configuration() = 0;
83
 
 
84
 
protected:
85
 
    /// @cond
86
 
    ConfigurationBuilder() = default;
87
 
    /// @endcond
88
 
};
89
 
 
90
 
/// @brief JsonConfigurationBuilder implements ConfigurationBuilder for sources in JSON format.
91
 
class JsonConfigurationBuilder : public ConfigurationBuilder
92
 
{
93
 
public:
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;
98
 
 
99
 
private:
100
 
    boost::filesystem::path path;
101
 
};
102
 
}
103
 
 
104
 
#endif // UTIL_CONFIGURATION_H_