added: to Space:

long Long(const wchar_t * name)
       for getting a long variable,
added: to Space:
       void Add(const wchar_t * name, long value)
       void Add(const wchar_t * name, const wchar_t * value)
       for inserting a variable,
added: to Space:
       Space & AddSpace(const wchar_t * name);
       for inserting a new space
added: to Space:
       Space * FindSpace(const wchar_t * name);
       to find a specified space
added: to Space:
       Space & FindAddSpace(const wchar_t * name);
       to find a specified space and if not exists
       automatically add a new one



git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@379 e52654a7-88a9-db11-a3e9-0013d4bc506e
master
Tomasz Sowa 11 years ago
parent d0ffdd336c
commit 04ca4692b3

@ -238,6 +238,40 @@ return def;
long Space::Long(const wchar_t * name)
{
tmp_name = name;
return Long(tmp_name, 0);
}
long Space::Long(const wchar_t * name, long def)
{
tmp_name = name;
return Long(tmp_name, def);
}
long Space::ToLong(const std::wstring & value)
{
return (value[0] == '0')? wcstol(value.c_str() + 1, 0, 8) : wcstol(value.c_str(), 0, 10);
}
long Space::Long(const std::wstring & name, long def)
{
std::wstring * value = GetValue(name);
if( value )
return ToLong(*value);
return def;
}
size_t Space::Size(const wchar_t * name)
{
tmp_name = name;
@ -309,6 +343,109 @@ return def;
}
void Space::Add(const wchar_t * name, long value)
{
wchar_t value_str[50];
swprintf(value_str, sizeof(value_str)/sizeof(wchar_t), L"%ld", value);
Add(name, value_str);
}
void Space::Add(const std::wstring & name, long value)
{
wchar_t value_str[50];
swprintf(value_str, sizeof(value_str)/sizeof(wchar_t), L"%ld", value);
Add(name.c_str(), value_str);
}
void Space::Add(const wchar_t * name, const wchar_t * value)
{
tmp_name = name;
table_single[tmp_name] = value;
}
void Space::Add(const wchar_t * name, const std::wstring & value)
{
tmp_name = name;
table_single[tmp_name] = value;
}
void Space::Add(const std::wstring & name, const std::wstring & value)
{
table_single[name] = value;
}
Space & Space::AddSpace(const wchar_t * name)
{
spaces.push_back(new Space());
spaces.back()->name = name;
spaces.back()->parent = this;
return *spaces.back();
}
Space & Space::AddSpace(const std::wstring & name)
{
spaces.push_back(new Space());
spaces.back()->name = name;
spaces.back()->parent = this;
return *spaces.back();
}
Space * Space::FindSpace(const wchar_t * name)
{
for(size_t i=0 ; i<spaces.size() ; ++i)
{
if( spaces[i]->name == name )
return spaces[i];
}
return 0;
}
Space * Space::FindSpace(const std::wstring & name)
{
for(size_t i=0 ; i<spaces.size() ; ++i)
{
if( spaces[i]->name == name )
return spaces[i];
}
return 0;
}
Space & Space::FindAddSpace(const wchar_t * name)
{
Space * space = FindSpace(name);
if( space )
return *space;
return AddSpace(name);
}
Space & Space::FindAddSpace(const std::wstring & name)
{
Space * space = FindSpace(name);
if( space )
return *space;
return AddSpace(name);
}
// in lists we don't use default values

@ -199,17 +199,38 @@ public:
std::string & AText(const wchar_t * name);
std::string & AText(const wchar_t * name, const char * def);
std::string & AText(const std::wstring & name, const char * def);
int Int(const wchar_t *);
int Int(const wchar_t * name, int def);
int Int(const std::wstring & name, int def);
size_t Size(const wchar_t *);
int Int(const wchar_t * name);
int Int(const wchar_t * name, int def);
int Int(const std::wstring & name, int def);
long Long(const wchar_t * name);
long Long(const wchar_t * name, long def);
long Long(const std::wstring & name, long def);
size_t Size(const wchar_t * name);
size_t Size(const wchar_t * name, size_t def);
size_t Size(const std::wstring & name, size_t def);
bool Bool(const wchar_t *);
bool Bool(const wchar_t * name, bool def);
bool Bool(const std::wstring & name, bool def);
void Add(const wchar_t * name, long value);
void Add(const std::wstring & name, long value);
void Add(const wchar_t * name, const wchar_t * value);
void Add(const wchar_t * name, const std::wstring & value);
void Add(const std::wstring & name, const std::wstring & value);
Space & AddSpace(const wchar_t * name);
Space & AddSpace(const std::wstring & name);
// looking for the first space with the specified name
// if there is not such a space those methods return a null pointer
Space * FindSpace(const wchar_t * name);
Space * FindSpace(const std::wstring & name);
// looking for the first space with the specified name
// if there is not such a space then this methods adds such a space
Space & FindAddSpace(const wchar_t * name);
Space & FindAddSpace(const std::wstring & name);
/*
*
@ -273,6 +294,7 @@ private:
std::string tmp_value_text_ascii;
int ToInt(const std::wstring & value);
long ToLong(const std::wstring & value);
size_t ToSize(const std::wstring & value);
bool ToBool(const std::wstring & value);
wchar_t ToSmall(wchar_t c);

Loading…
Cancel
Save