From a6160dc890262bbf4a0504ec3a3df6556275c60e Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Thu, 30 Nov 2017 14:07:47 +0100 Subject: libconfig test --- lib/settings/configuration.h | 92 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 lib/settings/configuration.h (limited to 'lib/settings/configuration.h') diff --git a/lib/settings/configuration.h b/lib/settings/configuration.h new file mode 100644 index 0000000..e0f1872 --- /dev/null +++ b/lib/settings/configuration.h @@ -0,0 +1,92 @@ +/******************************************************************************* + ** + ** 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 . + ** + ******************************************************************************/ + +#ifndef SETTINGS_H +#define SETTINGS_H + +#include +#include + +namespace libconfig { +class Config; +class Setting; +} + +class Configuration +{ +public: + Configuration(); + ~Configuration(); + + bool readUserConfiguration(const std::string &path); + bool readDefaultConfiguration(const std::string &data); + + std::vector children(const char *name = ""); + + template + std::optional value(const char* path) const; + + template + 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; +}; + +// instantiate functions +// this needs to be done because the implementation is in the cpp file + +// Settings::value<> +extern template std::optional Configuration::value(const char* path) const; +extern template std::optional Configuration::value(const char* path) const; +extern template std::optional Configuration::value(const char* path) const; +extern template std::optional Configuration::value(const char* path) const; + +extern template std::optional Configuration::value(const char* path) const; +extern template std::optional Configuration::value(const char* path) const; + +extern template std::optional Configuration::value(const char* path) const; +extern template std::optional Configuration::value(const char* path) const; + +extern template std::optional Configuration::value(const char* path) const; + +extern template std::optional Configuration::value(const char* path) const; + +// Settings::setValue<> +extern template void Configuration::setValue(std::string path, const int &val); +extern template void Configuration::setValue(std::string path, const unsigned int &val); +extern template void Configuration::setValue(std::string path, const long &val); +extern template void Configuration::setValue(std::string path, const unsigned long &val); + +extern template void Configuration::setValue(std::string path, const long long &val); +extern template void Configuration::setValue(std::string path, const unsigned long long &val); + +extern template void Configuration::setValue(std::string path, const float &val); +extern template void Configuration::setValue(std::string path, const double &val); + +extern template void Configuration::setValue(std::string path, const bool &val); + +extern template void Configuration::setValue(std::string path, const std::string &val); + +#endif // SETTINGS_H -- cgit v1.2.1