X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2FMoof%2FSettings.cc;h=6883ddc4f852d3edd4191957e81529f87f155c8a;hb=8ad81a8282ce6e9e488a453e6bcd05fbc09715dc;hp=ccf690af65e395f93142a08eb891cde8e7a31c77;hpb=16d1a05b0777e97a45c48e2874aa4e5cc791282e;p=chaz%2Fyoink diff --git a/src/Moof/Settings.cc b/src/Moof/Settings.cc index ccf690a..6883ddc 100644 --- a/src/Moof/Settings.cc +++ b/src/Moof/Settings.cc @@ -32,6 +32,7 @@ #include +#include "Log.hh" #include "Settings.hh" @@ -44,9 +45,16 @@ Settings::Settings(int argc, char* argv[]) } +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)'='); @@ -62,14 +70,14 @@ void Settings::parseArgs(int argc, char* argv[]) 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(stringValue)); } } } @@ -91,21 +99,21 @@ void Settings::loadFromFiles(const std::vector& filePaths, 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); } try { Deserializer deserializer(*it, true); - SerializablePtr obj = deserializer.deserialize(); - std::map map; + SerializableP obj = deserializer.deserialize(); + Serializable::Map map; if (obj && obj->get(map)) { @@ -122,8 +130,8 @@ void Settings::loadFromFiles(const std::vector& filePaths, } 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()); } } }