X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2FMoof%2FSettings.hh;h=2a2a9267026e5475ddd5c0a1d11433da19767251;hb=7f3984f3f9524f5b6813e01ceb2fe576dadff94e;hp=faad547c86f20820e91cbe80a1b5a88b87d32d49;hpb=a5f0d391406a68275b41448fc3f49e8d8396c497;p=chaz%2Fyoink diff --git a/src/Moof/Settings.hh b/src/Moof/Settings.hh index faad547..2a2a926 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() : + mGlobals(mScript.getGlobalTable()), + mTop(mScript[-1]) + { + mScript.importBaseLibrary(); + importLogPrintFunction(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: - std::map map_; + + Script mScript; + Script::Slot mGlobals, mTop; + + std::string mUserFile; }; template bool Settings::get(const std::string& key, T& value) { - std::map::const_iterator it = map_.find(key); + std::vector fields; + boost::split(fields, key, boost::is_any_of(".")); - if (it != map_.end()) - { - SerializablePtr obj = (*it).second; - return obj->get(value); - } - else - { - return false; - } -} - -template -bool Settings::getNumber(const std::string& key, T& value) -{ - std::map::const_iterator it = map_.find(key); + mGlobals.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 (mTop.isTable()) + { + mTop.pushField(*it); + } + else + { + mScript.clear(); + return false; + } } + + bool got = mTop.get(value); + mScript.clear(); + return got; }