part II of rewriting
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@635 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include "confparser.h"
|
||||
#include "misc.h"
|
||||
|
||||
@@ -27,6 +28,7 @@ ConfParser::ConfParser()
|
||||
|
||||
default_str = "";
|
||||
default_int = 0;
|
||||
default_size = 0;
|
||||
default_bool = false;
|
||||
}
|
||||
|
||||
@@ -454,6 +456,48 @@ return ToInt(i->second);
|
||||
}
|
||||
|
||||
|
||||
|
||||
size_t ConfParser::Size(const char * name)
|
||||
{
|
||||
return Size(std::string(name), default_size);
|
||||
}
|
||||
|
||||
|
||||
size_t ConfParser::Size(const char * name, size_t def)
|
||||
{
|
||||
return Size(std::string(name), def);
|
||||
}
|
||||
|
||||
|
||||
|
||||
size_t ConfParser::ToSize(const std::string & value)
|
||||
{
|
||||
long res = (value[0] == '0')? strtoul(value.c_str() + 1, 0, 8) : strtoul(value.c_str(), 0, 10);
|
||||
|
||||
return (size_t)res;
|
||||
}
|
||||
|
||||
|
||||
size_t ConfParser::Size(const std::string & name, size_t def)
|
||||
{
|
||||
TableSingle::iterator i = table_single.find(name);
|
||||
|
||||
if( i == table_single.end() )
|
||||
{
|
||||
Table::iterator t = table.find(name);
|
||||
|
||||
if( t == table.end() || t->second.empty() )
|
||||
return def;
|
||||
|
||||
return ToSize(t->second[0]);
|
||||
}
|
||||
|
||||
return ToSize(i->second);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool ConfParser::Bool(const char * name)
|
||||
{
|
||||
return Bool(std::string(name), default_bool);
|
||||
@@ -503,6 +547,11 @@ 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;
|
||||
|
Reference in New Issue
Block a user