1
0

cIniFile: Renamed functions to make meaning more explicit.

For example KeyComment() -> GetKeyComment() / AddKeyComment()
This commit is contained in:
madmaxoft 2013-10-25 11:38:14 +02:00
parent 9e9198e090
commit 323ebf119f
6 changed files with 322 additions and 584 deletions

View File

@ -56,9 +56,9 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect)
// Normally you would use ifstream, but the SGI CC compiler has // Normally you would use ifstream, but the SGI CC compiler has
// a few bugs with ifstream. So ... fstream used. // a few bugs with ifstream. So ... fstream used.
fstream f; fstream f;
string line; AString line;
string keyname, valuename, value; AString keyname, valuename, value;
string::size_type pLeft, pRight; AString::size_type pLeft, pRight;
bool IsFromExampleRedirect = false; bool IsFromExampleRedirect = false;
f.open((FILE_IO_PREFIX + a_FileName).c_str(), ios::in); f.open((FILE_IO_PREFIX + a_FileName).c_str(), ios::in);
@ -68,7 +68,7 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect)
if (a_AllowExampleRedirect) if (a_AllowExampleRedirect)
{ {
// Retry with the .example.ini file instead of .ini: // Retry with the .example.ini file instead of .ini:
string ExPath(a_FileName.substr(0, a_FileName.length() - 4)); AString ExPath(a_FileName.substr(0, a_FileName.length() - 4));
ExPath.append(".example.ini"); ExPath.append(".example.ini");
f.open((FILE_IO_PREFIX + ExPath).c_str(), ios::in); f.open((FILE_IO_PREFIX + ExPath).c_str(), ios::in);
if (f.fail()) if (f.fail())
@ -90,7 +90,7 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect)
// Note that the '\r' will be written to INI files from // Note that the '\r' will be written to INI files from
// Unix so that the created INI file can be read under Win32 // Unix so that the created INI file can be read under Win32
// without change. // without change.
unsigned int lineLength = line.length(); size_t lineLength = line.length();
if (lineLength == 0) if (lineLength == 0)
{ {
continue; continue;
@ -113,7 +113,7 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect)
f.close(); f.close();
return false; return false;
} }
if ((pLeft = line.find_first_of(";#[=")) == string::npos) if ((pLeft = line.find_first_of(";#[=")) == AString::npos)
{ {
continue; continue;
} }
@ -123,7 +123,7 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect)
case '[': case '[':
{ {
if ( if (
((pRight = line.find_last_of("]")) != string::npos) && ((pRight = line.find_last_of("]")) != AString::npos) &&
(pRight > pLeft) (pRight > pLeft)
) )
{ {
@ -146,11 +146,11 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect)
{ {
if (names.size() == 0) if (names.size() == 0)
{ {
HeaderComment(line.substr(pLeft + 1)); AddHeaderComment(line.substr(pLeft + 1));
} }
else else
{ {
KeyComment(keyname, line.substr(pLeft + 1)); AddKeyComment(keyname, line.substr(pLeft + 1));
} }
break; break;
} }
@ -176,7 +176,6 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect)
bool cIniFile::WriteFile(const AString & a_FileName) const bool cIniFile::WriteFile(const AString & a_FileName) const
{ {
unsigned commentID, keyID, valueID;
// Normally you would use ofstream, but the SGI CC compiler has // Normally you would use ofstream, but the SGI CC compiler has
// a few bugs with ofstream. So ... fstream used. // a few bugs with ofstream. So ... fstream used.
fstream f; fstream f;
@ -188,28 +187,29 @@ bool cIniFile::WriteFile(const AString & a_FileName) const
} }
// Write header comments. // Write header comments.
for (commentID = 0; commentID < comments.size(); ++commentID) size_t NumComments = comments.size();
for (size_t commentID = 0; commentID < NumComments; ++commentID)
{ {
f << ';' << comments[commentID] << iniEOL; f << ';' << comments[commentID] << iniEOL;
} }
if (comments.size()) if (NumComments > 0)
{ {
f << iniEOL; f << iniEOL;
} }
// Write keys and values. // Write keys and values.
for (keyID = 0; keyID < keys.size(); ++keyID) for (size_t keyID = 0; keyID < keys.size(); ++keyID)
{ {
f << '[' << names[keyID] << ']' << iniEOL; f << '[' << names[keyID] << ']' << iniEOL;
// Comments. // Comments.
for (commentID = 0; commentID < keys[keyID].comments.size(); ++commentID) for (size_t commentID = 0; commentID < keys[keyID].comments.size(); ++commentID)
{ {
f << ';' << keys[keyID].comments[commentID] << iniEOL; f << ';' << keys[keyID].comments[commentID] << iniEOL;
} }
// Values. // Values.
for (valueID = 0; valueID < keys[keyID].names.size(); ++valueID) for (size_t valueID = 0; valueID < keys[keyID].names.size(); ++valueID)
{ {
f << keys[keyID].names[valueID] << '=' << keys[keyID].values[valueID] << iniEOL; f << keys[keyID].names[valueID] << '=' << keys[keyID].values[valueID] << iniEOL;
} }
@ -224,14 +224,14 @@ bool cIniFile::WriteFile(const AString & a_FileName) const
long cIniFile::FindKey(const string & a_KeyName) const int cIniFile::FindKey(const AString & a_KeyName) const
{ {
string CaseKeyName = CheckCase(a_KeyName); AString CaseKeyName = CheckCase(a_KeyName);
for (unsigned keyID = 0; keyID < names.size(); ++keyID) for (size_t keyID = 0; keyID < names.size(); ++keyID)
{ {
if (CheckCase(names[keyID]) == CaseKeyName) if (CheckCase(names[keyID]) == CaseKeyName)
{ {
return long(keyID); return keyID;
} }
} }
return noID; return noID;
@ -241,19 +241,19 @@ long cIniFile::FindKey(const string & a_KeyName) const
long cIniFile::FindValue(unsigned const keyID, const string & a_ValueName) const int cIniFile::FindValue(const int keyID, const AString & a_ValueName) const
{ {
if (!keys.size() || (keyID >= keys.size())) if (!keys.size() || (keyID >= (int)keys.size()))
{ {
return noID; return noID;
} }
string CaseValueName = CheckCase(a_ValueName); AString CaseValueName = CheckCase(a_ValueName);
for (unsigned valueID = 0; valueID < keys[keyID].names.size(); ++valueID) for (size_t valueID = 0; valueID < keys[keyID].names.size(); ++valueID)
{ {
if (CheckCase(keys[keyID].names[valueID]) == CaseValueName) if (CheckCase(keys[keyID].names[valueID]) == CaseValueName)
{ {
return long(valueID); return int(valueID);
} }
} }
return noID; return noID;
@ -263,7 +263,7 @@ long cIniFile::FindValue(unsigned const keyID, const string & a_ValueName) const
unsigned cIniFile::AddKeyName(const string & keyname) int cIniFile::AddKeyName(const AString & keyname)
{ {
names.resize(names.size() + 1, keyname); names.resize(names.size() + 1, keyname);
keys.resize(keys.size() + 1); keys.resize(keys.size() + 1);
@ -274,9 +274,9 @@ unsigned cIniFile::AddKeyName(const string & keyname)
string cIniFile::KeyName(unsigned const keyID) const AString cIniFile::GetKeyName(const int keyID) const
{ {
if (keyID < names.size()) if (keyID < (int)names.size())
{ {
return names[keyID]; return names[keyID];
} }
@ -290,11 +290,11 @@ string cIniFile::KeyName(unsigned const keyID) const
unsigned cIniFile::NumValues(unsigned const keyID) int cIniFile::GetNumValues(const int keyID) const
{ {
if (keyID < keys.size()) if (keyID < (int)keys.size())
{ {
return keys[keyID].names.size(); return (int)keys[keyID].names.size();
} }
return 0; return 0;
} }
@ -303,23 +303,23 @@ unsigned cIniFile::NumValues(unsigned const keyID)
unsigned cIniFile::NumValues(const string & keyname) int cIniFile::GetNumValues(const AString & keyname) const
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
return 0; return 0;
} }
return keys[keyID].names.size(); return (int)keys[keyID].names.size();
} }
string cIniFile::ValueName(unsigned const keyID, unsigned const valueID) const AString cIniFile::GetValueName(const int keyID, const int valueID) const
{ {
if (keyID < keys.size() && valueID < keys[keyID].names.size()) if ((keyID < (int)keys.size()) && (valueID < (int)keys[keyID].names.size()))
{ {
return keys[keyID].names[valueID]; return keys[keyID].names[valueID];
} }
@ -330,23 +330,23 @@ string cIniFile::ValueName(unsigned const keyID, unsigned const valueID) const
string cIniFile::ValueName(const string & keyname, unsigned const valueID) const AString cIniFile::GetValueName(const AString & keyname, const int valueID) const
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
return ""; return "";
} }
return ValueName(keyID, valueID); return GetValueName(keyID, valueID);
} }
bool cIniFile::SetValue(unsigned const keyID, unsigned const valueID, const string & value) bool cIniFile::SetValue(const int keyID, const int valueID, const AString & value)
{ {
if ((keyID < keys.size()) && (valueID < keys[keyID].names.size())) if ((keyID < (int)keys.size()) && (valueID < (int)keys[keyID].names.size()))
{ {
keys[keyID].values[valueID] = value; keys[keyID].values[valueID] = value;
} }
@ -357,14 +357,14 @@ bool cIniFile::SetValue(unsigned const keyID, unsigned const valueID, const stri
bool cIniFile::SetValue(const string & keyname, const string & valuename, const string & value, bool const create) bool cIniFile::SetValue(const AString & keyname, const AString & valuename, const AString & value, bool const create)
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
if (create) if (create)
{ {
keyID = long(AddKeyName(keyname)); keyID = int(AddKeyName(keyname));
} }
else else
{ {
@ -372,7 +372,7 @@ bool cIniFile::SetValue(const string & keyname, const string & valuename, const
} }
} }
long valueID = FindValue(unsigned(keyID), valuename); int valueID = FindValue(int(keyID), valuename);
if (valueID == noID) if (valueID == noID)
{ {
if (!create) if (!create)
@ -402,7 +402,7 @@ bool cIniFile::SetValue(const string & keyname, const string & valuename, const
bool cIniFile::SetValueI(const string & keyname, const string & valuename, int const value, bool const create) bool cIniFile::SetValueI(const AString & keyname, const AString & valuename, const int value, bool const create)
{ {
AString Data; AString Data;
Printf(Data, "%d", value); Printf(Data, "%d", value);
@ -413,7 +413,7 @@ bool cIniFile::SetValueI(const string & keyname, const string & valuename, int c
bool cIniFile::SetValueF(const string & keyname, const string & valuename, double const value, bool const create) bool cIniFile::SetValueF(const AString & keyname, const AString & valuename, double const value, bool const create)
{ {
AString Data; AString Data;
Printf(Data, "%f", value); Printf(Data, "%f", value);
@ -424,7 +424,7 @@ bool cIniFile::SetValueF(const string & keyname, const string & valuename, doubl
bool cIniFile::SetValueV(const string & keyname, const string & valuename, char * format, ...) bool cIniFile::SetValueV(const AString & keyname, const AString & valuename, char * format, ...)
{ {
va_list args; va_list args;
va_start(args, format); va_start(args, format);
@ -439,9 +439,9 @@ bool cIniFile::SetValueV(const string & keyname, const string & valuename, char
string cIniFile::GetValue(unsigned const keyID, unsigned const valueID, const string & defValue) const AString cIniFile::GetValue(const int keyID, const int valueID, const AString & defValue) const
{ {
if ((keyID < keys.size()) && (valueID < keys[keyID].names.size())) if ((keyID < (int)keys.size()) && (valueID < (int)keys[keyID].names.size()))
{ {
return keys[keyID].values[valueID]; return keys[keyID].values[valueID];
} }
@ -452,15 +452,15 @@ string cIniFile::GetValue(unsigned const keyID, unsigned const valueID, const st
string cIniFile::GetValue(const string & keyname, const string & valuename, const string & defValue) const AString cIniFile::GetValue(const AString & keyname, const AString & valuename, const AString & defValue) const
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
return defValue; return defValue;
} }
long valueID = FindValue(unsigned(keyID), valuename); int valueID = FindValue(int(keyID), valuename);
if (valueID == noID) if (valueID == noID)
{ {
return defValue; return defValue;
@ -473,7 +473,7 @@ string cIniFile::GetValue(const string & keyname, const string & valuename, cons
int cIniFile::GetValueI(const string & keyname, const string & valuename, int const defValue) const int cIniFile::GetValueI(const AString & keyname, const AString & valuename, const int defValue) const
{ {
AString Data; AString Data;
Printf(Data, "%d", defValue); Printf(Data, "%d", defValue);
@ -484,7 +484,7 @@ int cIniFile::GetValueI(const string & keyname, const string & valuename, int co
double cIniFile::GetValueF(const string & keyname, const string & valuename, double const defValue) const double cIniFile::GetValueF(const AString & keyname, const AString & valuename, double const defValue) const
{ {
AString Data; AString Data;
Printf(Data, "%f", defValue); Printf(Data, "%f", defValue);
@ -497,14 +497,14 @@ double cIniFile::GetValueF(const string & keyname, const string & valuename, dou
AString cIniFile::GetValueSet(const AString & keyname, const AString & valuename, const AString & defValue) AString cIniFile::GetValueSet(const AString & keyname, const AString & valuename, const AString & defValue)
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
SetValue(keyname, valuename, defValue); SetValue(keyname, valuename, defValue);
return defValue; return defValue;
} }
long valueID = FindValue(unsigned(keyID), valuename); int valueID = FindValue(int(keyID), valuename);
if (valueID == noID) if (valueID == noID)
{ {
SetValue(keyname, valuename, defValue); SetValue(keyname, valuename, defValue);
@ -540,13 +540,13 @@ int cIniFile::GetValueSetI(const AString & keyname, const AString & valuename, c
bool cIniFile::DeleteValueByID(const unsigned keyID, const unsigned valueID) bool cIniFile::DeleteValueByID(const int keyID, const int valueID)
{ {
if (keyID < keys.size() && valueID < keys[keyID].names.size()) if ((keyID < (int)keys.size()) && (valueID < (int)keys[keyID].names.size()))
{ {
// This looks strange, but is neccessary. // This looks strange, but is neccessary.
vector<string>::iterator npos = keys[keyID].names.begin() + valueID; vector<AString>::iterator npos = keys[keyID].names.begin() + valueID;
vector<string>::iterator vpos = keys[keyID].values.begin() + valueID; vector<AString>::iterator vpos = keys[keyID].values.begin() + valueID;
keys[keyID].names.erase(npos, npos + 1); keys[keyID].names.erase(npos, npos + 1);
keys[keyID].values.erase(vpos, vpos + 1); keys[keyID].values.erase(vpos, vpos + 1);
return true; return true;
@ -558,15 +558,15 @@ bool cIniFile::DeleteValueByID(const unsigned keyID, const unsigned valueID)
bool cIniFile::DeleteValue(const string & keyname, const string & valuename) bool cIniFile::DeleteValue(const AString & keyname, const AString & valuename)
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
return false; return false;
} }
long valueID = FindValue(unsigned(keyID), valuename); int valueID = FindValue(int(keyID), valuename);
if (valueID == noID) if (valueID == noID)
{ {
return false; return false;
@ -579,15 +579,15 @@ bool cIniFile::DeleteValue(const string & keyname, const string & valuename)
bool cIniFile::DeleteKey(const string & keyname) bool cIniFile::DeleteKey(const AString & keyname)
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
return false; return false;
} }
vector<string>::iterator npos = names.begin() + keyID; vector<AString>::iterator npos = names.begin() + keyID;
vector<key>::iterator kpos = keys.begin() + keyID; vector<key>::iterator kpos = keys.begin() + keyID;
names.erase(npos, npos + 1); names.erase(npos, npos + 1);
keys.erase(kpos, kpos + 1); keys.erase(kpos, kpos + 1);
@ -610,7 +610,7 @@ void cIniFile::Clear(void)
void cIniFile::HeaderComment(const string & comment) void cIniFile::AddHeaderComment(const AString & comment)
{ {
comments.push_back(comment); comments.push_back(comment);
// comments.resize(comments.size() + 1, comment); // comments.resize(comments.size() + 1, comment);
@ -620,9 +620,9 @@ void cIniFile::HeaderComment(const string & comment)
string cIniFile::HeaderComment(unsigned const commentID) const AString cIniFile::GetHeaderComment(const int commentID) const
{ {
if (commentID < comments.size()) if (commentID < (int)comments.size())
{ {
return comments[commentID]; return comments[commentID];
} }
@ -633,11 +633,11 @@ string cIniFile::HeaderComment(unsigned const commentID) const
bool cIniFile::DeleteHeaderComment(unsigned commentID) bool cIniFile::DeleteHeaderComment(int commentID)
{ {
if (commentID < comments.size()) if (commentID < (int)comments.size())
{ {
vector<string>::iterator cpos = comments.begin() + commentID; vector<AString>::iterator cpos = comments.begin() + commentID;
comments.erase(cpos, cpos + 1); comments.erase(cpos, cpos + 1);
return true; return true;
} }
@ -648,9 +648,9 @@ bool cIniFile::DeleteHeaderComment(unsigned commentID)
unsigned cIniFile::NumKeyComments(unsigned const keyID) const int cIniFile::GetNumKeyComments(const int keyID) const
{ {
if (keyID < keys.size()) if (keyID < (int)keys.size())
{ {
return keys[keyID].comments.size(); return keys[keyID].comments.size();
} }
@ -661,21 +661,23 @@ unsigned cIniFile::NumKeyComments(unsigned const keyID) const
unsigned cIniFile::NumKeyComments(const string & keyname) const int cIniFile::GetNumKeyComments(const AString & keyname) const
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{
return 0; return 0;
return keys[keyID].comments.size(); }
return (int)keys[keyID].comments.size();
} }
bool cIniFile::KeyComment(unsigned const keyID, const string & comment) bool cIniFile::AddKeyComment(const int keyID, const AString & comment)
{ {
if (keyID < keys.size()) if (keyID < (int)keys.size())
{ {
keys[keyID].comments.resize(keys[keyID].comments.size() + 1, comment); keys[keyID].comments.resize(keys[keyID].comments.size() + 1, comment);
return true; return true;
@ -687,23 +689,23 @@ bool cIniFile::KeyComment(unsigned const keyID, const string & comment)
bool cIniFile::KeyComment(const string & keyname, const string & comment) bool cIniFile::AddKeyComment(const AString & keyname, const AString & comment)
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
return false; return false;
} }
return KeyComment(unsigned(keyID), comment); return AddKeyComment(keyID, comment);
} }
string cIniFile::KeyComment(unsigned const keyID, unsigned const commentID) const AString cIniFile::GetKeyComment(const int keyID, const int commentID) const
{ {
if ((keyID < keys.size()) && (commentID < keys[keyID].comments.size())) if ((keyID < (int)keys.size()) && (commentID < (int)keys[keyID].comments.size()))
{ {
return keys[keyID].comments[commentID]; return keys[keyID].comments[commentID];
} }
@ -714,25 +716,25 @@ string cIniFile::KeyComment(unsigned const keyID, unsigned const commentID) cons
string cIniFile::KeyComment(const string & keyname, unsigned const commentID) const AString cIniFile::GetKeyComment(const AString & keyname, const int commentID) const
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
return ""; return "";
} }
return KeyComment(unsigned(keyID), commentID); return GetKeyComment(int(keyID), commentID);
} }
bool cIniFile::DeleteKeyComment(unsigned const keyID, unsigned const commentID) bool cIniFile::DeleteKeyComment(const int keyID, const int commentID)
{ {
if ((keyID < keys.size()) && (commentID < keys[keyID].comments.size())) if ((keyID < (int)keys.size()) && (commentID < (int)keys[keyID].comments.size()))
{ {
vector<string>::iterator cpos = keys[keyID].comments.begin() + commentID; vector<AString>::iterator cpos = keys[keyID].comments.begin() + commentID;
keys[keyID].comments.erase(cpos, cpos + 1); keys[keyID].comments.erase(cpos, cpos + 1);
return true; return true;
} }
@ -743,23 +745,23 @@ bool cIniFile::DeleteKeyComment(unsigned const keyID, unsigned const commentID)
bool cIniFile::DeleteKeyComment(const string & keyname, unsigned const commentID) bool cIniFile::DeleteKeyComment(const AString & keyname, const int commentID)
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
return false; return false;
} }
return DeleteKeyComment(unsigned(keyID), commentID); return DeleteKeyComment(int(keyID), commentID);
} }
bool cIniFile::DeleteKeyComments(unsigned const keyID) bool cIniFile::DeleteKeyComments(const int keyID)
{ {
if (keyID < keys.size()) if (keyID < (int)keys.size())
{ {
keys[keyID].comments.clear(); keys[keyID].comments.clear();
return true; return true;
@ -771,27 +773,27 @@ bool cIniFile::DeleteKeyComments(unsigned const keyID)
bool cIniFile::DeleteKeyComments(const string & keyname) bool cIniFile::DeleteKeyComments(const AString & keyname)
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
return false; return false;
} }
return DeleteKeyComments(unsigned(keyID)); return DeleteKeyComments(int(keyID));
} }
string cIniFile::CheckCase(const string & s) const AString cIniFile::CheckCase(const AString & s) const
{ {
if (!m_IsCaseInsensitive) if (!m_IsCaseInsensitive)
{ {
return s; return s;
} }
string res(s); AString res(s);
size_t len = res.length(); size_t len = res.length();
for (size_t i = 0; i < len; i++) for (size_t i = 0; i < len; i++)
{ {

View File

@ -39,17 +39,17 @@ private:
struct key struct key
{ {
std::vector<std::string> names; std::vector<AString> names;
std::vector<std::string> values; std::vector<AString> values;
std::vector<std::string> comments; std::vector<AString> comments;
} ; } ;
std::vector<key> keys; std::vector<key> keys;
std::vector<std::string> names; std::vector<AString> names;
std::vector<std::string> comments; std::vector<AString> comments;
/// If the object is case-insensitive, returns s as lowercase; otherwise returns s as-is /// If the object is case-insensitive, returns s as lowercase; otherwise returns s as-is
std::string CheckCase(const std::string & s) const; AString CheckCase(const AString & s) const;
public: public:
enum errors enum errors
@ -77,54 +77,40 @@ public:
/// Deletes all stored ini data (but doesn't touch the file) /// Deletes all stored ini data (but doesn't touch the file)
void Clear(void); void Clear(void);
void Reset(void) { Clear(); }
void Erase(void) { Clear(); } // OBSOLETE, this name is misguiding and will be removed from the interface
/// Returns index of specified key, or noID if not found /// Returns index of specified key, or noID if not found
long FindKey(const std::string & keyname) const; int FindKey(const AString & keyname) const;
/// Returns index of specified value, in the specified key, or noID if not found /// Returns index of specified value, in the specified key, or noID if not found
long FindValue(const unsigned keyID, const std::string & valuename) const; int FindValue(const int keyID, const AString & valuename) const;
/// Returns number of keys currently in the ini /// Returns number of keys currently in the ini
unsigned NumKeys (void) const {return names.size();} int GetNumKeys(void) const { return (int)keys.size(); }
unsigned GetNumKeys(void) const {return NumKeys();}
/// Add a key name /// Add a key name
unsigned AddKeyName(const std::string & keyname); int AddKeyName(const AString & keyname);
// Returns key names by index. // Returns key names by index.
std::string KeyName(const unsigned keyID) const; AString GetKeyName(const int keyID) const;
std::string GetKeyName(const unsigned keyID) const {return KeyName(keyID);}
// Returns number of values stored for specified key. // Returns number of values stored for specified key.
unsigned NumValues (const std::string & keyname); int GetNumValues(const AString & keyname) const;
unsigned GetNumValues(const std::string & keyname) {return NumValues(keyname);} int GetNumValues(const int keyID) const;
unsigned NumValues (const unsigned keyID);
unsigned GetNumValues(const unsigned keyID) {return NumValues(keyID);}
// Returns value name by index for a given keyname or keyID. // Returns value name by index for a given keyname or keyID.
std::string ValueName( const std::string & keyname, const unsigned valueID) const; AString GetValueName(const AString & keyname, const int valueID) const;
std::string GetValueName( const std::string & keyname, const unsigned valueID) const AString GetValueName(const int keyID, const int valueID) const;
{
return ValueName(keyname, valueID);
}
std::string ValueName (const unsigned keyID, const unsigned valueID) const;
std::string GetValueName(const unsigned keyID, const unsigned valueID) const
{
return ValueName(keyID, valueID);
}
// Gets value of [keyname] valuename =. // Gets value of [keyname] valuename =.
// Overloaded to return string, int, and double. // Overloaded to return string, int, and double.
// Returns defValue if key/value not found. // Returns defValue if key/value not found.
AString GetValue (const AString & keyname, const AString & valuename, const AString & defValue = "") const; AString GetValue (const AString & keyname, const AString & valuename, const AString & defValue = "") const;
AString GetValue (const unsigned keyID, const unsigned valueID, const AString & defValue = "") const; AString GetValue (const int keyID, const int valueID, const AString & defValue = "") const;
double GetValueF(const AString & keyname, const AString & valuename, const double defValue = 0) const; double GetValueF(const AString & keyname, const AString & valuename, const double defValue = 0) const;
int GetValueI(const AString & keyname, const AString & valuename, const int defValue = 0) const; int GetValueI(const AString & keyname, const AString & valuename, const int defValue = 0) const;
bool GetValueB(const AString & keyname, const AString & valuename, const bool defValue = false) const bool GetValueB(const AString & keyname, const AString & valuename, const bool defValue = false) const
{ {
return (GetValueI(keyname, valuename, int(defValue)) > 0); return (GetValueI(keyname, valuename, defValue ? 1 : 0) != 0);
} }
// Gets the value; if not found, write the default to the INI file // Gets the value; if not found, write the default to the INI file
@ -133,50 +119,54 @@ public:
int GetValueSetI(const AString & keyname, const AString & valuename, const int defValue = 0); int GetValueSetI(const AString & keyname, const AString & valuename, const int defValue = 0);
bool GetValueSetB(const AString & keyname, const AString & valuename, const bool defValue = false) bool GetValueSetB(const AString & keyname, const AString & valuename, const bool defValue = false)
{ {
return (GetValueSetI(keyname, valuename, defValue ? 1 : 0) > 0); return (GetValueSetI(keyname, valuename, defValue ? 1 : 0) != 0);
} }
// Sets value of [keyname] valuename =. // Sets value of [keyname] valuename =.
// Specify the optional paramter as false (0) if you do not want it to create // Specify the optional paramter as false (0) if you do not want it to create
// the key if it doesn't exist. Returns true if data entered, false otherwise. // the key if it doesn't exist. Returns true if data entered, false otherwise.
// Overloaded to accept string, int, and double. // Overloaded to accept string, int, and double.
bool SetValue( const unsigned keyID, const unsigned valueID, const std::string & value); bool SetValue( const int keyID, const int valueID, const AString & value);
bool SetValue( const std::string & keyname, const std::string & valuename, const std::string & value, const bool create = true); bool SetValue( const AString & keyname, const AString & valuename, const AString & value, const bool create = true);
bool SetValueI( const std::string & keyname, const std::string & valuename, const int value, const bool create = true); bool SetValueI( const AString & keyname, const AString & valuename, const int value, const bool create = true);
bool SetValueB( const std::string & keyname, const std::string & valuename, const bool value, const bool create = true) bool SetValueB( const AString & keyname, const AString & valuename, const bool value, const bool create = true)
{ {
return SetValueI( keyname, valuename, int(value), create); return SetValueI( keyname, valuename, int(value), create);
} }
bool SetValueF( const std::string & keyname, const std::string & valuename, const double value, const bool create = true); bool SetValueF( const AString & keyname, const AString & valuename, const double value, const bool create = true);
// tolua_end // tolua_end
bool SetValueV( const std::string & keyname, const std::string & valuename, char *format, ...); bool SetValueV( const AString & keyname, const AString & valuename, char *format, ...);
// tolua_begin // tolua_begin
// Deletes specified value. // Deletes specified value.
// Returns true if value existed and deleted, false otherwise. // Returns true if value existed and deleted, false otherwise.
bool DeleteValueByID( const unsigned keyID, const unsigned valueID ); bool DeleteValueByID(const int keyID, const int valueID);
bool DeleteValue( const std::string & keyname, const std::string & valuename); bool DeleteValue(const AString & keyname, const AString & valuename);
// Deletes specified key and all values contained within. // Deletes specified key and all values contained within.
// Returns true if key existed and deleted, false otherwise. // Returns true if key existed and deleted, false otherwise.
bool DeleteKey(const std::string & keyname); bool DeleteKey(const AString & keyname);
// Header comment functions. // Header comment functions.
// Header comments are those comments before the first key. // Header comments are those comments before the first key.
//
// Number of header comments. /// Get number of header comments
unsigned NumHeaderComments(void) {return comments.size();} int GetNumHeaderComments(void) {return (int)comments.size();}
// Add a header comment.
void HeaderComment(const std::string & comment); /// Add a header comment
// Return a header comment. void AddHeaderComment(const AString & comment);
std::string HeaderComment(const unsigned commentID) const;
// Delete a header comment. /// Return a header comment
bool DeleteHeaderComment(unsigned commentID); AString GetHeaderComment(const int commentID) const;
// Delete all header comments.
void DeleteHeaderComments(void) {comments.clear();} /// Delete a header comment.
bool DeleteHeaderComment(int commentID);
/// Delete all header comments.
void DeleteHeaderComments(void) {comments.clear();}
// Key comment functions. // Key comment functions.
@ -184,26 +174,30 @@ public:
// defined within value names will be added to this list. Therefore, // defined within value names will be added to this list. Therefore,
// these comments will be moved to the top of the key definition when // these comments will be moved to the top of the key definition when
// the CIniFile::WriteFile() is called. // the CIniFile::WriteFile() is called.
//
// Number of key comments. /// Get number of key comments
unsigned NumKeyComments( const unsigned keyID) const; int GetNumKeyComments(const int keyID) const;
unsigned NumKeyComments( const std::string & keyname) const;
/// Get number of key comments
int GetNumKeyComments(const AString & keyname) const;
// Add a key comment. /// Add a key comment
bool KeyComment(const unsigned keyID, const std::string & comment); bool AddKeyComment(const int keyID, const AString & comment);
bool KeyComment(const std::string & keyname, const std::string & comment);
/// Add a key comment
bool AddKeyComment(const AString & keyname, const AString & comment);
// Return a key comment. /// Return a key comment
std::string KeyComment(const unsigned keyID, const unsigned commentID) const; AString GetKeyComment(const int keyID, const int commentID) const;
std::string KeyComment(const std::string & keyname, const unsigned commentID) const; AString GetKeyComment(const AString & keyname, const int commentID) const;
// Delete a key comment. // Delete a key comment.
bool DeleteKeyComment(const unsigned keyID, const unsigned commentID); bool DeleteKeyComment(const int keyID, const int commentID);
bool DeleteKeyComment(const std::string & keyname, const unsigned commentID); bool DeleteKeyComment(const AString & keyname, const int commentID);
// Delete all comments for a key. // Delete all comments for a key.
bool DeleteKeyComments(const unsigned keyID); bool DeleteKeyComments(const int keyID);
bool DeleteKeyComments(const std::string & keyname); bool DeleteKeyComments(const AString & keyname);
}; };
// tolua_end // tolua_end

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/* /*
** Lua binding: AllToLua ** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 10/25/13 10:38:51. ** Generated automatically by tolua++-1.0.92 on 10/25/13 11:34:58.
*/ */
/* Exported function */ /* Exported function */

View File

@ -47,15 +47,15 @@ public:
{ {
return; return;
} }
long KeyID = Ini.FindKey("Items"); int KeyID = Ini.FindKey("Items");
if (KeyID == cIniFile::noID) if (KeyID == cIniFile::noID)
{ {
return; return;
} }
unsigned NumValues = Ini.GetNumValues(KeyID); int NumValues = Ini.GetNumValues(KeyID);
for (unsigned i = 0; i < NumValues; i++) for (int i = 0; i < NumValues; i++)
{ {
AString Name = Ini.ValueName(KeyID, i); AString Name = Ini.GetValueName(KeyID, i);
if (Name.empty()) if (Name.empty())
{ {
continue; continue;

View File

@ -63,10 +63,10 @@ void cMonsterConfig::Initialize()
return; return;
} }
for (int i = (int)MonstersIniFile.NumKeys(); i >= 0; i--) for (int i = (int)MonstersIniFile.GetNumKeys(); i >= 0; i--)
{ {
sAttributesStruct Attributes; sAttributesStruct Attributes;
AString Name = MonstersIniFile.KeyName(i); AString Name = MonstersIniFile.GetKeyName(i);
Attributes.m_Name = Name; Attributes.m_Name = Name;
Attributes.m_AttackDamage = MonstersIniFile.GetValueF(Name, "AttackDamage", 0); Attributes.m_AttackDamage = MonstersIniFile.GetValueF(Name, "AttackDamage", 0);
Attributes.m_AttackRange = MonstersIniFile.GetValueF(Name, "AttackRange", 0); Attributes.m_AttackRange = MonstersIniFile.GetValueF(Name, "AttackRange", 0);