Loading...
Searching...
No Matches
configuration.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_HPP__
25#define __BITPIT_CONFIGURATION_HPP__
26
27#include <memory>
28#include <string>
29
30#include "bitpit_common.hpp"
31
32#include "configuration_common.hpp"
33#include "configuration_config.hpp"
34
35namespace bitpit {
36
37// Configuration file parser
38class ConfigParser : public Config
39{
40
41public:
42 ConfigParser(const std::string &rootName);
43 ConfigParser(const std::string &rootName, bool multiSections);
44 ConfigParser(const std::string &rootName, int version);
45 ConfigParser(const std::string &rootName, int version, bool multiSections);
46
47 void reset(const std::string &rootName);
48 void reset(const std::string &rootName, int version);
49 void reset(const std::string &rootName, int version, bool multiSections);
50
51 void read(const std::string &filename, bool append = true);
52 void read(config::SourceFormat format, const std::string &content, bool append = true);
53 void write(const std::string &filename) const;
54 void write(config::SourceFormat format, std::string *content) const;
55
56private:
57 BITPIT_PUBLIC_API static const int VERSION_UNDEFINED;
58
59 std::string m_rootName;
60
61 bool m_checkVersion;
62 int m_version;
63
64};
65
66// Global configuration file parser
68{
69
70public:
71 static GlobalConfigParser & parser();
72
73private:
74 static const std::string DEFAULT_ROOT_NAME;
75 static const int DEFAULT_VERSION;
76
77 static std::unique_ptr<GlobalConfigParser> m_parser;
78
80 GlobalConfigParser(const std::string &rootName, int version);
81 GlobalConfigParser(const std::string &rootName, bool multiSections);
82 GlobalConfigParser(const std::string &rootName, int version, bool multiSections);
83
85 GlobalConfigParser& operator=(GlobalConfigParser const&) = delete;
86
87};
88
89
95namespace config {
96
97 extern BITPIT_PUBLIC_API GlobalConfigParser & root;
98
99 void reset();
100 void reset(const std::string &rootName);
101 void reset(const std::string &rootName, int version);
102 void reset(const std::string &rootName, int version, bool multiSections);
103
104 void read(const std::string &filename, bool append = true);
105 void read(config::SourceFormat format, const std::string &content, bool append = true);
106 void write(const std::string &filename);
107 void write(config::SourceFormat format, std::string *content);
108
109};
110
111}
112
113#endif
Configuration file parser.
void write(const std::string &filename) const
ConfigParser(const std::string &rootName)
void read(const std::string &filename, bool append=true)
void reset(const std::string &rootName)
Configuration storage.
Global configuration file parser.
static GlobalConfigParser & parser()
void write(const std::string &filename)
GlobalConfigParser & root
void read(const std::string &filename, bool append)
--- layout: doxygen_footer ---