X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FSettings.hh;h=d31b57dcf763c2fe0d38b1f3f96cc1fa24583223;hp=42e7d3a7a5f26e159237a3b37682efb2a4a9f015;hb=b357615aba1dbde81e3c6999366604e6001010a7;hpb=a31d65a998121df0651c57bfb68782e2a07d2e2f diff --git a/src/Moof/Settings.hh b/src/Moof/Settings.hh index 42e7d3a..d31b57d 100644 --- a/src/Moof/Settings.hh +++ b/src/Moof/Settings.hh @@ -50,13 +50,14 @@ class Settings { public: - Settings() : - mGlobals(mScript.getGlobalTable()), - mTop(mScript[-1]) + Settings() { - importLogScript(mScript); + mScript.importBaseLibrary(); + importLogFunctions(mScript); } + ~Settings(); + // get global instance static Settings& getInstance(); @@ -65,30 +66,39 @@ public: 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); private: Script mScript; - Script::Value mGlobals, mTop; + + std::string mUserFile; }; template bool Settings::get(const std::string& key, T& value) { + 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 { @@ -97,7 +107,7 @@ bool Settings::get(const std::string& key, T& value) } } - bool got = mTop.get(value); + bool got = top.get(value); mScript.clear(); return got; }