diff options
author | Kevin Quick <kquick@galois.com> | 2020-09-24 22:42:59 -0700 |
---|---|---|
committer | Kevin Quick <kquick@galois.com> | 2020-09-24 22:42:59 -0700 |
commit | a439e9488df6c13d0e44dd4816df98487d69f4c6 (patch) | |
tree | bd88f92af674143ccee9082f36bb39f8799e0caf | |
parent | 83fec38fc93922192ada7c0409fec76578ef8dfb (diff) |
Support StringMap configuration settings.
Allows Configuration values that are space-separated key=value pairs.
-rw-r--r-- | src/libutil/config.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libutil/config.cc b/src/libutil/config.cc index 309d23b40..b14feb10d 100644 --- a/src/libutil/config.cc +++ b/src/libutil/config.cc @@ -268,6 +268,26 @@ template<> std::string BaseSetting<StringSet>::to_string() const return concatStringsSep(" ", value); } +template<> void BaseSetting<StringMap>::set(const std::string & str) +{ + auto kvpairs = tokenizeString<Strings>(str); + for (auto & s : kvpairs) + { + auto eq = s.find_first_of('='); + if (std::string::npos != eq) + value.emplace(std::string(s, 0, eq), std::string(s, eq + 1)); + // else ignored + } +} + +template<> std::string BaseSetting<StringMap>::to_string() const +{ + Strings kvstrs; + std::transform(value.begin(), value.end(), back_inserter(kvstrs), + [&](auto kvpair){ return kvpair.first + "=" + kvpair.second; }); + return concatStringsSep(" ", kvstrs); +} + template class BaseSetting<int>; template class BaseSetting<unsigned int>; template class BaseSetting<long>; @@ -278,6 +298,7 @@ template class BaseSetting<bool>; template class BaseSetting<std::string>; template class BaseSetting<Strings>; template class BaseSetting<StringSet>; +template class BaseSetting<StringMap>; void PathSetting::set(const std::string & str) { |