99 template <
class T> T
find (
const std::string key)
const;
111 template <
class T> T
find (
const std::string key,
const T default_value)
const;
122 template <
class T> std::vector< T >
find_vector (
const std::string key)
const;
134 template <
class T> std::vector< T >
find_vector (
const std::string key,
const std::vector<T> default_value)
const;
145 std::unordered_map<std::string, std::vector<std::string>>
m_vectors;
155 std::string
m_trim (
const std::string inStr);
166 std::vector<std::string>
m_trim_vect (
const std::string inStr);
178 tmpVal >> std::boolalpha >> value ;
181 ErrorCBL(
"[ReadParameters] Parameter "+key+
" not found",
"find",
"ReadParameters.h");
193 tmpVal >> std::boolalpha >> value;
196 coutCBL <<
"Parameter " << key <<
" not found --> using default: " << default_value << std::endl;
197 value = default_value;
207 std::vector< T > vect;
210 for (
size_t ii=0; ii<
m_vectors.at(key).size(); ii++) {
212 std::stringstream tmpVal(
m_vectors.at(key)[ii]);
213 tmpVal >> std::boolalpha >> value ;
214 vect.push_back(value);
218 ErrorCBL(
"[ReadParameters] Parameter "+key+
" not found",
"find_vector",
"ReadParameters.h");
226 std::vector< T > vect;
229 std::vector< T > vect;
230 for (
size_t ii=0; ii<
m_vectors.at(key).size(); ii++) {
232 std::stringstream tmpVal(
m_vectors.at(key)[ii]);
233 tmpVal >> std::boolalpha >> value ;
234 vect.push_back(value);
238 coutCBL <<
"Parameter " << key <<
" not found --> using default vector." << std::endl;
Useful generic functions.
#define coutCBL
CBL print message.
The class ReadParameters.
std::string m_trim(const std::string inStr)
Remove white spaces treading and leading each std::string (private function)
ReadParameters()=default
Default empty constructor.
std::unordered_map< std::string, std::string > m_parameters
map with all the parameter name/value couples
~ReadParameters()=default
Default destructor.
std::unordered_map< std::string, std::vector< std::string > > m_vectors
map with all the vector type parameter name/value couples
T find(const std::string key) const
Template method to get parameter value.
std::vector< std::string > m_trim_vect(const std::string inStr)
Stores values contained in between curly brackets in a vector of std::string (private function)
std::vector< T > find_vector(const std::string key) const
Template method to get a vector parameter.
The global namespace of the CosmoBolognaLib
int ErrorCBL(const std::string msg, const std::string functionCBL, const std::string fileCBL, const cbl::glob::ExitCode exitCode=cbl::glob::ExitCode::_error_)
throw an exception: it is used for handling exceptions inside the CosmoBolognaLib