configuration: better boolean parsing

This commit is contained in:
Matej Sekoranja
2012-10-12 12:14:41 +02:00
parent 5f08c6e37c
commit e264f5f51d
2 changed files with 18 additions and 7 deletions

View File

@@ -248,6 +248,7 @@ SystemConfigurationImpl::~SystemConfigurationImpl()
bool SystemConfigurationImpl::getPropertyAsBoolean(const string &name, const bool defaultValue)
{
/*
bool retval;
_ibuffer.clear();
_obuffer.clear();
@@ -259,6 +260,19 @@ bool SystemConfigurationImpl::getPropertyAsBoolean(const string &name, const boo
return defaultValue;
else
return retval;
*/
string value = getPropertyAsString(name, defaultValue ? "1" : "0");
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
bool isTrue = (value == "1") || (value == "true") || (value == "yes");
bool isFalse = (value == "0") || (value == "false") || (value == "no");
// invalid value
if (!(isTrue || isFalse))
return defaultValue;
else
return isTrue == true;
}
int32 SystemConfigurationImpl::getPropertyAsInteger(const string &name, const int32 defaultValue)

View File

@@ -54,11 +54,9 @@ void formatNTScalar(std::ostream& o, PVStructurePtr const & pvStruct)
std::ostream& formatScalarArray(std::ostream& o, PVScalarArrayPtr const & pvScalarArray)
{
size_t len = pvScalarArray->getLength();
if (len == 0)
o << "(empty)" << std::endl; // TODO is this OK?
else
for (size_t i = 0; i < len; i++)
(pvScalarArray.get())->dumpValue(o, i) << std::endl;
o << len << std::endl;
for (size_t i = 0; i < len; i++)
(pvScalarArray.get())->dumpValue(o, i) << std::endl;
return o;
}
@@ -399,8 +397,7 @@ class ChannelGetRequesterImpl : public ChannelGetRequester
std::cout << *(value.get()) << std::endl;
else if (valueType == scalarArray)
{
// TODO decide on formatting (with or without std::endl)
formatScalarArray(std::cout, dynamic_pointer_cast<PVScalarArray>(value)) << std::endl;
formatScalarArray(std::cout, dynamic_pointer_cast<PVScalarArray>(value));
}
else
{