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
|
/*******************************************************************************
**
** nyamp: yet another media player
** Copyright (C) 2017 Aqua-sama
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
******************************************************************************/
#ifndef CONFIGURATION_H
#define CONFIGURATION_H
#include <optional>
#include <vector>
namespace libconfig {
class Config;
class Setting;
}
class Configuration
{
public:
Configuration();
~Configuration();
bool readUserConfiguration(const std::string &path);
bool writeUserConfiguration(const std::string &path);
bool readDefaultConfiguration(const std::string &data);
std::vector<std::string> childrenSettings(const char *name = "");
std::vector<std::string> childrenGroups(const char *name = "");
template<typename T>
std::optional<T> value(const char* path) const;
template<typename T>
void setValue(std::string path, const T &val);
private:
libconfig::Config* getConfig(const char* path) const;
std::string m_userCfgPath;
libconfig::Config *m_userCfg;
libconfig::Config *m_defaultCfg;
};
// replace ~ with home
std::string& patchHome(std::string &path, const std::string &home);
// instantiate functions
// this needs to be done because the implementation is in the cpp file
// Settings::value<>
extern template std::optional<int> Configuration::value<int>(const char* path) const;
extern template std::optional<unsigned int> Configuration::value<unsigned int>(const char* path) const;
extern template std::optional<long> Configuration::value<long>(const char* path) const;
extern template std::optional<unsigned long> Configuration::value<unsigned long>(const char* path) const;
extern template std::optional<long long> Configuration::value<long long>(const char* path) const;
extern template std::optional<unsigned long long> Configuration::value<unsigned long long>(const char* path) const;
extern template std::optional<float> Configuration::value<float>(const char* path) const;
extern template std::optional<double> Configuration::value<double>(const char* path) const;
extern template std::optional<bool> Configuration::value<bool>(const char* path) const;
extern template std::optional<std::string> Configuration::value<std::string>(const char* path) const;
// Settings::setValue<>
extern template void Configuration::setValue<int>(std::string path, const int &val);
extern template void Configuration::setValue<unsigned int>(std::string path, const unsigned int &val);
extern template void Configuration::setValue<long>(std::string path, const long &val);
extern template void Configuration::setValue<unsigned long>(std::string path, const unsigned long &val);
extern template void Configuration::setValue<long long>(std::string path, const long long &val);
extern template void Configuration::setValue<unsigned long long>(std::string path, const unsigned long long &val);
extern template void Configuration::setValue<float>(std::string path, const float &val);
extern template void Configuration::setValue<double>(std::string path, const double &val);
extern template void Configuration::setValue<bool>(std::string path, const bool &val);
extern template void Configuration::setValue<std::string>(std::string path, const std::string &val);
#endif // CONFIGURATION_H
|