|
|
@ -1,10 +1,9 @@
|
|
|
|
#include "settings.hpp"
|
|
|
|
#include "settings.hpp"
|
|
|
|
#include "parser.hpp"
|
|
|
|
#include "parser.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
#include <components/debug/debuglog.hpp>
|
|
|
|
#include <sstream>
|
|
|
|
#include <components/misc/stringops.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
#include <components/misc/stringops.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
namespace Settings
|
|
|
|
namespace Settings
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -55,32 +54,20 @@ std::string Manager::getString(const std::string &setting, const std::string &ca
|
|
|
|
|
|
|
|
|
|
|
|
float Manager::getFloat (const std::string& setting, const std::string& category)
|
|
|
|
float Manager::getFloat (const std::string& setting, const std::string& category)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const std::string value = getString(setting, category);
|
|
|
|
const std::string& value = getString(setting, category);
|
|
|
|
try
|
|
|
|
std::stringstream stream(value);
|
|
|
|
{
|
|
|
|
float number = 0.f;
|
|
|
|
// We have to rely on Boost because std::stof from C++11 uses the current locale
|
|
|
|
stream >> number;
|
|
|
|
// for separators (which is undesired) and it often silently ignores parsing errors.
|
|
|
|
return number;
|
|
|
|
return boost::lexical_cast<float>(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (boost::bad_lexical_cast&)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Log(Debug::Warning) << "Cannot parse setting '" << setting << "' (invalid setting value: " << value << ").";
|
|
|
|
|
|
|
|
return 0.f;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Manager::getInt (const std::string& setting, const std::string& category)
|
|
|
|
int Manager::getInt (const std::string& setting, const std::string& category)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const std::string value = getString(setting, category);
|
|
|
|
const std::string& value = getString(setting, category);
|
|
|
|
try
|
|
|
|
std::stringstream stream(value);
|
|
|
|
{
|
|
|
|
int number = 0;
|
|
|
|
return std::stoi(value);
|
|
|
|
stream >> number;
|
|
|
|
}
|
|
|
|
return number;
|
|
|
|
catch(const std::exception& e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Log(Debug::Warning) << "Cannot parse setting '" << setting << "' (invalid setting value: " << value << ").";
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Manager::getBool (const std::string& setting, const std::string& category)
|
|
|
|
bool Manager::getBool (const std::string& setting, const std::string& category)
|
|
|
|