From e264f5f51d8a2ae0c6227c479a1f7435cc1a1c5d Mon Sep 17 00:00:00 2001 From: Matej Sekoranja Date: Fri, 12 Oct 2012 12:14:41 +0200 Subject: [PATCH] configuration: better boolean parsing --- pvAccessApp/utils/configuration.cpp | 14 ++++++++++++++ testApp/remote/eget.cpp | 11 ++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/pvAccessApp/utils/configuration.cpp b/pvAccessApp/utils/configuration.cpp index e182dd9..7f17d03 100644 --- a/pvAccessApp/utils/configuration.cpp +++ b/pvAccessApp/utils/configuration.cpp @@ -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) diff --git a/testApp/remote/eget.cpp b/testApp/remote/eget.cpp index 77e2a88..476ae5c 100644 --- a/testApp/remote/eget.cpp +++ b/testApp/remote/eget.cpp @@ -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(value)) << std::endl; + formatScalarArray(std::cout, dynamic_pointer_cast(value)); } else {