]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Settings.hh
cade lab fixes
[chaz/yoink] / src / Moof / Settings.hh
index 42e7d3a7a5f26e159237a3b37682efb2a4a9f015..d4cbb9fa0cd47e0a06a0f21a4ea5a3923f6a5d7d 100644 (file)
@@ -50,45 +50,52 @@ class Settings
 {
 public:
 
-       Settings() :
-               mGlobals(mScript.getGlobalTable()),
-               mTop(mScript[-1])
+       Settings()
        {
-               importLogScript(mScript);
+               mScript.importBaseLibrary();
+               importLogFunctions(mScript);
        }
 
-       // get global instance
-       static Settings& getInstance();
+       ~Settings();
 
        void parseArgs(int argc, char* argv[]);
 
-       void loadFromFile(const std::string& filePath);
-       void loadFromFiles(const std::vector<std::string>& filePaths);
+       void loadFromFiles(const std::string& path);
+       void loadFromFiles(const std::vector<std::string>& path);
+
+       void clear();           // remove all settings
+
+       void saveAs(const std::string& path);
+       void save() const;
 
        template <typename T>
-       bool get(const std::string& key, T& value);
+       bool get(const std::string& key, T& value) const;
 
 private:
 
-       Script                  mScript;
-       Script::Value   mGlobals, mTop;
+       mutable Script  mScript;
+
+       std::string             mUserFile;
 };
 
 
 template <typename T>
-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<std::string> fields;
        boost::split(fields, key, boost::is_any_of("."));
 
-       mGlobals.pushCopy();
+       globals.pushCopy();
 
        std::vector<std::string>::iterator it;
        for (it = fields.begin(); it != fields.end(); ++it)
        {
-               if (mTop.isTable())
+               if (top.isTable())
                {
-                       mTop.pushField(*it);
+                       top.pushField(*it);
                }
                else
                {
@@ -97,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_
This page took 0.020208 seconds and 4 git commands to generate.