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