X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FSettings.hh;h=d4cbb9fa0cd47e0a06a0f21a4ea5a3923f6a5d7d;hp=2a2a9267026e5475ddd5c0a1d11433da19767251;hb=3f6e44698c38b74bb622ad81ea9d2daa636981d2;hpb=7f3984f3f9524f5b6813e01ceb2fe576dadff94e diff --git a/src/Moof/Settings.hh b/src/Moof/Settings.hh index 2a2a926..d4cbb9f 100644 --- a/src/Moof/Settings.hh +++ b/src/Moof/Settings.hh @@ -50,55 +50,52 @@ class Settings { public: - Settings() : - mGlobals(mScript.getGlobalTable()), - mTop(mScript[-1]) + Settings() { mScript.importBaseLibrary(); - importLogPrintFunction(mScript); + importLogFunctions(mScript); } ~Settings(); - // get global instance - static Settings& getInstance(); - void parseArgs(int argc, char* argv[]); - void loadFromFile(const std::string& filePath); - void loadFromFiles(const std::vector& filePaths); + void loadFromFiles(const std::string& path); + void loadFromFiles(const std::vector& path); void clear(); // remove all settings - void saveAs(const std::string& filePath); + void saveAs(const std::string& path); void save() const; template - bool get(const std::string& key, T& value); + bool get(const std::string& key, T& value) const; private: - Script mScript; - Script::Slot mGlobals, mTop; + 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 { + Script::Slot top = mScript[-1]; + Script::Slot globals = mScript.getGlobalTable(); + std::vector fields; boost::split(fields, key, boost::is_any_of(".")); - mGlobals.pushCopy(); + globals.pushCopy(); std::vector::iterator it; for (it = fields.begin(); it != fields.end(); ++it) { - if (mTop.isTable()) + if (top.isTable()) { - mTop.pushField(*it); + top.pushField(*it); } else { @@ -107,12 +104,15 @@ bool Settings::get(const std::string& key, T& value) } } - bool got = mTop.get(value); + bool got = top.get(value); mScript.clear(); return got; } +extern Settings settings; + + } // namepsace Mf #endif // _MOOF_SETTINGS_HH_