10 #include "LHAPDF/Utils.h"
11 #include "LHAPDF/Paths.h"
12 #include "LHAPDF/Exceptions.h"
36 Info(
const std::string& path) {
51 void load(
const std::string& filepath);
71 std::vector<std::string> rtn;
72 rtn.reserve(_metadict.size());
73 for (
const auto& kv : _metadict) rtn.push_back(kv.first);
88 return _metadict.find(key) != _metadict.end();
100 virtual bool has_key(
const std::string& key)
const {
101 return has_key_local(key);
107 if (has_key_local(key))
return _metadict.find(key)->second;
108 throw MetadataError(
"Metadata for key: " + key +
" not found.");
120 return get_entry_local(key);
127 return get_entry(key);
138 template <
typename T>
140 const string& s = get_entry(key);
141 return lexical_cast<T>(s);
146 template <
typename T>
149 return get_entry_as<T>(key);
157 template <
typename T>
159 _metadict[key] = to_str(val);
178 inline bool Info::get_entry_as(
const std::string& key)
const {
179 const string& s = get_entry(key);
181 bool rtn = lexical_cast<
bool>(s);
184 if (s ==
"true" || s ==
"on" || s ==
"yes")
return true;
185 if (s ==
"false" || s ==
"off" || s ==
"no")
return false;
187 throw MetadataError(
"'" + s +
"' is not a valid string for conversion to bool type");
191 inline std::vector<std::string>
Info::get_entry_as(
const std::string& key)
const {
192 static const string delim =
",";
193 string strval = trim(get_entry(key));
195 if (startswith(strval,
"[")) strval = strval.substr(1, strval.size()-1);
196 if (endswith(strval,
"]")) strval = strval.substr(0, strval.size()-1);
198 return split(strval, delim);
202 inline std::vector<
int>
Info::get_entry_as(
const std::string& key)
const {
203 const vector<string> strs = get_entry_as< vector<string> >(key);
205 rtn.reserve(strs.size());
206 for (
const string& s : strs) rtn.push_back( lexical_cast<
int>(s) );
207 assert(rtn.size() == strs.size());
212 inline std::vector<
double>
Info::get_entry_as(
const std::string& key)
const {
213 const vector<string> strs = get_entry_as< vector<string> >(key);
215 rtn.reserve(strs.size());
216 for (
const string& s : strs) rtn.push_back( lexical_cast<
double>(s) );
217 assert(rtn.size() == strs.size());