X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FSettings.hh;h=d31b57dcf763c2fe0d38b1f3f96cc1fa24583223;hp=653d4561dd1e2af4dd4b66ddcd1232b90b893f1d;hb=b357615aba1dbde81e3c6999366604e6001010a7;hpb=fdfba4553433b9b2804c2772c7645211b828c2ea diff --git a/src/Moof/Settings.hh b/src/Moof/Settings.hh index 653d456..d31b57d 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,58 +49,67 @@ namespace Mf { class Settings { public: - Settings() {} - Settings(int argc, char* argv[]); + + Settings() + { + mScript.importBaseLibrary(); + importLogFunctions(mScript); + } + + ~Settings(); // get global instance static Settings& getInstance(); 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 loadFromFile(const std::string& filePath); + void loadFromFiles(const std::vector& filePaths); + + void clear(); // remove all settings + + void saveAs(const std::string& filePath); + void save() const; template bool get(const std::string& key, T& value); - template - bool getNumber(const std::string& key, T& value); private: - Serializable::Map map_; + + Script mScript; + + std::string mUserFile; }; template bool Settings::get(const std::string& key, T& value) { - Serializable::Map::const_iterator it = map_.find(key); + Script::Slot top = mScript[-1]; + Script::Slot globals = mScript.getGlobalTable(); - if (it != map_.end()) - { - SerializableP 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) -{ - Serializable::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) { - SerializableP 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; }