diff options
Diffstat (limited to 'Source/Core/Common')
| -rw-r--r-- | Source/Core/Common/Src/IniFile.cpp | 47 | ||||
| -rw-r--r-- | Source/Core/Common/Src/IniFile.h | 43 |
2 files changed, 42 insertions, 48 deletions
diff --git a/Source/Core/Common/Src/IniFile.cpp b/Source/Core/Common/Src/IniFile.cpp index b9e46feb28..244d06a161 100644 --- a/Source/Core/Common/Src/IniFile.cpp +++ b/Source/Core/Common/Src/IniFile.cpp @@ -60,21 +60,6 @@ static void ParseLine(const std::string& line, std::string* keyOut, std::string* } -IniFile::Section::Section() - : lines(), name(""), comment("") {} - - -IniFile::Section::Section(const std::string& _name) - : lines(), name(_name), comment("") {} - - -IniFile::Section::Section(const Section& other) -{ - name = other.name; - comment = other.comment; - lines = other.lines; -} - std::string* IniFile::Section::GetLine(const char* key, std::string* valueOut, std::string* commentOut) { for (std::vector<std::string>::iterator iter = lines.begin(); iter != lines.end(); ++iter) @@ -104,6 +89,14 @@ void IniFile::Section::Set(const char* key, const char* newValue) } } +void IniFile::Section::Set(const char* key, const std::string& newValue, const std::string& defaultValue) +{ + if (newValue != defaultValue) + Set(key, newValue); + else + Delete(key); +} + bool IniFile::Section::Get(const char* key, std::string* value, const char* defaultValue) { std::string* line = GetLine(key, value, 0); @@ -118,6 +111,14 @@ bool IniFile::Section::Get(const char* key, std::string* value, const char* defa return true; } +void IniFile::Section::Set(const char* key, const float newValue, const float defaultValue) +{ + if (newValue != defaultValue) + Set(key, newValue); + else + Delete(key); +} + void IniFile::Section::Set(const char* key, const std::vector<std::string>& newValues) { std::string temp; @@ -222,12 +223,22 @@ bool IniFile::Section::Exists(const char *key) const return false; } +bool IniFile::Section::Delete(const char *key) +{ + std::string* line = GetLine(key, 0, 0); + for (std::vector<std::string>::iterator liter = lines.begin(); liter != lines.end(); ++liter) + { + if (line == &*liter) + { + lines.erase(liter); + return true; + } + } + return false; +} // IniFile -IniFile::IniFile() {} -IniFile::~IniFile() {} - const IniFile::Section* IniFile::GetSection(const char* sectionName) const { for (std::vector<Section>::const_iterator iter = sections.begin(); iter != sections.end(); ++iter) diff --git a/Source/Core/Common/Src/IniFile.h b/Source/Core/Common/Src/IniFile.h index e287427c09..1b214edf86 100644 --- a/Source/Core/Common/Src/IniFile.h +++ b/Source/Core/Common/Src/IniFile.h @@ -28,19 +28,19 @@ class IniFile public: class Section { - public: - Section(); - Section(const std::string& _name); - Section(const Section& other); + friend class IniFile; - std::vector<std::string> lines; - std::string name; - std::string comment; + public: + Section() {} + Section(const std::string& _name) : name(_name) {} bool Exists(const char *key) const; + bool Delete(const char *key); std::string* GetLine(const char* key, std::string* valueOut, std::string* commentOut); void Set(const char* key, const char* newValue); + void Set(const char* key, const std::string& newValue, const std::string& defaultValue); + void Set(const std::string &key, const std::string &value) { Set(key.c_str(), value.c_str()); } @@ -52,6 +52,7 @@ public: void Set(const char* key, float newValue) { Set(key, StringFromFormat("%f", newValue).c_str()); } + void Set(const char* key, const float newValue, const float defaultValue); void Set(const char* key, double newValue) { Set(key, StringFromFormat("%f", newValue).c_str()); } @@ -70,33 +71,15 @@ public: bool Get(const char* key, double* value, double defaultValue = false); bool Get(const char* key, std::vector<std::string>& values); - // Direct getters, Billiard-style. - std::string Get(const char *key, const char *default_value) { - std::string value; Get(key, &value, default_value); return value; - } - int Get(const char *key, int defaultValue) { - int value; Get(key, &value, defaultValue); return value; - } - int Get(const char *key, u32 defaultValue) { - u32 value; Get(key, &value, defaultValue); return value; - } - int Get(const char *key, bool defaultValue) { - bool value; Get(key, &value, defaultValue); return value; - } - float Get(const char *key, float defaultValue) { - float value; Get(key, &value, defaultValue); return value; - } - double Get(const char *key, double defaultValue) { - double value; Get(key, &value, defaultValue); return value; - } - bool operator < (const Section& other) const { return name < other.name; } - }; - IniFile(); - ~IniFile(); + protected: + std::vector<std::string> lines; + std::string name; + std::string comment; + }; bool Load(const char* filename); bool Load(const std::string &filename) { return Load(filename.c_str()); } |
