]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Settings.hh
settings subsystem now using lua
[chaz/yoink] / src / Moof / Settings.hh
index faad547c86f20820e91cbe80a1b5a88b87d32d49..dc29deb3ad260e772348bd8c40abe7e080a271c4 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,55 @@ namespace Mf {
 class Settings
 {
 public:
-       Settings() {}
-       Settings(int argc, char* argv[]);
+       Settings() :
+               globals_(script_.getGlobalTable()),
+               top_(script_[-1])
+       {
+               importLogScript(script_);
+       }
 
        // 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);
 
        template <typename T>
        bool get(const std::string& key, T& value);
-       template <typename T>
-       bool getNumber(const std::string& key, T& value);
 
 private:
-       std::map<std::string,SerializablePtr> map_;
+       Script                  script_;
+       Script::Value   globals_, top_;
 };
 
 
 template <typename T>
 bool Settings::get(const std::string& key, T& value)
 {
-       std::map<std::string,SerializablePtr>::const_iterator it = map_.find(key);
+       std::vector<std::string> 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 <typename T>
-bool Settings::getNumber(const std::string& key, T& value)
-{
-       std::map<std::string,SerializablePtr>::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)
        {
-               SerializablePtr obj = (*it).second;
-               return obj->getNumber(value);
-       }
-       else
-       {
-               return false;
+               if (top_.isTable())
+               {
+                       top_.pushField(*it);
+               }
+               else
+               {
+                       script_.clear();
+                       return false;
+               }
        }
+
+       bool got = top_.get(value);
+       script_.clear();
+       return got;
 }
 
 
This page took 0.019238 seconds and 4 git commands to generate.