]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Settings.hh
simplified win32 installer build script
[chaz/yoink] / src / Moof / Settings.hh
index 653d4561dd1e2af4dd4b66ddcd1232b90b893f1d..d31b57dcf763c2fe0d38b1f3f96cc1fa24583223 100644 (file)
  * Load, store, save program settings.
  */
 
-#include <map>
 #include <string>
+#include <vector>
 
-#include <Moof/Serializable.hh>
+#include <boost/algorithm/string.hpp>
+
+#include <Moof/Log.hh>
+#include <Moof/Script.hh>
 
 
 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<std::string>& filePaths,
-                       bool precedence = false);
+       void loadFromFile(const std::string& filePath);
+       void loadFromFiles(const std::vector<std::string>& filePaths);
+
+       void clear();           // remove all settings
+
+       void saveAs(const std::string& filePath);
+       void save() const;
 
        template <typename T>
        bool get(const std::string& key, T& value);
-       template <typename T>
-       bool getNumber(const std::string& key, T& value);
 
 private:
-       Serializable::Map map_;
+
+       Script                  mScript;
+
+       std::string             mUserFile;
 };
 
 
 template <typename T>
 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<std::string> fields;
+       boost::split(fields, key, boost::is_any_of("."));
 
-template <typename T>
-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<std::string>::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;
 }
 
 
This page took 0.019452 seconds and 4 git commands to generate.