#include <boost/algorithm/string.hpp>
+#include "Log.hh"
#include "Settings.hh"
}
+Settings& Settings::getInstance()
+{
+ static Settings settings;
+ return settings;
+}
+
+
void Settings::parseArgs(int argc, char* argv[])
{
- for (int i = 1; i < argc; i++)
+ for (int i = 1; i < argc; ++i)
{
char* where = strchr(argv[i], (int)'=');
try
{
- SerializablePtr value(deserializer.deserialize());
+ SerializableP value(deserializer.deserialize());
map_[key] = value;
}
catch (std::exception e)
{
// it doesn't deserialize to anything we know, so just store it
// as a string
- map_[key] = SerializablePtr(new SerializableString(stringValue));
+ map_[key] = SerializableP(new SerializableBasic<Serializable::String>(stringValue));
}
}
}
char* home = getenv("HOME");
- for (it = filePaths.begin(); it != filePaths.end(); it++)
+ for (it = filePaths.begin(); it != filePaths.end(); ++it)
{
std::string path = *it;
if (home)
{
- boost::replace_first(path, "$HOME", home);
+ boost::replace_all(path, "$HOME", home);
}
- Deserializer deserializer(*it, true);
-
- std::cout << "Looking for a config file at " << path << std::endl;
try
{
- SerializablePtr obj = deserializer.deserialize();
- std::map<std::string,SerializablePtr> map;
+ Deserializer deserializer(*it, true);
+
+ SerializableP obj = deserializer.deserialize();
+ Serializable::Map map;
+
if (obj && obj->get(map))
{
if (!precedence)
}
catch (Deserializer::Exception e)
{
- std::cerr << "Cannot load settings from " << *it <<
- " because an exception was thrown: " << e.what() << std::endl;
+ logWarning("cannot load settings from %s because an exception was"
+ "thrown: %s", (*it).c_str(), e.what());
}
}
}