mirror of
https://github.com/1dot13/source.git
synced 2026-09-09 14:46:05 +02:00
Added array readers to the ini reader (by rftr).
git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@9171 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
@@ -253,6 +253,80 @@ FLOAT CIniReader::ReadFloat(const STR8 szSection, const STR8 szKey, FLOAT defaul
|
|||||||
return iniValueReadFromFile;
|
return iniValueReadFromFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CIniReader::ReadFloatArray(const STR8 szSection, const STR8 szKey, std::vector<FLOAT>& vec)
|
||||||
|
{
|
||||||
|
// read the array as a string
|
||||||
|
STRING512 textBuffer;
|
||||||
|
ReadString(szSection, szKey, "", textBuffer, _countof(textBuffer));
|
||||||
|
|
||||||
|
std::string str, token;
|
||||||
|
std::string delim = ",";
|
||||||
|
size_t offset = 0, prevOffset = 0;
|
||||||
|
|
||||||
|
// sanitise input
|
||||||
|
vec.clear();
|
||||||
|
str = textBuffer;
|
||||||
|
str.erase(std::remove(str.begin(), str.end(), ' '), str.end());
|
||||||
|
|
||||||
|
// split into array
|
||||||
|
try
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
offset = str.find(delim, prevOffset);
|
||||||
|
token = str.substr(prevOffset, offset - prevOffset);
|
||||||
|
prevOffset = offset + delim.length();
|
||||||
|
|
||||||
|
vec.push_back(std::stof(token.c_str()));
|
||||||
|
} while (offset != std::string::npos);
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
std::stringstream errMessage;
|
||||||
|
errMessage << "There was an error reading array [" << szSection << "][" << szKey << "] in file [" << m_szFileName << "]. Defaulting to [0].";
|
||||||
|
iniErrorMessages.push(errMessage.str());
|
||||||
|
|
||||||
|
vec.push_back(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CIniReader::ReadINT32Array(const STR8 szSection, const STR8 szKey, std::vector<INT32>& vec)
|
||||||
|
{
|
||||||
|
// read the array as a string
|
||||||
|
STRING512 textBuffer;
|
||||||
|
ReadString(szSection, szKey, "", textBuffer, _countof(textBuffer));
|
||||||
|
|
||||||
|
std::string str, token;
|
||||||
|
std::string delim = ",";
|
||||||
|
size_t offset = 0, prevOffset = 0;
|
||||||
|
|
||||||
|
// sanitise input
|
||||||
|
vec.clear();
|
||||||
|
str = textBuffer;
|
||||||
|
str.erase(std::remove(str.begin(), str.end(), ' '), str.end());
|
||||||
|
|
||||||
|
// split into array
|
||||||
|
try
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
offset = str.find(delim, prevOffset);
|
||||||
|
token = str.substr(prevOffset, offset - prevOffset);
|
||||||
|
prevOffset = offset + delim.length();
|
||||||
|
|
||||||
|
vec.push_back(std::stoi(token.c_str()));
|
||||||
|
} while (offset != std::string::npos);
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
std::stringstream errMessage;
|
||||||
|
errMessage << "There was an error reading array [" << szSection << "][" << szKey << "] in file [" << m_szFileName << "]. Defaulting to [0].";
|
||||||
|
iniErrorMessages.push(errMessage.str());
|
||||||
|
|
||||||
|
vec.push_back(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BOOLEAN CIniReader::ReadBoolean(const STR8 szSection, const STR8 szKey, bool defaultValue, bool bolDisplayError)
|
BOOLEAN CIniReader::ReadBoolean(const STR8 szSection, const STR8 szKey, bool defaultValue, bool bolDisplayError)
|
||||||
{
|
{
|
||||||
#ifndef USE_VFS
|
#ifndef USE_VFS
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ public:
|
|||||||
DOUBLE ReadDouble(const STR8 szSection, const STR8 szKey, DOUBLE defaultValue, DOUBLE minValue, DOUBLE maxValue);
|
DOUBLE ReadDouble(const STR8 szSection, const STR8 szKey, DOUBLE defaultValue, DOUBLE minValue, DOUBLE maxValue);
|
||||||
FLOAT ReadFloat (const STR8 szSection, const STR8 szKey, FLOAT defaultValue, FLOAT minValue, FLOAT maxValue);
|
FLOAT ReadFloat (const STR8 szSection, const STR8 szKey, FLOAT defaultValue, FLOAT minValue, FLOAT maxValue);
|
||||||
|
|
||||||
|
void ReadFloatArray(const STR8 szSection, const STR8 szKey, std::vector<FLOAT>& vec);
|
||||||
|
void ReadINT32Array(const STR8 szSection, const STR8 szKey, std::vector<INT32>& vec);
|
||||||
|
|
||||||
BOOLEAN ReadBoolean(const STR8 szSection, const STR8 szKey, bool bolDefaultValue, bool bolDisplayError = true);
|
BOOLEAN ReadBoolean(const STR8 szSection, const STR8 szKey, bool bolDefaultValue, bool bolDisplayError = true);
|
||||||
|
|
||||||
void ReadString(const STR8 szSection, const STR8 szKey, const STR8 szDefaultValue, STR8 input_buffer, size_t buffer_size);
|
void ReadString(const STR8 szSection, const STR8 szKey, const STR8 szDefaultValue, STR8 input_buffer, size_t buffer_size);
|
||||||
|
|||||||
Reference in New Issue
Block a user