Skip to content
Snippets Groups Projects
Commit ffd9feb3 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[BL] Add ConfigTree::getConfParam* for vector<T>.

parent 513d6c82
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "ConfigTree.h" #include "ConfigTree.h"
#include <sstream>
namespace BaseLib namespace BaseLib
{ {
...@@ -50,15 +52,37 @@ getConfParam(std::string const& param, T const& default_value) const ...@@ -50,15 +52,37 @@ getConfParam(std::string const& param, T const& default_value) const
return default_value; return default_value;
} }
template<typename T> template <typename T>
boost::optional<T> boost::optional<T> ConfigTree::getConfParamOptional(
ConfigTree:: std::string const& param) const
getConfParamOptional(std::string const& param) const
{ {
checkUnique(param); checkUnique(param);
return getConfParamOptionalImpl(param, static_cast<T*>(nullptr));
}
template <typename T>
boost::optional<T> ConfigTree::getConfParamOptionalImpl(
std::string const& param, T*) const
{
if (auto p = getConfSubtreeOptional(param)) return p->getValue<T>();
return boost::none;
}
template <typename T>
boost::optional<std::vector<T>> ConfigTree::getConfParamOptionalImpl(
std::string const& param, std::vector<T>*) const
{
if (auto p = getConfSubtreeOptional(param)) if (auto p = getConfSubtreeOptional(param))
return p->getValue<T>(); {
std::istringstream sstr{p->getValue<std::string>()};
std::vector<T> result;
T value;
while (sstr >> value)
result.push_back(value);
return boost::make_optional(result);
}
return boost::none; return boost::none;
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <vector>
#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ptree.hpp>
...@@ -497,6 +498,15 @@ public: ...@@ -497,6 +498,15 @@ public:
static void onwarning(std::string const& filename, std::string const& path, static void onwarning(std::string const& filename, std::string const& path,
std::string const& message); std::string const& message);
private:
//! Default implementation of reading a value of type T.
template<typename T> boost::optional<T>
getConfParamOptionalImpl(std::string const& param, T*) const;
//! Implementation of reading a vector of values of type T.
template<typename T> boost::optional<std::vector<T>>
getConfParamOptionalImpl(std::string const& param, std::vector<T>*) const;
private: private:
struct CountType struct CountType
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment