diff options
author | madmaxoft <github@xoft.cz> | 2014-01-11 16:44:28 +0100 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2014-01-11 16:44:28 +0100 |
commit | a332a5dc730289cca0357c7387731fd25e0b74cd (patch) | |
tree | b09e974b93451fa192b02e6f7f65529e66f0ad3d /lib/inifile/iniFile.cpp | |
parent | Merge branch 'master' into IniFileFix (diff) | |
download | cuberite-a332a5dc730289cca0357c7387731fd25e0b74cd.tar cuberite-a332a5dc730289cca0357c7387731fd25e0b74cd.tar.gz cuberite-a332a5dc730289cca0357c7387731fd25e0b74cd.tar.bz2 cuberite-a332a5dc730289cca0357c7387731fd25e0b74cd.tar.lz cuberite-a332a5dc730289cca0357c7387731fd25e0b74cd.tar.xz cuberite-a332a5dc730289cca0357c7387731fd25e0b74cd.tar.zst cuberite-a332a5dc730289cca0357c7387731fd25e0b74cd.zip |
Diffstat (limited to '')
-rw-r--r-- | lib/inifile/iniFile.cpp | 83 |
1 files changed, 55 insertions, 28 deletions
diff --git a/lib/inifile/iniFile.cpp b/lib/inifile/iniFile.cpp index 5ca6f6618..c1fd9c929 100644 --- a/lib/inifile/iniFile.cpp +++ b/lib/inifile/iniFile.cpp @@ -344,47 +344,79 @@ AString cIniFile::GetValueName(const AString & keyname, const int valueID) const +void cIniFile::AddValue(const AString & a_KeyName, const AString & a_ValueName, const AString & a_Value) +{ + int keyID = FindKey(a_KeyName); + if (keyID == noID) + { + keyID = int(AddKeyName(a_KeyName)); + } + + keys[keyID].names.push_back(a_ValueName); + keys[keyID].values.push_back(a_Value); +} + + + + + +void cIniFile::AddValueI(const AString & a_KeyName, const AString & a_ValueName, const int a_Value) +{ + AddValue(a_KeyName, a_ValueName, Printf("%d", a_Value)); +} + + + + + +void cIniFile::AddValueF(const AString & a_KeyName, const AString & a_ValueName, const double a_Value) +{ + AddValue(a_KeyName, a_ValueName, Printf("%f", a_Value)); +} + + + + + bool cIniFile::SetValue(const int keyID, const int valueID, const AString & value) { - if ((keyID < (int)keys.size()) && (valueID < (int)keys[keyID].names.size())) + if (((size_t)keyID >= keys.size()) || ((size_t)valueID >= keys[keyID].names.size())) { - keys[keyID].values[valueID] = value; + return false; } - return false; + keys[keyID].values[valueID] = value; + return true; } -bool cIniFile::SetValue(const AString & keyname, const AString & valuename, const AString & value, bool const create) +bool cIniFile::SetValue(const AString & a_KeyName, const AString & a_ValueName, const AString & a_Value, const bool a_CreateIfNotExists) { - int keyID = FindKey(keyname); + int keyID = FindKey(a_KeyName); if (keyID == noID) { - if (create) - { - keyID = int(AddKeyName(keyname)); - } - else + if (!a_CreateIfNotExists) { return false; } + keyID = AddKeyName(a_KeyName); } - int valueID = FindValue(int(keyID), valuename); + int valueID = FindValue(keyID, a_ValueName); if (valueID == noID) { - if (!create) + if (!a_CreateIfNotExists) { return false; } - keys[keyID].names.resize(keys[keyID].names.size() + 1, valuename); - keys[keyID].values.resize(keys[keyID].values.size() + 1, value); + keys[keyID].names.push_back(a_ValueName); + keys[keyID].values.push_back(a_Value); } else { - keys[keyID].values[valueID] = value; + keys[keyID].values[valueID] = a_Value; } return true; @@ -394,37 +426,32 @@ bool cIniFile::SetValue(const AString & keyname, const AString & valuename, cons -bool cIniFile::SetValueI(const AString & keyname, const AString & valuename, const int value, bool const create) +bool cIniFile::SetValueI(const AString & a_KeyName, const AString & a_ValueName, const int a_Value, const bool a_CreateIfNotExists) { - AString Data; - Printf(Data, "%d", value); - return SetValue(keyname, valuename, Data, create); + return SetValue(a_KeyName, a_ValueName, Printf("%d", a_Value), a_CreateIfNotExists); } -bool cIniFile::SetValueF(const AString & keyname, const AString & valuename, double const value, bool const create) +bool cIniFile::SetValueF(const AString & a_KeyName, const AString & a_ValueName, double const a_Value, const bool a_CreateIfNotExists) { - AString Data; - Printf(Data, "%f", value); - return SetValue(keyname, valuename, Data, create); + return SetValue(a_KeyName, a_ValueName, Printf("%f", a_Value), a_CreateIfNotExists); } -bool cIniFile::SetValueV(const AString & keyname, const AString & valuename, char * format, ...) +bool cIniFile::SetValueV(const AString & a_KeyName, const AString & a_ValueName, const char * a_Format, ...) { va_list args; - va_start(args, format); - + va_start(args, a_Format); AString Data; - AppendVPrintf(Data, format, args); + AppendVPrintf(Data, a_Format, args); va_end(args); - return SetValue(keyname, valuename, Data); + return SetValue(a_KeyName, a_ValueName, Data); } |