mirror of
https://github.com/1dot13/source.git
synced 2026-08-05 14:00:23 +02:00
**********************************************************
** Big Maps Projects code (incl. Multiplayer v1.5 ** ********************************************************** - Merged Big Maps Project code from BMP+MP trunk (Revision: 3340) o Complete SVN Revision history: https://81.169.133.124/source/ja2/branches/Wanne/JA2%201.13%20MP - Before THIS merge, I made a branch of the existing 1.13 source o SVN Branch: https://81.169.133.124/source/ja2/branches/JA2_rev.3336/src - Removed old VS 6.0 and VS 2003 project and solutions files, because compilation is broken long time ago - I will add VS 2010 projects and solution file in the next few days git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@3341 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
+234
-225
@@ -1,10 +1,11 @@
|
||||
#include "vfs_config.h"
|
||||
#include "PropertyContainer.h"
|
||||
|
||||
#include "vfs.h"
|
||||
#include "File/vfs_file.h"
|
||||
#include "File/vfs_memory_file.h"
|
||||
#include "vfs_file_raii.h"
|
||||
#include "iteratedir.h"
|
||||
#include "os_functions.h"
|
||||
|
||||
#include "Tools/Tools.h"
|
||||
#include "Tools/ParserTools.h"
|
||||
@@ -12,9 +13,13 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
/*************************************************************************************/
|
||||
/*************************************************************************************/
|
||||
|
||||
/*************************************************************************************/
|
||||
/*************************************************************************************/
|
||||
bool CPropertyContainer::CSection::has(utf8string const& key)
|
||||
{
|
||||
return mapProps.find(key) != mapProps.end();
|
||||
}
|
||||
|
||||
bool CPropertyContainer::CSection::add(utf8string const& key, utf8string const& value)
|
||||
{
|
||||
@@ -40,7 +45,7 @@ bool CPropertyContainer::CSection::value(utf8string const& key, utf8string& valu
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void CPropertyContainer::CSection::Print(std::ostream& out, utf8string::str_t sPrefix)
|
||||
void CPropertyContainer::CSection::print(std::ostream& out, utf8string::str_t sPrefix)
|
||||
{
|
||||
tProps::iterator sit = mapProps.begin();
|
||||
for(; sit != mapProps.end(); ++sit)
|
||||
@@ -49,184 +54,178 @@ void CPropertyContainer::CSection::Print(std::ostream& out, utf8string::str_t sP
|
||||
}
|
||||
}
|
||||
|
||||
void CPropertyContainer::CSection::Clear()
|
||||
void CPropertyContainer::CSection::clear()
|
||||
{
|
||||
mapProps.clear();
|
||||
}
|
||||
|
||||
/*************************************************************************************/
|
||||
/*************************************************************************************/
|
||||
void CPropertyContainer::ClearContainer()
|
||||
void CPropertyContainer::clearContainer()
|
||||
{
|
||||
tSections::iterator it = m_mapProps.begin();
|
||||
for(;it != m_mapProps.end(); ++it)
|
||||
{
|
||||
it->second.Clear();
|
||||
it->second.clear();
|
||||
}
|
||||
m_mapProps.clear();
|
||||
}
|
||||
|
||||
bool CPropertyContainer::ExtractSection(utf8string::str_t const& readStr, size_t startPos, utf8string::str_t& sSection)
|
||||
bool CPropertyContainer::extractSection(utf8string::str_t const& readStr, vfs::size_t startPos, utf8string::str_t& sSection)
|
||||
{
|
||||
// extract section name
|
||||
unsigned int close = readStr.find_first_of(L"]",startPos);
|
||||
if( close > 0 && close > startPos)
|
||||
vfs::size_t close = readStr.find_first_of(L"]", startPos);
|
||||
if( close != vfs::npos && close > startPos)
|
||||
{
|
||||
startPos += 1;
|
||||
sSection = vfs::TrimString(readStr,startPos,close-1);
|
||||
sSection = vfs::trimString(readStr,startPos,(vfs::size_t)(close-1));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CPropertyContainer::EOperation CPropertyContainer::ExtractKeyValue(utf8string::str_t const &readStr, size_t startPos, utf8string::str_t& sKey, utf8string::str_t& sValue)
|
||||
CPropertyContainer::EOperation CPropertyContainer::extractKeyValue(utf8string::str_t const &readStr, vfs::size_t startPos, utf8string::str_t& sKey, utf8string::str_t& sValue)
|
||||
{
|
||||
vfs::Int32 iEqual = readStr.find_first_of(L"+=",startPos);
|
||||
if(iEqual < 0)
|
||||
vfs::size_t iEqual = readStr.find_first_of(L"+=", startPos);
|
||||
if(iEqual == vfs::npos)
|
||||
{
|
||||
//std::cout << "WARNING : could not extract key-value pair : " << readStr << std::endl;
|
||||
return CPropertyContainer::Error;
|
||||
}
|
||||
// extract key
|
||||
sKey = vfs::TrimString(readStr,0,iEqual-1);
|
||||
sKey = vfs::trimString(readStr,0,iEqual-1);
|
||||
// extract value
|
||||
EOperation op = CPropertyContainer::Set;
|
||||
if( readStr.at(iEqual) == L'+' )
|
||||
{
|
||||
if( (vfs::UInt32)(iEqual+1) < readStr.size() && (readStr.at((vfs::UInt32)(iEqual+1)) == L'=') )
|
||||
if( (iEqual+1) < readStr.size() && (readStr.at(iEqual+1) == L'=') )
|
||||
{
|
||||
iEqual += 1;
|
||||
op = CPropertyContainer::Add;
|
||||
}
|
||||
}
|
||||
sValue = vfs::TrimString(readStr,iEqual+1,readStr.size());
|
||||
sValue = vfs::trimString(readStr,iEqual+1,readStr.size());
|
||||
return op;
|
||||
}
|
||||
|
||||
|
||||
bool CPropertyContainer::InitFromIniFile(vfs::Path const& sFileName)
|
||||
bool CPropertyContainer::initFromIniFile(vfs::Path const& sFileName)
|
||||
{
|
||||
// try to open via VirtualFileSystem
|
||||
if(GetVFS()->FileExists(sFileName))
|
||||
if(getVFS()->fileExists(sFileName))
|
||||
{
|
||||
return InitFromIniFile(GetVFS()->GetRFile(sFileName));
|
||||
return initFromIniFile(getVFS()->getReadFile(sFileName));
|
||||
}
|
||||
else
|
||||
{
|
||||
// file doesn't exist or VFS not initialized yet
|
||||
vfs::IBaseFile* pFile = new vfs::CTextFile(sFileName);
|
||||
if(pFile)
|
||||
{
|
||||
bool success = InitFromIniFile(vfs::tReadableFile::Cast(pFile));
|
||||
delete pFile;
|
||||
return success;
|
||||
}
|
||||
vfs::CFile file(sFileName);
|
||||
return initFromIniFile(vfs::tReadableFile::cast(&file));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::InitFromIniFile(vfs::tReadableFile *pFile)
|
||||
bool CPropertyContainer::initFromIniFile(vfs::tReadableFile *pFile)
|
||||
{
|
||||
if(pFile && pFile->OpenRead())
|
||||
if(!pFile)
|
||||
{
|
||||
vfs::COpenReadFile rfile(pFile);
|
||||
std::string sBuffer;
|
||||
utf8string::str_t sCurrentSection;
|
||||
int line_counter = 0;
|
||||
CReadLine rl(*pFile);
|
||||
while(rl.GetLine(sBuffer))
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string sBuffer;
|
||||
utf8string::str_t sCurrentSection;
|
||||
int line_counter = 0;
|
||||
CReadLine rl(*pFile);
|
||||
while(rl.getLine(sBuffer))
|
||||
{
|
||||
line_counter++;
|
||||
// very simple parsing : key = value
|
||||
if(!sBuffer.empty())
|
||||
{
|
||||
line_counter++;
|
||||
// very simple parsing : key = value
|
||||
if(!sBuffer.empty())
|
||||
// remove leading white spaces
|
||||
::size_t iStart = sBuffer.find_first_not_of(" \t",0);
|
||||
if(iStart == std::string::npos)
|
||||
{
|
||||
// remove leading white spaces
|
||||
unsigned int iStart = sBuffer.find_first_not_of(" \t",0);
|
||||
if(iStart == std::string::npos)
|
||||
// only white space characters
|
||||
continue;
|
||||
}
|
||||
char first = sBuffer.at(iStart);
|
||||
switch(first)
|
||||
{
|
||||
case '!':
|
||||
case ';':
|
||||
case '#':
|
||||
// comment -> do nothing
|
||||
break;
|
||||
case '[':
|
||||
{
|
||||
// only white space characters
|
||||
continue;
|
||||
}
|
||||
char first = sBuffer.at(iStart);
|
||||
switch(first)
|
||||
{
|
||||
case '!':
|
||||
case ';':
|
||||
case '#':
|
||||
// comment -> do nothing
|
||||
break;
|
||||
case '[':
|
||||
utf8string u8s;
|
||||
try
|
||||
{
|
||||
utf8string u8s;
|
||||
try
|
||||
utf8string::as_utf16(sBuffer.substr(iStart, sBuffer.length()-iStart), u8s.r_wcs());
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Conversion error in file \"" << pFile->getPath().c_wcs()
|
||||
<< L"\", line " << line_counter;
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
if(this->extractSection(u8s.c_wcs(), 0, sCurrentSection))
|
||||
{
|
||||
m_mapProps[sCurrentSection];
|
||||
}
|
||||
else
|
||||
{
|
||||
//std::cout << "WARNING : could not extract section name : " << sBuffer << std::endl;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
// probably key-value pair
|
||||
utf8string::str_t u8s;
|
||||
try
|
||||
{
|
||||
utf8string::as_utf16(sBuffer.substr(iStart, sBuffer.length()-iStart), u8s);
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Conversion error in file \"" << pFile->getPath().c_wcs()
|
||||
<< L"\", line " << line_counter;
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
utf8string::str_t sKey, sValue;
|
||||
EOperation op = this->extractKeyValue(u8s, 0, sKey, sValue);
|
||||
if(op != Error)
|
||||
{
|
||||
// add key-value pair to map
|
||||
if(m_mapProps.find(sCurrentSection) != m_mapProps.end())
|
||||
{
|
||||
utf8string::as_utf16(sBuffer.substr(iStart, sBuffer.length()-iStart), u8s.r_wcs());
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Conversion error in file \"" << pFile->GetFullPath()().c_wcs()
|
||||
<< L"\", line " << line_counter;
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
if(this->ExtractSection(u8s.c_wcs(), 0, sCurrentSection))
|
||||
{
|
||||
m_mapProps[sCurrentSection];
|
||||
if(op == Set)
|
||||
{
|
||||
this->section(sCurrentSection).value(sKey) = sValue;
|
||||
}
|
||||
else if(op == Add)
|
||||
{
|
||||
this->section(sCurrentSection).add(sKey, sValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//std::cout << "WARNING : could not extract section name : " << sBuffer << std::endl;
|
||||
//std::cout << "ERROR : could not find section ["<<sCurrentSection << "]in container" << std::endl;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
// probably key-value pair
|
||||
utf8string u8s;
|
||||
try
|
||||
{
|
||||
utf8string::as_utf16(sBuffer.substr(iStart, sBuffer.length()-iStart), u8s.r_wcs());
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Conversion error in file \"" << pFile->GetFullPath()().c_wcs()
|
||||
<< L"\", line " << line_counter;
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
utf8string::str_t sKey, sValue;
|
||||
EOperation op = this->ExtractKeyValue(u8s.c_wcs(), 0, sKey, sValue);
|
||||
if(op != Error)
|
||||
{
|
||||
// add key-value pair to map
|
||||
if(m_mapProps.find(sCurrentSection) != m_mapProps.end())
|
||||
{
|
||||
if(op == Set)
|
||||
{
|
||||
Section(sCurrentSection).value(sKey) = sValue;
|
||||
}
|
||||
else if(op == Add)
|
||||
{
|
||||
Section(sCurrentSection).add(sKey, sValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//std::cout << "ERROR : could not find section ["<<sCurrentSection << "]in container" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}; // end switch
|
||||
} // end if (empty)
|
||||
} // end while(!eof)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}; // end switch
|
||||
} // end if (empty)
|
||||
} // end while(!eof)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::WriteToIniFile(vfs::Path const& sFileName, bool bCreateNew)
|
||||
static vfs::UByte utf8bom[3] = {0xef,0xbb,0xbf};
|
||||
|
||||
bool CPropertyContainer::writeToIniFile(vfs::Path const& sFilename, bool bCreateNew)
|
||||
{
|
||||
#ifdef WIN32
|
||||
const char ENDL[] = "\r\n";
|
||||
@@ -235,43 +234,43 @@ bool CPropertyContainer::WriteToIniFile(vfs::Path const& sFileName, bool bCreate
|
||||
#endif
|
||||
if(bCreateNew)
|
||||
{
|
||||
vfs::tWriteableFile* file;
|
||||
vfs::tWritableFile* file;
|
||||
bool delete_file = false;
|
||||
try
|
||||
{
|
||||
vfs::COpenWriteFile wfile(sFileName,true,true);
|
||||
vfs::COpenWriteFile wfile(sFilename,true,true);
|
||||
file = &wfile.file();
|
||||
wfile.release();
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
LogException(ex);
|
||||
logException(ex);
|
||||
// vfs not initialized?
|
||||
vfs::CFile* cfile = new vfs::CFile(sFileName);
|
||||
cfile->OpenWrite(true,true);
|
||||
file = vfs::tWriteableFile::Cast(cfile);
|
||||
vfs::CFile* cfile = new vfs::CFile(sFilename);
|
||||
cfile->openWrite(true,true);
|
||||
file = vfs::tWritableFile::cast(cfile);
|
||||
delete_file = true;
|
||||
}
|
||||
tSections::iterator sit = m_mapProps.begin();
|
||||
std::stringstream ss;
|
||||
std::string str;
|
||||
vfs::UInt32 written;
|
||||
ss << (char*)utf8bom;
|
||||
for(; sit != m_mapProps.end(); ++sit)
|
||||
{
|
||||
ss.str("");
|
||||
ss << "[" << sit->first.utf8() << "]" << ENDL;
|
||||
str = ss.str();
|
||||
file->Write(str.c_str(),str.length(),written);
|
||||
file->write(str.c_str(), str.length());
|
||||
|
||||
ss.clear();
|
||||
ss.str("");
|
||||
CSection& section = sit->second;
|
||||
section.Print(ss);
|
||||
section.print(ss);
|
||||
ss << ENDL;
|
||||
str = ss.str();
|
||||
file->Write(str.c_str(),str.length(),written);
|
||||
file->write(str.c_str(),str.length());
|
||||
}
|
||||
file->Close();
|
||||
file->close();
|
||||
if(delete_file)
|
||||
{
|
||||
delete file;
|
||||
@@ -283,18 +282,18 @@ bool CPropertyContainer::WriteToIniFile(vfs::Path const& sFileName, bool bCreate
|
||||
// try to open via VirtualFileSystem
|
||||
vfs::tReadableFile *pFile = NULL;
|
||||
vfs::CMemoryFile rfile;
|
||||
if(GetVFS()->FileExists(sFileName))
|
||||
if(getVFS()->fileExists(sFilename))
|
||||
{
|
||||
pFile = GetVFS()->GetRFile(sFileName);
|
||||
rfile.CopyToBuffer(*pFile);
|
||||
pFile = getVFS()->getReadFile(sFilename);
|
||||
rfile.copyToBuffer(*pFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
// file doesn't exist or VFS not initialized yet
|
||||
vfs::IBaseFile* pFile = new vfs::CFile(sFileName);
|
||||
vfs::IBaseFile* pFile = new vfs::CFile(sFilename);
|
||||
if(pFile)
|
||||
{
|
||||
rfile.CopyToBuffer(*vfs::tReadableFile::Cast(pFile));
|
||||
rfile.copyToBuffer(*vfs::tReadableFile::cast(pFile));
|
||||
delete pFile;
|
||||
}
|
||||
}
|
||||
@@ -302,7 +301,6 @@ bool CPropertyContainer::WriteToIniFile(vfs::Path const& sFileName, bool bCreate
|
||||
|
||||
std::string sBuffer;
|
||||
utf8string::str_t sCurrentSection;
|
||||
vfs::UInt32 written;
|
||||
|
||||
std::set<utf8string> setKeys;
|
||||
std::set<utf8string> setSections;
|
||||
@@ -312,15 +310,16 @@ bool CPropertyContainer::WriteToIniFile(vfs::Path const& sFileName, bool bCreate
|
||||
setSections.insert(sit->first);
|
||||
}
|
||||
|
||||
CReadLine rl(*vfs::tReadableFile::Cast(&rfile));
|
||||
CReadLine rl(*vfs::tReadableFile::cast(&rfile));
|
||||
outbuffer << (char*)(utf8bom);
|
||||
vfs::UInt32 line_counter = 0;
|
||||
while(rl.GetLine(sBuffer))
|
||||
while(rl.getLine(sBuffer))
|
||||
{
|
||||
line_counter++;
|
||||
if(!sBuffer.empty())
|
||||
{
|
||||
// remove leading white spaces
|
||||
int iStart = sBuffer.find_first_not_of(" \t",0);
|
||||
::size_t iStart = sBuffer.find_first_not_of(" \t",0);
|
||||
char first = sBuffer.at(iStart);
|
||||
switch(first)
|
||||
{
|
||||
@@ -339,12 +338,12 @@ bool CPropertyContainer::WriteToIniFile(vfs::Path const& sFileName, bool bCreate
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Conversion error in file \"" << pFile->GetFullPath()().c_wcs()
|
||||
wss << L"Conversion error in file \"" << pFile->getPath().c_wcs()
|
||||
<< L"\", line " << line_counter;
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
utf8string::str_t oldSection = sCurrentSection;
|
||||
if(this->ExtractSection(u8s.c_wcs(), 0, sCurrentSection))
|
||||
if(this->extractSection(u8s.c_wcs(), 0, sCurrentSection))
|
||||
{
|
||||
if(setSections.find(sCurrentSection) == setSections.end())
|
||||
{
|
||||
@@ -388,12 +387,12 @@ bool CPropertyContainer::WriteToIniFile(vfs::Path const& sFileName, bool bCreate
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Conversion error in file \"" << pFile->GetFullPath()().c_wcs()
|
||||
wss << L"Conversion error in file \"" << pFile->getPath().c_wcs()
|
||||
<< L"\", line " << line_counter;
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
utf8string::str_t sKey, sValue;
|
||||
if(this->ExtractKeyValue(u8s.c_wcs(), 0, sKey, sValue))
|
||||
if(this->extractKeyValue(u8s.c_wcs(), 0, sKey, sValue))
|
||||
{
|
||||
if(setKeys.find(sKey) != setKeys.end())
|
||||
{
|
||||
@@ -437,57 +436,67 @@ bool CPropertyContainer::WriteToIniFile(vfs::Path const& sFileName, bool bCreate
|
||||
{
|
||||
outbuffer << ENDL << "[" << utf8string::as_utf8(*it) << "]" << ENDL;
|
||||
std::stringstream ss;
|
||||
m_mapProps[*it].Print(outbuffer);
|
||||
m_mapProps[*it].print(outbuffer);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
vfs::COpenWriteFile wfile(sFileName,true,true);
|
||||
wfile.file().Write(outbuffer.str().c_str(),outbuffer.str().length(),written);
|
||||
vfs::COpenWriteFile wfile(sFilename,true,true);
|
||||
wfile.file().write(outbuffer.str().c_str(),(vfs::size_t)outbuffer.str().length());
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
LogException(ex);
|
||||
vfs::CFile file(sFileName);
|
||||
if(file.OpenWrite(true,true))
|
||||
logException(ex);
|
||||
vfs::CFile file(sFilename);
|
||||
if(file.openWrite(true,true))
|
||||
{
|
||||
file.Write(outbuffer.str().c_str(),outbuffer.str().length(),written);
|
||||
file.Close();
|
||||
file.write(outbuffer.str().c_str(),(vfs::size_t)outbuffer.str().length());
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void CPropertyContainer::PrintProperties()
|
||||
void CPropertyContainer::printProperties()
|
||||
{
|
||||
tSections::iterator pit = m_mapProps.begin();
|
||||
for(;pit != m_mapProps.end(); ++pit)
|
||||
{
|
||||
std::cout << "[" << pit->first.utf8() << "]\n";
|
||||
pit->second.Print(std::cout, L" ");
|
||||
pit->second.print(std::cout, L" ");
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
CPropertyContainer::CSection& CPropertyContainer::Section(utf8string const& sSection)
|
||||
|
||||
CPropertyContainer::CSection& CPropertyContainer::section(utf8string const& sSection)
|
||||
{
|
||||
return m_mapProps[sSection];
|
||||
}
|
||||
|
||||
bool CPropertyContainer::GetValueForKey(utf8string const& sSection, utf8string const& sKey, utf8string &sValue)
|
||||
bool CPropertyContainer::getValueForKey(utf8string const& sSection, utf8string const& sKey, utf8string &sValue)
|
||||
{
|
||||
tSections::iterator pit = m_mapProps.find(vfs::TrimString(sSection,0,sSection.length()));
|
||||
tSections::iterator pit = m_mapProps.find(vfs::trimString(sSection,0,(vfs::size_t)sSection.length()));
|
||||
if( pit != m_mapProps.end() )
|
||||
{
|
||||
return pit->second.value( vfs::TrimString(sKey,0,sKey.length()), sValue );
|
||||
return pit->second.value( vfs::trimString(sKey,0,(vfs::size_t)sKey.length()), sValue );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
utf8string const& CPropertyContainer::GetStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string const& sDefaultValue)
|
||||
bool CPropertyContainer::hasProperty(utf8string const& sSection, utf8string const& sKey)
|
||||
{
|
||||
tSections::iterator pit = m_mapProps.find(vfs::trimString(sSection,0,(vfs::size_t)sSection.length()));
|
||||
if( pit != m_mapProps.end() )
|
||||
{
|
||||
return pit->second.has(vfs::trimString(sKey,0,sKey.length()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
utf8string const& CPropertyContainer::getStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string const& sDefaultValue)
|
||||
{
|
||||
CPropertyContainer::tSections::iterator sit = m_mapProps.find(sSection);
|
||||
if(sit != m_mapProps.end())
|
||||
@@ -501,9 +510,9 @@ utf8string const& CPropertyContainer::GetStringProperty(utf8string const& sSecti
|
||||
return sDefaultValue;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::GetStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string& sValue, utf8string const& sDefaultValue)
|
||||
bool CPropertyContainer::getStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string& sValue, utf8string const& sDefaultValue)
|
||||
{
|
||||
if(GetValueForKey(sSection,sKey,sValue))
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -511,34 +520,34 @@ bool CPropertyContainer::GetStringProperty(utf8string const& sSection, utf8strin
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::GetStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string::char_t* sValue, vfs::UInt32 len, utf8string const& sDefaultValue)
|
||||
bool CPropertyContainer::getStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string::char_t* sValue, vfs::size_t len, utf8string const& sDefaultValue)
|
||||
{
|
||||
utf8string s;
|
||||
if(GetValueForKey(sSection,sKey,s))
|
||||
if(getValueForKey(sSection,sKey,s))
|
||||
{
|
||||
vfs::UInt32 l = std::min<vfs::UInt32>(s.length(), len-1);
|
||||
wcsncpy(sValue,s.c_wcs().c_str(), l);
|
||||
vfs::size_t l = std::min<vfs::size_t>(s.length(), len-1);
|
||||
wcsncpy(sValue,s.c_str(), l);
|
||||
sValue[l] = 0;
|
||||
return true;
|
||||
}
|
||||
vfs::UInt32 l = std::min<vfs::UInt32>(sDefaultValue.length(), len-1);
|
||||
wcsncpy(sValue,sDefaultValue.c_wcs().c_str(), l);
|
||||
vfs::size_t l = std::min<vfs::size_t>(sDefaultValue.length(), len-1);
|
||||
wcsncpy(sValue,sDefaultValue.c_str(), l);
|
||||
sValue[l] = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
vfs::Int64 CPropertyContainer::GetIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 iDefaultValue, vfs::Int64 iMinValue, vfs::Int64 iMaxValue)
|
||||
vfs::Int64 CPropertyContainer::getIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 iDefaultValue, vfs::Int64 iMinValue, vfs::Int64 iMaxValue)
|
||||
{
|
||||
return std::min<vfs::Int64>(iMaxValue, std::max<vfs::Int64>(iMinValue, GetIntProperty(sSection, sKey, iDefaultValue)));
|
||||
return std::min<vfs::Int64>(iMaxValue, std::max<vfs::Int64>(iMinValue, this->getIntProperty(sSection, sKey, iDefaultValue)));
|
||||
}
|
||||
|
||||
vfs::Int64 CPropertyContainer::GetIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 iDefaultValue)
|
||||
vfs::Int64 CPropertyContainer::getIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 iDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(GetValueForKey(sSection,sKey,sValue))
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
vfs::Int64 iRetVal;
|
||||
if(ConvertTo<vfs::Int64>(sValue,iRetVal))
|
||||
if(convertTo<vfs::Int64>(sValue,iRetVal))
|
||||
{
|
||||
return iRetVal;
|
||||
}
|
||||
@@ -546,18 +555,18 @@ vfs::Int64 CPropertyContainer::GetIntProperty(utf8string const& sSection, utf8st
|
||||
return iDefaultValue;
|
||||
}
|
||||
|
||||
vfs::UInt64 CPropertyContainer::GetUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 iDefaultValue, vfs::UInt64 iMinValue, vfs::UInt64 iMaxValue)
|
||||
vfs::UInt64 CPropertyContainer::getUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 iDefaultValue, vfs::UInt64 iMinValue, vfs::UInt64 iMaxValue)
|
||||
{
|
||||
return std::min<vfs::UInt64>(iMaxValue, std::max<vfs::UInt64>(iMinValue, GetIntProperty(sSection, sKey, iDefaultValue)));
|
||||
return std::min<vfs::UInt64>(iMaxValue, std::max<vfs::UInt64>(iMinValue, this->getIntProperty(sSection, sKey, iDefaultValue)));
|
||||
}
|
||||
|
||||
vfs::UInt64 CPropertyContainer::GetUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 iDefaultValue)
|
||||
vfs::UInt64 CPropertyContainer::getUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 iDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(GetValueForKey(sSection,sKey,sValue))
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
vfs::UInt64 iRetVal;
|
||||
if(ConvertTo<vfs::UInt64>(sValue,iRetVal))
|
||||
if(convertTo<vfs::UInt64>(sValue,iRetVal))
|
||||
{
|
||||
return iRetVal;
|
||||
}
|
||||
@@ -565,18 +574,18 @@ vfs::UInt64 CPropertyContainer::GetUIntProperty(utf8string const& sSection, utf8
|
||||
return iDefaultValue;
|
||||
}
|
||||
|
||||
double CPropertyContainer::GetFloatProperty(utf8string const& sSection, utf8string const& sKey, double fDefaultValue, double fMinValue, double fMaxValue)
|
||||
double CPropertyContainer::getFloatProperty(utf8string const& sSection, utf8string const& sKey, double fDefaultValue, double fMinValue, double fMaxValue)
|
||||
{
|
||||
return std::min<double>(fMaxValue, std::max<double>(fMinValue, GetFloatProperty(sSection, sKey, fDefaultValue)));
|
||||
return std::min<double>(fMaxValue, std::max<double>(fMinValue, this->getFloatProperty(sSection, sKey, fDefaultValue)));
|
||||
}
|
||||
|
||||
double CPropertyContainer::GetFloatProperty(utf8string const& sSection, utf8string const& sKey, double fDefaultValue)
|
||||
double CPropertyContainer::getFloatProperty(utf8string const& sSection, utf8string const& sKey, double fDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(GetValueForKey(sSection,sKey,sValue))
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
double fRetVal;
|
||||
if(ConvertTo<double>(sValue,fRetVal))
|
||||
if(convertTo<double>(sValue,fRetVal))
|
||||
{
|
||||
return fRetVal;
|
||||
}
|
||||
@@ -584,17 +593,17 @@ double CPropertyContainer::GetFloatProperty(utf8string const& sSection, utf8stri
|
||||
return fDefaultValue;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::GetBoolProperty(utf8string const& sSection, utf8string const& sKey, bool bDefaultValue)
|
||||
bool CPropertyContainer::getBoolProperty(utf8string const& sSection, utf8string const& sKey, bool bDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(GetValueForKey(sSection,sKey,sValue))
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
int iRetVal;
|
||||
if( StrCmp::Equal(sValue,L"true") || ( ConvertTo<vfs::Int32>(sValue,iRetVal) && (iRetVal != 0) ) )
|
||||
vfs::Int32 iRetVal;
|
||||
if( StrCmp::Equal(sValue,L"true") || ( convertTo<>(sValue,iRetVal) && (iRetVal != 0) ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if( StrCmp::Equal(sValue,"false") || ( ConvertTo<vfs::Int32>(sValue,iRetVal) && (iRetVal == 0) ) )
|
||||
else if( StrCmp::Equal(sValue,"false") || ( convertTo<>(sValue,iRetVal) && (iRetVal == 0) ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -603,33 +612,33 @@ bool CPropertyContainer::GetBoolProperty(utf8string const& sSection, utf8string
|
||||
return bDefaultValue;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::GetStringListProperty(utf8string const& sSection, utf8string const& sKey, std::list<utf8string> &lValueList, utf8string sDefaultValue)
|
||||
bool CPropertyContainer::getStringListProperty(utf8string const& sSection, utf8string const& sKey, std::list<utf8string> &lValueList, utf8string sDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(GetValueForKey(sSection,sKey,sValue))
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
utf8string entry;
|
||||
CSplitStringList splitter(sValue);
|
||||
while(splitter.NextListEntry(entry))
|
||||
while(splitter.nextListEntry(entry))
|
||||
{
|
||||
lValueList.push_back(vfs::TrimString(entry,0,entry.length()));
|
||||
lValueList.push_back(vfs::trimString(entry,0,entry.length()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::GetIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::Int64> &lValueList, vfs::Int64 iDefaultValue)
|
||||
bool CPropertyContainer::getIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::Int64> &lValueList, vfs::Int64 iDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(GetValueForKey(sSection,sKey,sValue))
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
utf8string entry;
|
||||
CSplitStringList splitter(sValue);
|
||||
while(splitter.NextListEntry(entry))
|
||||
while(splitter.nextListEntry(entry))
|
||||
{
|
||||
vfs::Int64 iRetVal;
|
||||
if(ConvertTo<vfs::Int64>(entry,iRetVal))
|
||||
if(convertTo<vfs::Int64>(entry,iRetVal))
|
||||
{
|
||||
lValueList.push_back(iRetVal);
|
||||
}
|
||||
@@ -643,17 +652,17 @@ bool CPropertyContainer::GetIntListProperty(utf8string const& sSection, utf8stri
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::GetUIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::UInt64> &lValueList, vfs::UInt64 iDefaultValue)
|
||||
bool CPropertyContainer::getUIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::UInt64> &lValueList, vfs::UInt64 iDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(GetValueForKey(sSection,sKey,sValue))
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
utf8string entry;
|
||||
CSplitStringList splitter(sValue);
|
||||
while(splitter.NextListEntry(entry))
|
||||
while(splitter.nextListEntry(entry))
|
||||
{
|
||||
vfs::UInt64 iRetVal;
|
||||
if(ConvertTo<vfs::UInt64>(entry,iRetVal))
|
||||
if(convertTo<vfs::UInt64>(entry,iRetVal))
|
||||
{
|
||||
lValueList.push_back(iRetVal);
|
||||
}
|
||||
@@ -666,17 +675,17 @@ bool CPropertyContainer::GetUIntListProperty(utf8string const& sSection, utf8str
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool CPropertyContainer::GetFloatListProperty(utf8string const& sSection, utf8string const& sKey, std::list<double> &lValueList, double fDefaultValue)
|
||||
bool CPropertyContainer::getFloatListProperty(utf8string const& sSection, utf8string const& sKey, std::list<double> &lValueList, double fDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(GetValueForKey(sSection,sKey,sValue))
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
utf8string entry;
|
||||
CSplitStringList splitter(sValue);
|
||||
while(splitter.NextListEntry(entry))
|
||||
while(splitter.nextListEntry(entry))
|
||||
{
|
||||
double fRetVal;
|
||||
if(ConvertTo<double>(entry,fRetVal))
|
||||
if(convertTo<double>(entry,fRetVal))
|
||||
{
|
||||
lValueList.push_back(fRetVal);
|
||||
}
|
||||
@@ -690,21 +699,21 @@ bool CPropertyContainer::GetFloatListProperty(utf8string const& sSection, utf8st
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::GetBoolListProperty(utf8string const& sSection, utf8string const& sKey, std::list<bool> &lValueList, bool bDefaultValue)
|
||||
bool CPropertyContainer::getBoolListProperty(utf8string const& sSection, utf8string const& sKey, std::list<bool> &lValueList, bool bDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(GetValueForKey(sSection,sKey,sValue))
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
utf8string entry;
|
||||
CSplitStringList splitter(sValue);
|
||||
while(splitter.NextListEntry(entry))
|
||||
while(splitter.nextListEntry(entry))
|
||||
{
|
||||
int iRetVal;
|
||||
if( StrCmp::Equal(entry,L"true") || ( ConvertTo<vfs::Int32>(entry,iRetVal) && (iRetVal != 0) ) )
|
||||
vfs::Int32 iRetVal;
|
||||
if( StrCmp::Equal(entry,L"true") || ( convertTo<>(entry,iRetVal) && (iRetVal != 0) ) )
|
||||
{
|
||||
lValueList.push_back(true);
|
||||
}
|
||||
else if( StrCmp::Equal(entry,L"false") || ( ConvertTo<vfs::Int32>(entry,iRetVal) && (iRetVal == 0) ) )
|
||||
else if( StrCmp::Equal(entry,L"false") || ( convertTo<>(entry,iRetVal) && (iRetVal == 0) ) )
|
||||
{
|
||||
lValueList.push_back(false);
|
||||
}
|
||||
@@ -718,46 +727,46 @@ bool CPropertyContainer::GetBoolListProperty(utf8string const& sSection, utf8str
|
||||
return false;
|
||||
}
|
||||
|
||||
void CPropertyContainer::SetStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string const& sValue)
|
||||
void CPropertyContainer::setStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string const& sValue)
|
||||
{
|
||||
Section(sSection).value(sKey) = sValue;
|
||||
this->section(sSection).value(sKey) = sValue;
|
||||
}
|
||||
|
||||
void CPropertyContainer::SetIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 const& iValue)
|
||||
void CPropertyContainer::setIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 const& iValue)
|
||||
{
|
||||
Section(sSection).value(sKey) = ToString<wchar_t,vfs::Int64>(iValue);
|
||||
this->section(sSection).value(sKey) = toString<wchar_t,vfs::Int64>(iValue);
|
||||
}
|
||||
void CPropertyContainer::SetUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 const& iValue)
|
||||
void CPropertyContainer::setUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 const& iValue)
|
||||
{
|
||||
Section(sSection).value(sKey) = ToString<wchar_t,vfs::UInt64>(iValue);
|
||||
this->section(sSection).value(sKey) = toString<wchar_t,vfs::UInt64>(iValue);
|
||||
}
|
||||
void CPropertyContainer::SetFloatProperty(utf8string const& sSection, utf8string const& sKey, double const& fValue)
|
||||
void CPropertyContainer::setFloatProperty(utf8string const& sSection, utf8string const& sKey, double const& fValue)
|
||||
{
|
||||
Section(sSection).value(sKey) = ToString<wchar_t,double>(fValue);
|
||||
this->section(sSection).value(sKey) = toString<wchar_t,double>(fValue);
|
||||
}
|
||||
void CPropertyContainer::SetBoolProperty(utf8string const& sSection, utf8string const& sKey, bool const& bValue)
|
||||
void CPropertyContainer::setBoolProperty(utf8string const& sSection, utf8string const& sKey, bool const& bValue)
|
||||
{
|
||||
Section(sSection).value(sKey) = ToString<wchar_t,bool>(bValue);
|
||||
this->section(sSection).value(sKey) = toString<wchar_t,bool>(bValue);
|
||||
}
|
||||
|
||||
void CPropertyContainer::SetStringListProperty(utf8string const& sSection, utf8string const& sKey, std::list<utf8string> const& slValue)
|
||||
void CPropertyContainer::setStringListProperty(utf8string const& sSection, utf8string const& sKey, std::list<utf8string> const& slValue)
|
||||
{
|
||||
Section(sSection).value(sKey) = ToStringList<utf8string>(slValue);
|
||||
this->section(sSection).value(sKey) = toStringList<utf8string>(slValue);
|
||||
}
|
||||
|
||||
void CPropertyContainer::SetIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::Int64> const& ilValue)
|
||||
void CPropertyContainer::setIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::Int64> const& ilValue)
|
||||
{
|
||||
Section(sSection).value(sKey) = ToStringList<vfs::Int64>(ilValue);
|
||||
this->section(sSection).value(sKey) = toStringList<vfs::Int64>(ilValue);
|
||||
}
|
||||
|
||||
void CPropertyContainer::SetFloatListProperty(utf8string const& sSection, utf8string const& sKey, std::list<double> const& flValue)
|
||||
void CPropertyContainer::setFloatListProperty(utf8string const& sSection, utf8string const& sKey, std::list<double> const& flValue)
|
||||
{
|
||||
Section(sSection).value(sKey) = ToStringList<double>(flValue);
|
||||
this->section(sSection).value(sKey) = toStringList<double>(flValue);
|
||||
}
|
||||
|
||||
void CPropertyContainer::SetBoolListProperty(utf8string const& sSection, utf8string const& sKey, std::list<bool> const& blValue)
|
||||
void CPropertyContainer::setBoolListProperty(utf8string const& sSection, utf8string const& sKey, std::list<bool> const& blValue)
|
||||
{
|
||||
Section(sSection).value(sKey) = ToStringList<bool>(blValue);
|
||||
this->section(sSection).value(sKey) = toStringList<bool>(blValue);
|
||||
}
|
||||
|
||||
/**************************************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user