changed: ConfParser -- now we can have a tree (spaces can have more than one level)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@768 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -14,12 +14,399 @@
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* Space
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
Space::Space()
|
||||
{
|
||||
parent = 0;
|
||||
}
|
||||
|
||||
|
||||
Space::~Space()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
Space::Space(const Space & s)
|
||||
{
|
||||
operator=(s);
|
||||
}
|
||||
|
||||
|
||||
Space & Space::operator=(const Space & s)
|
||||
{
|
||||
Clear();
|
||||
|
||||
name = s.name;
|
||||
table_single = s.table_single;
|
||||
table = s.table;
|
||||
parent = s.parent;
|
||||
|
||||
for(size_t i=0 ; i<s.spaces.size() ; ++i)
|
||||
{
|
||||
Space * pspace = new Space(*s.spaces[i]);
|
||||
pspace->parent = this;
|
||||
spaces.push_back(pspace);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Space::Clear()
|
||||
{
|
||||
name.clear();
|
||||
table_single.clear();
|
||||
table.clear();
|
||||
|
||||
for(size_t i=0 ; i<spaces.size() ; ++i)
|
||||
delete spaces[i];
|
||||
|
||||
spaces.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::wstring * Space::GetValue(const wchar_t * name)
|
||||
{
|
||||
tmp_name = name;
|
||||
return GetValue(tmp_name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::wstring * Space::GetValue(const std::wstring & name)
|
||||
{
|
||||
TableSingle::iterator i = table_single.find(name);
|
||||
|
||||
if( i != table_single.end() )
|
||||
{
|
||||
return &i->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
Table::iterator t = table.find(name);
|
||||
|
||||
if( t == table.end() || t->second.empty() )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return &t->second[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
std::wstring & Space::Text(const wchar_t * name)
|
||||
{
|
||||
tmp_name = name;
|
||||
return Text(tmp_name, L"");
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::wstring & Space::Text(const wchar_t * name, const wchar_t * def)
|
||||
{
|
||||
tmp_name = name;
|
||||
return Text(tmp_name, def);
|
||||
}
|
||||
|
||||
|
||||
std::wstring & Space::Text(const std::wstring & name, const wchar_t * def)
|
||||
{
|
||||
std::wstring * value = GetValue(name);
|
||||
|
||||
if( value )
|
||||
{
|
||||
return *value;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_value_text = def;
|
||||
return tmp_value_text;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string & Space::AText(const wchar_t * name)
|
||||
{
|
||||
tmp_name = name;
|
||||
return AText(tmp_name, "");
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string & Space::AText(const wchar_t * name, const char * def)
|
||||
{
|
||||
tmp_name = name;
|
||||
return AText(tmp_name, def);
|
||||
}
|
||||
|
||||
|
||||
std::string & Space::AText(const std::wstring & name, const char * def)
|
||||
{
|
||||
std::wstring * value = GetValue(name);
|
||||
|
||||
if( value )
|
||||
{
|
||||
Ezc::WideToUTF8(*value, tmp_value_text_ascii);
|
||||
return tmp_value_text_ascii;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_value_text_ascii = def;
|
||||
return tmp_value_text_ascii;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int Space::Int(const wchar_t * name)
|
||||
{
|
||||
tmp_name = name;
|
||||
return Int(tmp_name, 0);
|
||||
}
|
||||
|
||||
|
||||
int Space::Int(const wchar_t * name, int def)
|
||||
{
|
||||
tmp_name = name;
|
||||
return Int(tmp_name, def);
|
||||
}
|
||||
|
||||
|
||||
int Space::ToInt(const std::wstring & value)
|
||||
{
|
||||
long res = (value[0] == '0')? wcstol(value.c_str() + 1, 0, 8) : wcstol(value.c_str(), 0, 10);
|
||||
|
||||
return static_cast<int>(res);
|
||||
}
|
||||
|
||||
|
||||
int Space::Int(const std::wstring & name, int def)
|
||||
{
|
||||
std::wstring * value = GetValue(name);
|
||||
|
||||
if( value )
|
||||
return ToInt(*value);
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
|
||||
size_t Space::Size(const wchar_t * name)
|
||||
{
|
||||
tmp_name = name;
|
||||
return Size(tmp_name, 0);
|
||||
}
|
||||
|
||||
|
||||
size_t Space::Size(const wchar_t * name, size_t def)
|
||||
{
|
||||
tmp_name = name;
|
||||
return Size(tmp_name, def);
|
||||
}
|
||||
|
||||
|
||||
|
||||
size_t Space::ToSize(const std::wstring & value)
|
||||
{
|
||||
unsigned long res = (value[0] == '0')? wcstoul(value.c_str() + 1, 0, 8) : wcstoul(value.c_str(), 0, 10);
|
||||
|
||||
return static_cast<size_t>(res);
|
||||
}
|
||||
|
||||
|
||||
size_t Space::Size(const std::wstring & name, size_t def)
|
||||
{
|
||||
std::wstring * value = GetValue(name);
|
||||
|
||||
if( value )
|
||||
return ToSize(*value);
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool Space::Bool(const wchar_t * name)
|
||||
{
|
||||
tmp_name = name;
|
||||
return Bool(tmp_name, false);
|
||||
}
|
||||
|
||||
|
||||
bool Space::Bool(const wchar_t * name, bool def)
|
||||
{
|
||||
tmp_name = name;
|
||||
return Bool(tmp_name, def);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Space::ToBool(const std::wstring & value)
|
||||
{
|
||||
return ( EqualNoCase(value.c_str(), L"true") ||
|
||||
EqualNoCase(value.c_str(), L"yes") ||
|
||||
EqualNoCase(value.c_str(), L"1")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
bool Space::Bool(const std::wstring & name, bool def)
|
||||
{
|
||||
std::wstring * value = GetValue(name);
|
||||
|
||||
if( value )
|
||||
return ToBool(*value);
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// in lists we don't use default values
|
||||
bool Space::ListText(const wchar_t * name, std::vector<std::wstring> & list)
|
||||
{
|
||||
tmp_name = name;
|
||||
return ListText(tmp_name, list);
|
||||
}
|
||||
|
||||
|
||||
bool Space::ListText(const std::wstring & name, std::vector<std::wstring> & list)
|
||||
{
|
||||
list.clear();
|
||||
TableSingle::iterator i = table_single.find(name);
|
||||
|
||||
if( i != table_single.end() )
|
||||
{
|
||||
list.push_back(i->second);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Table::iterator t = table.find(name);
|
||||
|
||||
if( t != table.end() )
|
||||
{
|
||||
list = t->second;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
wchar_t Space::ToSmall(wchar_t c)
|
||||
{
|
||||
if( c>='A' && c<='Z' )
|
||||
c = c - 'A' + 'a';
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
bool Space::EqualNoCase(const wchar_t * str1, const wchar_t * str2)
|
||||
{
|
||||
while( *str1 && *str2 && ToSmall(*str1) == ToSmall(*str2) )
|
||||
{
|
||||
++str1;
|
||||
++str2;
|
||||
}
|
||||
|
||||
if( *str1 == 0 && *str2 == 0 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Space::Print(std::wostream & out)
|
||||
{
|
||||
out << "Space name: " << name << std::endl;
|
||||
|
||||
out << "table_single: " << std::endl;
|
||||
TableSingle::iterator i1;
|
||||
|
||||
for(i1 = table_single.begin() ; i1 != table_single.end() ; ++i1)
|
||||
out << i1->first << '=' << i1->second << std::endl;
|
||||
|
||||
out << "table: " << std::endl;
|
||||
|
||||
Table::iterator i2;
|
||||
Value::iterator i3;
|
||||
|
||||
for(i2 = table.begin() ; i2 != table.end() ; ++i2)
|
||||
{
|
||||
out << i2->first << '=';
|
||||
|
||||
for(i3 = i2->second.begin() ; i3 != i2->second.end() ; ++i3)
|
||||
out << *i3 << ',';
|
||||
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
for(size_t i=0 ; i<spaces.size() ; ++i)
|
||||
spaces[i]->Print(out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* ConfParser
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ConfParser::ConfParser()
|
||||
{
|
||||
root_space = 0;
|
||||
SetDefault();
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::SetSpace(Space * pspace)
|
||||
{
|
||||
root_space = pspace;
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::SetSpace(Space & pspace)
|
||||
{
|
||||
root_space = &pspace;
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::SetDefault()
|
||||
{
|
||||
// you can change this separators to what you want
|
||||
@@ -34,11 +421,6 @@ void ConfParser::SetDefault()
|
||||
skip_empty = false;
|
||||
use_escape_char = true;
|
||||
input_as_utf8 = false;
|
||||
|
||||
default_str = L"";
|
||||
default_int = 0;
|
||||
default_size = 0;
|
||||
default_bool = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,23 +449,9 @@ void ConfParser::UTF8(bool utf)
|
||||
|
||||
|
||||
|
||||
void ConfParser::Clear()
|
||||
{
|
||||
space.table.clear();
|
||||
space.table_single.clear();
|
||||
spaces.clear();
|
||||
|
||||
line = 1;
|
||||
using_global_space = true;
|
||||
pchar_ascii = 0;
|
||||
pchar_unicode = 0;
|
||||
status = ok;
|
||||
}
|
||||
|
||||
|
||||
ConfParser::Status ConfParser::Parse(const char * file_name)
|
||||
{
|
||||
Clear();
|
||||
reading_from_file = true;
|
||||
|
||||
file.clear();
|
||||
@@ -129,10 +497,10 @@ ConfParser::Status ConfParser::Parse(const std::wstring & file_name)
|
||||
|
||||
ConfParser::Status ConfParser::ParseString(const char * str)
|
||||
{
|
||||
Clear();
|
||||
reading_from_file = false;
|
||||
reading_from_wchar_string = false;
|
||||
pchar_ascii = str;
|
||||
pchar_unicode = 0;
|
||||
|
||||
Parse();
|
||||
|
||||
@@ -148,10 +516,10 @@ ConfParser::Status ConfParser::ParseString(const std::string & str)
|
||||
|
||||
ConfParser::Status ConfParser::ParseString(const wchar_t * str)
|
||||
{
|
||||
Clear();
|
||||
reading_from_file = false;
|
||||
reading_from_wchar_string = true;
|
||||
pchar_unicode = str;
|
||||
pchar_ascii = 0;
|
||||
|
||||
Parse();
|
||||
|
||||
@@ -167,15 +535,35 @@ ConfParser::Status ConfParser::ParseString(const std::wstring & str)
|
||||
|
||||
void ConfParser::Parse()
|
||||
{
|
||||
if( !root_space )
|
||||
{
|
||||
status = no_space;
|
||||
return;
|
||||
}
|
||||
|
||||
line = 1;
|
||||
status = ok;
|
||||
space = root_space;
|
||||
ReadChar();
|
||||
SkipWhiteLines();
|
||||
|
||||
ParseLoop();
|
||||
|
||||
if( status == ok && space != root_space )
|
||||
{
|
||||
// last closing a space characters ')' are missing
|
||||
status = syntax_error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::ParseLoop()
|
||||
{
|
||||
while( status == ok && lastc != -1 )
|
||||
{
|
||||
if( lastc == list_end )
|
||||
{
|
||||
TestListEnd();
|
||||
SpaceEnds();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -183,7 +571,7 @@ void ConfParser::Parse()
|
||||
|
||||
if( lastc == list_start )
|
||||
{
|
||||
TestListStart();
|
||||
SpaceStarts();
|
||||
}
|
||||
else
|
||||
if( lastc == separator && !variable.empty() )
|
||||
@@ -202,35 +590,30 @@ void ConfParser::Parse()
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::TestListEnd()
|
||||
void ConfParser::SpaceEnds()
|
||||
{
|
||||
if( using_global_space )
|
||||
if( space == root_space )
|
||||
{
|
||||
// there cannot be a loose list end character in the global space
|
||||
status = syntax_error;
|
||||
}
|
||||
else
|
||||
{
|
||||
using_global_space = true;
|
||||
space = space->parent;
|
||||
ReadChar();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::TestListStart()
|
||||
void ConfParser::SpaceStarts()
|
||||
{
|
||||
if( using_global_space )
|
||||
{
|
||||
spaces.insert(spaces.end(), Space());
|
||||
spaces.back().name = variable;
|
||||
using_global_space = false;
|
||||
ReadChar();
|
||||
}
|
||||
else
|
||||
{
|
||||
// only one additional level of spaces is allowed
|
||||
status = syntax_error;
|
||||
}
|
||||
Space * new_space = new Space();
|
||||
space->spaces.push_back(new_space);
|
||||
new_space->parent = space;
|
||||
new_space->name = variable;
|
||||
space = new_space;
|
||||
|
||||
ReadChar();
|
||||
}
|
||||
|
||||
|
||||
@@ -336,28 +719,6 @@ std::wstring::size_type i;
|
||||
}
|
||||
|
||||
|
||||
wchar_t ConfParser::ToSmall(wchar_t c)
|
||||
{
|
||||
if( c>='A' && c<='Z' )
|
||||
c = c - 'A' + 'a';
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
bool ConfParser::EqualNoCase(const wchar_t * str1, const wchar_t * str2)
|
||||
{
|
||||
while( *str1 && *str2 && ToSmall(*str1) == ToSmall(*str2) )
|
||||
{
|
||||
++str1;
|
||||
++str2;
|
||||
}
|
||||
|
||||
if( *str1 == 0 && *str2 == 0 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -370,19 +731,14 @@ void ConfParser::AddOption()
|
||||
return;
|
||||
}
|
||||
|
||||
Space * ps = &space;
|
||||
|
||||
if( !using_global_space && !spaces.empty() )
|
||||
ps = &spaces.back();
|
||||
|
||||
if( split_single && value.size() == 1 )
|
||||
{
|
||||
ps->table_single[variable] = value[0];
|
||||
space->table_single[variable] = value[0];
|
||||
DeleteFromTable(variable);
|
||||
}
|
||||
else
|
||||
{
|
||||
ps->table[variable] = value;
|
||||
space->table[variable] = value;
|
||||
DeleteFromTableSingle(variable);
|
||||
}
|
||||
}
|
||||
@@ -391,30 +747,20 @@ void ConfParser::AddOption()
|
||||
|
||||
void ConfParser::DeleteFromTable(const std::wstring & var)
|
||||
{
|
||||
Space * ps = &space;
|
||||
Space::Table::iterator i = space->table.find(var);
|
||||
|
||||
if( !using_global_space && !spaces.empty() )
|
||||
ps = &spaces.back();
|
||||
|
||||
Table::iterator i = ps->table.find(var);
|
||||
|
||||
if( i != ps->table.end() )
|
||||
ps->table.erase(i);
|
||||
if( i != space->table.end() )
|
||||
space->table.erase(i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConfParser::DeleteFromTableSingle(const std::wstring & var)
|
||||
{
|
||||
Space * ps = &space;
|
||||
Space::TableSingle::iterator i = space->table_single.find(var);
|
||||
|
||||
if( !using_global_space && !spaces.empty() )
|
||||
ps = &spaces.back();
|
||||
|
||||
TableSingle::iterator i = ps->table_single.find(var);
|
||||
|
||||
if( i != ps->table_single.end() )
|
||||
ps->table_single.erase(i);
|
||||
if( i != space->table_single.end() )
|
||||
space->table_single.erase(i);
|
||||
}
|
||||
|
||||
|
||||
@@ -533,7 +879,7 @@ bool ConfParser::ReadValueSimple(bool use_list_delimiter)
|
||||
if( use_list_delimiter )
|
||||
list_delimiter1 = list_delimiter;
|
||||
|
||||
if( use_list_delimiter || !using_global_space )
|
||||
if( use_list_delimiter || space != root_space )
|
||||
list_delimiter2 = list_end;
|
||||
|
||||
while( lastc!=-1 && lastc!='\n' && lastc!=commentary &&
|
||||
@@ -673,313 +1019,5 @@ int ConfParser::ReadChar()
|
||||
|
||||
|
||||
|
||||
bool ConfParser::Space::GetValue(const wchar_t * name, std::wstring & out)
|
||||
{
|
||||
tmp_name = name;
|
||||
return GetValue(tmp_name, out, L"");
|
||||
}
|
||||
|
||||
|
||||
bool ConfParser::Space::GetValue(const wchar_t * name, std::wstring & out, const wchar_t * def)
|
||||
{
|
||||
tmp_name = name;
|
||||
return GetValue(tmp_name, out, def);
|
||||
}
|
||||
|
||||
|
||||
bool ConfParser::Space::GetValue(const std::wstring & name, std::wstring & out)
|
||||
{
|
||||
return GetValue(name, out, L"");
|
||||
}
|
||||
|
||||
|
||||
bool ConfParser::Space::GetValue(const std::wstring & name, std::wstring & out, const wchar_t * def)
|
||||
{
|
||||
TableSingle::iterator i = table_single.find(name);
|
||||
|
||||
if( i != table_single.end() )
|
||||
{
|
||||
out = i->second;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Table::iterator t = table.find(name);
|
||||
|
||||
if( t == table.end() || t->second.empty() )
|
||||
{
|
||||
out = def;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
out = t->second[0];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ConfParser::ToText(const wchar_t * name, std::wstring & out)
|
||||
{
|
||||
tmp_name = name;
|
||||
return ToText(tmp_name, out, default_str.c_str());
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::ToText(const wchar_t * name, std::wstring & out, const wchar_t * def)
|
||||
{
|
||||
tmp_name = name;
|
||||
return ToText(tmp_name, out, def);
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::ToText(const std::wstring & name, std::wstring & out, const wchar_t * def)
|
||||
{
|
||||
space.GetValue(name, out, def);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
std::wstring & ConfParser::Text(const wchar_t * name)
|
||||
{
|
||||
ToText(name, tmp_value_text);
|
||||
return tmp_value_text;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::wstring & ConfParser::Text(const wchar_t * name, const wchar_t * def)
|
||||
{
|
||||
ToText(name, tmp_value_text, def);
|
||||
return tmp_value_text;
|
||||
}
|
||||
|
||||
|
||||
std::wstring & ConfParser::Text(const std::wstring & name, const wchar_t * def)
|
||||
{
|
||||
ToText(name, tmp_value_text, def);
|
||||
return tmp_value_text;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string & ConfParser::AText(const wchar_t * name)
|
||||
{
|
||||
ToText(name, tmp_value_text);
|
||||
Ezc::WideToUTF8(tmp_value_text, tmp_value_text_ascii);
|
||||
|
||||
return tmp_value_text_ascii;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string & ConfParser::AText(const wchar_t * name, const wchar_t * def)
|
||||
{
|
||||
ToText(name, tmp_value_text, def);
|
||||
Ezc::WideToUTF8(tmp_value_text, tmp_value_text_ascii);
|
||||
|
||||
return tmp_value_text_ascii;
|
||||
}
|
||||
|
||||
|
||||
std::string & ConfParser::AText(const std::wstring & name, const wchar_t * def)
|
||||
{
|
||||
ToText(name, tmp_value_text, def);
|
||||
Ezc::WideToUTF8(tmp_value_text, tmp_value_text_ascii);
|
||||
|
||||
return tmp_value_text_ascii;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int ConfParser::Int(const wchar_t * name)
|
||||
{
|
||||
tmp_name = name;
|
||||
return Int(tmp_name, default_int);
|
||||
}
|
||||
|
||||
|
||||
int ConfParser::Int(const wchar_t * name, int def)
|
||||
{
|
||||
tmp_name = name;
|
||||
return Int(tmp_name, def);
|
||||
}
|
||||
|
||||
|
||||
int ConfParser::ToInt(const std::wstring & value)
|
||||
{
|
||||
long res = (value[0] == '0')? wcstol(value.c_str() + 1, 0, 8) : wcstol(value.c_str(), 0, 10);
|
||||
|
||||
return static_cast<int>(res);
|
||||
}
|
||||
|
||||
|
||||
int ConfParser::Int(const std::wstring & name, int def)
|
||||
{
|
||||
if( space.GetValue(name, tmp_value_text) )
|
||||
return ToInt(tmp_value_text);
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
|
||||
size_t ConfParser::Size(const wchar_t * name)
|
||||
{
|
||||
tmp_name = name;
|
||||
return Size(tmp_name, default_size);
|
||||
}
|
||||
|
||||
|
||||
size_t ConfParser::Size(const wchar_t * name, size_t def)
|
||||
{
|
||||
tmp_name = name;
|
||||
return Size(tmp_name, def);
|
||||
}
|
||||
|
||||
|
||||
|
||||
size_t ConfParser::ToSize(const std::wstring & value)
|
||||
{
|
||||
unsigned long res = (value[0] == '0')? wcstoul(value.c_str() + 1, 0, 8) : wcstoul(value.c_str(), 0, 10);
|
||||
|
||||
return static_cast<size_t>(res);
|
||||
}
|
||||
|
||||
|
||||
size_t ConfParser::Size(const std::wstring & name, size_t def)
|
||||
{
|
||||
if( space.GetValue(name, tmp_value_text) )
|
||||
return ToSize(tmp_value_text);
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool ConfParser::Bool(const wchar_t * name)
|
||||
{
|
||||
tmp_name = name;
|
||||
return Bool(tmp_name, default_bool);
|
||||
}
|
||||
|
||||
|
||||
bool ConfParser::Bool(const wchar_t * name, bool def)
|
||||
{
|
||||
tmp_name = name;
|
||||
return Bool(tmp_name, def);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ConfParser::ToBool(const std::wstring & value)
|
||||
{
|
||||
return ( EqualNoCase(value.c_str(), L"true") ||
|
||||
EqualNoCase(value.c_str(), L"yes") ||
|
||||
EqualNoCase(value.c_str(), L"1")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
bool ConfParser::Bool(const std::wstring & name, bool def)
|
||||
{
|
||||
if( space.GetValue(name, tmp_value_text) )
|
||||
return ToBool(tmp_value_text);
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::SetDefaultText(const wchar_t * def)
|
||||
{
|
||||
default_str = def;
|
||||
}
|
||||
|
||||
void ConfParser::SetDefaultText(const std::wstring & def)
|
||||
{
|
||||
default_str = def;
|
||||
}
|
||||
|
||||
void ConfParser::SetDefaultInt(int def)
|
||||
{
|
||||
default_int = def;
|
||||
}
|
||||
|
||||
void ConfParser::SetDefaultSize(size_t def)
|
||||
{
|
||||
default_size = def;
|
||||
}
|
||||
|
||||
void ConfParser::SetDefaultBool(bool def)
|
||||
{
|
||||
default_bool = def;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// in lists we don't use default values
|
||||
void ConfParser::ListText(const wchar_t * name, std::vector<std::wstring> & list)
|
||||
{
|
||||
tmp_name = name;
|
||||
ListText(tmp_name, list);
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::ListText(const std::wstring & name, std::vector<std::wstring> & list)
|
||||
{
|
||||
list.clear();
|
||||
ConfParser::TableSingle::iterator i = space.table_single.find(name);
|
||||
|
||||
if( i != space.table_single.end() )
|
||||
{
|
||||
list.push_back(i->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConfParser::Table::iterator z = space.table.find(name);
|
||||
|
||||
if( z != space.table.end() )
|
||||
list = z->second;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void ConfParser::Print(std::ostream & out)
|
||||
{
|
||||
TableSingle::iterator i1;
|
||||
|
||||
for(i1 = space.table_single.begin() ; i1 != space.table_single.end() ; ++i1)
|
||||
{
|
||||
Ezc::WideToUTF8(i1->first, out);
|
||||
out << '=';
|
||||
Ezc::WideToUTF8(i1->second, out);
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
Table::iterator i2;
|
||||
Value::iterator i3;
|
||||
|
||||
for(i2 = space.table.begin() ; i2 != space.table.end() ; ++i2)
|
||||
{
|
||||
Ezc::WideToUTF8(i2->first, out);
|
||||
out << '=';
|
||||
|
||||
for(i3 = i2->second.begin() ; i3 != i2->second.end() ; ++i3)
|
||||
{
|
||||
Ezc::WideToUTF8(*i3, out);
|
||||
out << ',';
|
||||
}
|
||||
|
||||
out << std::endl;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user