X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FSettings.hh;h=d4cbb9fa0cd47e0a06a0f21a4ea5a3923f6a5d7d;hp=faad547c86f20820e91cbe80a1b5a88b87d32d49;hb=3f6e44698c38b74bb622ad81ea9d2daa636981d2;hpb=a5f0d391406a68275b41448fc3f49e8d8396c497 diff --git a/src/Moof/Settings.hh b/src/Moof/Settings.hh index faad547..d4cbb9f 100644 --- a/src/Moof/Settings.hh +++ b/src/Moof/Settings.hh @@ -34,10 +34,13 @@ * Load, store, save program settings. */ -#include #include +#include -#include +#include + +#include +#include namespace Mf { @@ -46,61 +49,70 @@ namespace Mf { class Settings { public: - Settings() {} - Settings(int argc, char* argv[]); - // get global instance - static Settings& getInstance(); + Settings() + { + mScript.importBaseLibrary(); + importLogFunctions(mScript); + } + + ~Settings(); void parseArgs(int argc, char* argv[]); - void loadFromFile(const std::string& filePath, bool precedence = false); - void loadFromFiles(const std::vector& filePaths, - bool precedence = false); + void loadFromFiles(const std::string& path); + void loadFromFiles(const std::vector& path); + + void clear(); // remove all settings + + void saveAs(const std::string& path); + void save() const; template - bool get(const std::string& key, T& value); - template - bool getNumber(const std::string& key, T& value); + bool get(const std::string& key, T& value) const; private: - std::map map_; + + mutable Script mScript; + + std::string mUserFile; }; template -bool Settings::get(const std::string& key, T& value) +bool Settings::get(const std::string& key, T& value) const { - std::map::const_iterator it = map_.find(key); + Script::Slot top = mScript[-1]; + Script::Slot globals = mScript.getGlobalTable(); - if (it != map_.end()) - { - SerializablePtr obj = (*it).second; - return obj->get(value); - } - else - { - return false; - } -} + std::vector fields; + boost::split(fields, key, boost::is_any_of(".")); -template -bool Settings::getNumber(const std::string& key, T& value) -{ - std::map::const_iterator it = map_.find(key); + globals.pushCopy(); - if (it != map_.end()) + std::vector::iterator it; + for (it = fields.begin(); it != fields.end(); ++it) { - SerializablePtr obj = (*it).second; - return obj->getNumber(value); - } - else - { - return false; + if (top.isTable()) + { + top.pushField(*it); + } + else + { + mScript.clear(); + return false; + } } + + bool got = top.get(value); + mScript.clear(); + return got; } +extern Settings settings; + + } // namepsace Mf #endif // _MOOF_SETTINGS_HH_