1 #ifndef WIRECELL_CONFIGURATION 2 #define WIRECELL_CONFIGURATION 5 #include <boost/algorithm/string/split.hpp> 6 #include <boost/algorithm/string/classification.hpp> 69 if (cfg.isNull())
return def;
75 if (cfg.isNull())
return def;
81 if (cfg.isNull())
return def;
82 return cfg.asDouble();
87 if (cfg.isNull())
return def;
88 return cfg.asDouble();
93 if (cfg.isNull())
return def;
94 return cfg.asString();
98 std::vector<std::string> convert< std::vector<std::string> >(
const Configuration&
cfg,
const std::vector<std::string>& def) {
99 std::vector<std::string> ret;
101 ret.push_back(convert<std::string>(v));
107 std::vector<int> convert< std::vector<int> >(
const Configuration&
cfg,
const std::vector<int>& def) {
108 std::vector<int> ret;
116 std::vector<double> convert< std::vector<double> >(
const Configuration&
cfg,
const std::vector<double>& def) {
117 std::vector<double> ret;
130 Configuration
update(Configuration&
a, Configuration&
b);
134 Configuration
append(Configuration& a, Configuration& b);
139 for (
auto ent : lst) {
140 auto maybe =
branch(ent, dotpath);
141 if (maybe.isNull()) {
continue; }
142 if (convert<T>(maybe) ==
val) {
return maybe; }
156 Configuration*
ptr = &
cfg;
157 std::vector<std::string> path;
159 for (
auto name : path) {
Configuration update(Configuration &a, Configuration &b)
Merge dictionary b into a, return a.
T convert(const Configuration &cfg, const T &def=T())
Convert a configuration value to a particular type.
void put(Configuration &cfg, const std::string &dotpath, const T &val)
Put value in configuration at the dotted path.
Configuration branch(Configuration cfg, const std::string &dotpath)
Follow a dot.separated.path and return the branch there.
Configuration find(Configuration &lst, const std::string &dotpath, const T &val)
Return dictionary in given list if it value at dotpath matches.
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
float convert< float >(const Configuration &cfg, const float &def)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
bool convert< bool >(const Configuration &cfg, const bool &def)
Configuration append(Configuration &a, Configuration &b)
Return an array which is composed of the array b appended to the array a.
Json::Value Configuration
int convert< int >(const Configuration &cfg, const int &def)
void split(std::string const &s, char c, OutIter dest)
double convert< double >(const Configuration &cfg, const double &def)