[CONF] Resurrected config files

This commit is contained in:
emeric
2016-05-02 20:13:39 +02:00
parent 6f973096f3
commit 1034adac6c
5 changed files with 155 additions and 2 deletions
+2 -1
View File
@@ -3,7 +3,8 @@ bin_PROGRAMS = lms
lms_SOURCES = \
$(srcdir)/main/main.cpp \
$(srcdir)/av/AvInfo.cpp \
$(srcdir)/av/AvTranscoder.cpp \
$(srcdir)/av/AvTranscoder.cpp \
$(srcdir)/config/Config.cpp \
$(srcdir)/cover/CoverArtGrabber.cpp \
$(srcdir)/database/Artist.cpp \
$(srcdir)/database/DatabaseClassifier.cpp \
+99
View File
@@ -0,0 +1,99 @@
/*
* Copyright (C) 2016 Emeric Poupon
*
* This file is part of LMS.
*
* LMS 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.
*
* LMS 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 LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sstream>
#include "Config.hpp"
namespace {
}
Config::Config()
: _config (nullptr)
{
}
Config&
Config::instance()
{
static Config instance;
return instance;
}
void
Config::setFile(boost::filesystem::path p)
{
if (_config != nullptr)
delete _config;
_config = new libconfig::Config();
_config->readFile(p.string().c_str());
}
std::string
Config::getString(std::string setting, std::string def)
{
try {
return _config->lookup(setting);
}
catch (std::exception &e)
{
return def;
}
}
unsigned long
Config::getULong(std::string setting, unsigned long def)
{
try {
return static_cast<unsigned int>(_config->lookup(setting));
}
catch (...)
{
return def;
}
}
long
Config::getLong(std::string setting, long def)
{
try {
return _config->lookup(setting);
}
catch (...)
{
return def;
}
}
bool
Config::getBool(std::string setting, bool def)
{
try {
return _config->lookup(setting);
}
catch (...)
{
return def;
}
}
+48
View File
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2016 Emeric Poupon
*
* This file is part of LMS.
*
* LMS 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.
*
* LMS 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 LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <boost/filesystem.hpp>
#include <libconfig.h++>
class Config
{
public:
Config(const Config&) = delete;
Config& operator=(const Config&) = delete;
static Config& instance();
void setFile(boost::filesystem::path p);
// Default values are returned in case of setting not found
std::string getString(std::string setting, std::string def = "");
unsigned long getULong(std::string setting, unsigned long def = 0);
long getLong(std::string setting, long def = 0);
bool getBool(std::string setting, bool def = false);
private:
Config();
libconfig::Config *_config;
};