CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
cbl::glob::ReadParameters Class Reference

The class ReadParameters. More...

#include <ReadParameters.h>

Public Member Functions

Constructors/destructors
 ReadParameters ()=default
 Default empty constructor.
 
 ReadParameters (const std::string parameter_file)
 Constructor. More...
 
 ~ReadParameters ()=default
 Default destructor.
 
Member functions used to get private/protected parameters
template<class T >
find (const std::string key) const
 Template method to get parameter value. More...
 
template<class T >
find (const std::string key, const T default_value) const
 Template method to get parameter value with default value. More...
 
template<class T >
std::vector< T > find_vector (const std::string key) const
 Template method to get a vector parameter. More...
 
template<class T >
std::vector< T > find_vector (const std::string key, const std::vector< T > default_value) const
 Template method to get a vector parameter with default value. More...
 

Private Member Functions

std::string m_trim (const std::string inStr)
 Remove white spaces treading and leading each std::string (private function) More...
 
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) More...
 

Private Attributes

std::unordered_map< std::string, std::string > m_parameters
 map with all the parameter name/value couples
 
std::unordered_map< std::string, std::vector< std::string > > m_vectors
 map with all the vector type parameter name/value couples
 

Detailed Description

The class ReadParameters.

"Headers/ReadParameters.h"

Examples
readParameterFile.cpp.

Definition at line 54 of file ReadParameters.h.

Constructor & Destructor Documentation

◆ ReadParameters()

cbl::glob::ReadParameters::ReadParameters ( const std::string  parameter_file)

Constructor.

Parameters
parameter_filestd::string with path and name of the parameter file to read

Definition at line 46 of file ReadParameters.cpp.

Member Function Documentation

◆ find() [1/2]

template<class T >
T cbl::glob::ReadParameters::find ( const std::string  key) const

Template method to get parameter value.

template method to get the parameter value in the requested T type

Parameters
keystd::string, parameter name
Returns
value of the requested parameter of type T, error message if parameter not found
Examples
readParameterFile.cpp.

Definition at line 172 of file ReadParameters.h.

◆ find() [2/2]

template<class T >
T cbl::glob::ReadParameters::find ( const std::string  key,
const T  default_value 
) const

Template method to get parameter value with default value.

template method to get the parameter value in the requested T type with default

Parameters
keystd::string, parameter name
default_valuetypeT parameter default value to be returned if parameter not found
Returns
value associated to key, or default_value if parameter not found

Definition at line 187 of file ReadParameters.h.

◆ find_vector() [1/2]

template<class T >
std::vector< T > cbl::glob::ReadParameters::find_vector ( const std::string  key) const

Template method to get a vector parameter.

template method to get the parameter value in the requested T type

Parameters
keystd::string, vector parameter name
Returns
std::vector<type T> of values of the requested parameter, error message if parameter not found

Definition at line 205 of file ReadParameters.h.

◆ find_vector() [2/2]

template<class T >
std::vector< T > cbl::glob::ReadParameters::find_vector ( const std::string  key,
const std::vector< T >  default_value 
) const

Template method to get a vector parameter with default value.

template method to get the parameter value in the requested T type with default

Parameters
keystd::string, parameter name
default_valuestd::vector<typeT> parameter default value to be returned if parameter not found
Returns
vector of values associated to key, or default_value if parameter not found

Definition at line 224 of file ReadParameters.h.

◆ m_trim()

std::string cbl::glob::ReadParameters::m_trim ( const std::string  inStr)
private

Remove white spaces treading and leading each std::string (private function)

Parameters
inStrstd::string read in the parameter file (after '=')
Returns
input std::string with treading and leading white spaces removed

Definition at line 85 of file ReadParameters.cpp.

◆ m_trim_vect()

vector< string > cbl::glob::ReadParameters::m_trim_vect ( const std::string  inStr)
private

Stores values contained in between curly brackets in a vector of std::string (private function)

Parameters
inStrstd::string read in the parameter file (after '=', in between curly brackets '{', '}'); values inside brackets must be separated by comas ','
Returns
a vector of std::string values

Definition at line 93 of file ReadParameters.cpp.


The documentation for this class was generated from the following files: