-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathconfiguration_config.hpp
107 lines (84 loc) · 3.21 KB
/
configuration_config.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*---------------------------------------------------------------------------*\
*
* bitpit
*
* Copyright (C) 2015-2021 OPTIMAD engineering Srl
*
* -------------------------------------------------------------------------
* License
* This file is part of bitpit.
*
* bitpit is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License v3 (LGPL)
* as published by the Free Software Foundation.
*
* bitpit is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with bitpit. If not, see <http://www.gnu.org/licenses/>.
*
\*---------------------------------------------------------------------------*/
#ifndef __BITPIT_CONFIGURATION_CONFIG_HPP__
#define __BITPIT_CONFIGURATION_CONFIG_HPP__
#include <memory>
#include <map>
#include <vector>
namespace bitpit {
// Configuration storage
class Config
{
public:
typedef Config Section;
typedef std::vector<Section *> MultiSection;
typedef std::vector<const Section *> ConstMultiSection;
typedef std::map<std::string, std::string> Options;
typedef std::multimap<std::string, std::unique_ptr<Config>> Sections;
Config(bool multiSections = false);
Config(const Config &other);
Config(Config &&other) = default;
Config & operator=(Config other);
Config & operator=(Config &&other) = default;
virtual ~Config() = default;
void swap(Config &other);
bool isMultiSectionsEnabled() const;
int getOptionCount() const;
Options & getOptions();
const Options & getOptions() const;
bool hasOption(const std::string &key) const;
const std::string & get(const std::string &key) const;
std::string get(const std::string &key, const std::string &fallback) const;
void set(const std::string &key, const std::string &value);
bool removeOption(const std::string &key);
int getSectionCount() const;
int getSectionCount(const std::string &key) const;
Sections & getSections();
const Sections & getSections() const;
MultiSection getSections(const std::string &key);
ConstMultiSection getSections(const std::string &key) const;
bool hasSection(const std::string &key) const;
Section & getSection(const std::string &key);
const Section & getSection(const std::string &key) const;
Section & addSection(const std::string &key);
bool removeSection(const std::string &key);
void clear();
void dump(std::ostream &out, int indentLevel = 0) const;
Section & operator[](const std::string &key);
const Section & operator[](const std::string &key) const;
template<typename T>
T get(const std::string &key) const;
template<typename T>
T get(const std::string &key, const T &fallback) const;
template<typename T>
void set(const std::string &key, const T &value);
protected:
bool m_multiSections;
private:
std::unique_ptr<Options> m_options;
std::unique_ptr<Sections> m_sections;
};
}
#include "configuration_config.tpp"
#endif