]> git.lizzy.rs Git - minetest.git/blobdiff - src/settings.h
Initially add small and tight logging facility
[minetest.git] / src / settings.h
index f972ce3ece1ce8528d97eb2c82514ca9e5aef550..e8f376938676ecee172f247e189325098ac47c06 100644 (file)
@@ -102,6 +102,22 @@ class Settings
                return true;
        }
 
+       void parseConfigLines(std::istream &is, const std::string &endstring)
+       {
+               for(;;){
+                       if(is.eof())
+                               break;
+                       std::string line;
+                       std::getline(is, line);
+                       std::string trimmedline = trim(line);
+                       if(endstring != ""){
+                               if(trimmedline == endstring)
+                                       break;
+                       }
+                       parseConfigLine(line);
+               }
+       }
+
        // Returns false on EOF
        bool parseConfigObject(std::istream &is)
        {
@@ -481,6 +497,16 @@ class Settings
                return value;
        }
 
+       v2f getV2F(std::string name)
+       {
+               v2f value;
+               Strfnd f(get(name));
+               f.next("(");
+               value.X = stof(f.next(","));
+               value.Y = stof(f.next(")"));
+               return value;
+       }
+
        u64 getU64(std::string name)
        {
                u64 value = 0;
@@ -515,6 +541,13 @@ class Settings
                set(name, os.str());
        }
 
+       void setV2F(std::string name, v2f value)
+       {
+               std::ostringstream os;
+               os<<"("<<value.X<<","<<value.Y<<")";
+               set(name, os.str());
+       }
+
        void setU64(std::string name, u64 value)
        {
                std::ostringstream os;
@@ -530,6 +563,47 @@ class Settings
                m_defaults.clear();
        }
 
+       void updateValue(Settings &other, const std::string &name)
+       {
+               JMutexAutoLock lock(m_mutex);
+               
+               if(&other == this)
+                       return;
+
+               try{
+                       std::string val = other.get(name);
+                       m_settings[name] = val;
+               } catch(SettingNotFoundException &e){
+               }
+
+               return;
+       }
+
+       void update(Settings &other)
+       {
+               JMutexAutoLock lock(m_mutex);
+               JMutexAutoLock lock2(other.m_mutex);
+               
+               if(&other == this)
+                       return;
+
+               for(core::map<std::string, std::string>::Iterator
+                               i = other.m_settings.getIterator();
+                               i.atEnd() == false; i++)
+               {
+                       m_settings[i.getNode()->getKey()] = i.getNode()->getValue();
+               }
+               
+               for(core::map<std::string, std::string>::Iterator
+                               i = other.m_defaults.getIterator();
+                               i.atEnd() == false; i++)
+               {
+                       m_defaults[i.getNode()->getKey()] = i.getNode()->getValue();
+               }
+
+               return;
+       }
+
        Settings & operator+=(Settings &other)
        {
                JMutexAutoLock lock(m_mutex);