configuration: better boolean parsing
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user