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);
83 virtual bool has_key(
const std::string& key)
const {
91 throw MetadataError(
"Metadata for key: " + key +
" not found.");
102 virtual const std::string&
get_entry(
const std::string& key)
const {
108 virtual const std::string&
get_entry(
const std::string& key,
const std::string& fallback)
const {
121 template <
typename T>
129 template <
typename T>
132 return get_entry_as<T>(key);
140 template <
typename T>
167 if (s ==
"true" || s ==
"on" || s ==
"yes")
return true;
168 if (s ==
"false" || s ==
"off" || s ==
"no")
return false;
170 throw MetadataError(
"'" + s +
"' is not a valid string for conversion to bool type");
175 static const string delim =
",";
178 if (
startswith(strval,
"[")) strval = strval.substr(1, strval.size()-1);
179 if (
endswith(strval,
"]")) strval = strval.substr(0, strval.size()-1);
181 return split(strval, delim);
186 const vector<string> strs = get_entry_as< vector<string> >(key);
188 rtn.reserve(strs.size());
189 for (
const string& s : strs) rtn.push_back( lexical_cast<int>(s) );
190 assert(rtn.size() == strs.size());
196 const vector<string> strs = get_entry_as< vector<string> >(key);
198 rtn.reserve(strs.size());
199 for (
const string& s : strs) rtn.push_back( lexical_cast<double>(s) );
200 assert(rtn.size() == strs.size());
bool endswith(const std::string &s, const std::string &sub)
Does a string s end with the sub substring?
Definition: Utils.h:120
virtual ~Info()
Virtual destructor to allow inheritance.
Definition: Info.h:41
void set_entry(const std::string &key, const T &val)
Set a keyed value entry.
Definition: Info.h:141
T get_entry_as(const std::string &key, const T &fallback) const
Retrieve a metadata entry by key name, with an inline type cast and default fallback.
Definition: Info.h:130
Info(const std::string &path)
Constructor.
Definition: Info.h:36
virtual const std::string & get_entry(const std::string &key) const
Definition: Info.h:102
const std::string & get_entry_local(const std::string &key) const
Retrieve a metadata string by key name, as defined on this specific object.
Definition: Info.h:89
Info()
Default constructor.
Definition: Info.h:33
virtual const std::string & get_entry(const std::string &key, const std::string &fallback) const
Retrieve a metadata string by key name, with a default fallback.
Definition: Info.h:108
std::map< std::string, std::string > _metadict
The string -> string native metadata storage container.
Definition: Info.h:151
std::string trim(const std::string &s)
Strip leading and trailing spaces (not in-place)
Definition: Utils.h:130
void load(const std::string &filepath)
T get_entry_as(const std::string &key) const
Definition: Info.h:122
bool startswith(const std::string &s, const std::string &sub)
Does a string s start with the sub substring?
Definition: Utils.h:115
virtual bool has_key(const std::string &key) const
Definition: Info.h:83
std::string to_str(const T &val)
Make a string representation of val.
Definition: Utils.h:61
T lexical_cast(const U &in)
Convert between types via stringstream.
Definition: Utils.h:47
std::vector< std::string > split(const std::string &s, const std::string &sep)
Split a string by a given separator.
Definition: Utils.h:95
Metadata base class for PDFs, PDF sets, or global configuration.
Definition: Info.h:29
bool has_key_local(const std::string &key) const
Is a value defined for the given key on this specific object?
Definition: Info.h:71