From 54afb47d8a5cdeda4e0ff00bd68047d7e0a24267 Mon Sep 17 00:00:00 2001 From: Jakob Jordan <j.jordan@fz-juelich.de> Date: Tue, 24 Oct 2017 22:36:39 +0200 Subject: [PATCH] Add function to load boolean values from config --- src/configuration.cc | 18 ++++++++++++++++++ src/music/configuration.hh | 2 ++ src/music/setup.hh | 2 ++ src/setup.cc | 7 +++++++ 4 files changed, 29 insertions(+) diff --git a/src/configuration.cc b/src/configuration.cc index 74654b7..592e644 100644 --- a/src/configuration.cc +++ b/src/configuration.cc @@ -230,6 +230,24 @@ namespace MUSIC { return true; // Doesn't happen! Just for compiler! } + bool + Configuration::lookup (std::string name, bool* result) + { + std::map<std::string, std::string>::iterator pos = dict_.find (name); + if (pos == dict_.end ()) + return defaultConfig_ && defaultConfig_->lookup (name, result); + + std::istringstream iss(pos->second); + if (! (iss >> std::boolalpha >> *result).fail ()) + return true; + + std::ostringstream oss; + oss << "var " << name << " given wrong type (" << pos->second + << "; expected bool) in config file"; + error(oss.str ()); + return true; // Doesn't happen! Just for compiler! + } + std::string Configuration::Name () { diff --git a/src/music/configuration.hh b/src/music/configuration.hh index 4d3ff00..841f279 100644 --- a/src/music/configuration.hh +++ b/src/music/configuration.hh @@ -64,6 +64,8 @@ namespace MUSIC { bool lookup(std::string name, std::string* result); + bool lookup (std::string name, bool* result); + void insert (std::string name, std::string value); const ConfigDict &getDict(); diff --git a/src/music/setup.hh b/src/music/setup.hh index 8fb1717..6b58b3e 100644 --- a/src/music/setup.hh +++ b/src/music/setup.hh @@ -67,6 +67,8 @@ namespace MUSIC { bool config (string var, double* result); + bool config (string var, bool* result); + ContInputPort* publishContInput (string identifier); ContOutputPort* publishContOutput (string identifier); diff --git a/src/setup.cc b/src/setup.cc index b0c964f..5f2895a 100644 --- a/src/setup.cc +++ b/src/setup.cc @@ -398,6 +398,13 @@ namespace MUSIC { return config_->lookup (var, result); } + + bool + Setup::config (string var, bool* result) + { + return config_->lookup (var, result); + } + ContInputPort* Setup::publishContInput (std::string identifier) -- GitLab