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

The class ParameterFile. More...

#include <ParameterFile.h>

Public Member Functions

Constructors/destructors
 ParameterFile ()=default
 Default empty constructor.
 
 ParameterFile (const std::string parameter_file)
 Constructor. More...
 
 ~ParameterFile ()=default
 Default destructor.
 
Member functions used to get private/protected parameters
void read (const std::string parameter_file)
 member to read a parameter file More...
 
void write (const std::string parameter_file)
 member to write a parameter file More...
 
std::vector< std::string > & operator[] (const std::string key)
 Method to set/get entries of the parameter file. More...
 
void set_key (const std::string key, std::string value, const size_t pos=0)
 Method to set entries of the parameter file. More...
 
void set_key (const std::string key, const std::vector< std::string > values)
 Method to set entries of the parameter file. More...
 
std::string get_key (const std::string key, const std::string default_value, const size_t pos=0) const
 Method to get one value for a specific parameter. More...
 
std::vector< std::string > get_key (const std::string key, const std::vector< std::string > default_values) const
 Method to get entries of the parameter file. 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

parameter_map m_parameters
 map with all the vector type parameter name/value couples
 
std::vector< std::string > m_keys
 list of keys in order of insertion
 

Detailed Description

The class ParameterFile.

"Headers/ParameterFile.h"

Definition at line 57 of file ParameterFile.h.

Constructor & Destructor Documentation

◆ ParameterFile()

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

Constructor.

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

Definition at line 82 of file ParameterFile.cpp.

Member Function Documentation

◆ get_key() [1/2]

std::string cbl::glob::ParameterFile::get_key ( const std::string  key,
const std::string  default_value,
const size_t  pos = 0 
) const

Method to get one value for a specific parameter.

Parameters
keystd::string, parameter name
default_valueparameter to return if the key is not found
posposition in the values vector
Returns
value of the requested parameter of type T, if the key is not found returns the default values

Definition at line 215 of file ParameterFile.cpp.

◆ get_key() [2/2]

std::vector< std::string > cbl::glob::ParameterFile::get_key ( const std::string  key,
const std::vector< std::string >  default_values 
) const

Method to get entries of the parameter file.

Parameters
keystd::string, parameter name
default_valuesparameter to return if the key is not found
Returns
value of the requested parameter of type T, if the key is not found returns the default values

Definition at line 236 of file ParameterFile.cpp.

◆ m_trim()

std::string cbl::glob::ParameterFile::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 46 of file ParameterFile.cpp.

◆ m_trim_vect()

vector< string > cbl::glob::ParameterFile::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 57 of file ParameterFile.cpp.

◆ operator[]()

std::vector< std::string > & cbl::glob::ParameterFile::operator[] ( const std::string  key)

Method to set/get entries of the parameter file.

This method return a reference to the parameter values. It can be modified by the user at wish. Use with caution

Parameters
keystd::string, parameter name
Returns
reference to the values of the requested parameter of type T, if the key is not found is automatically created.

Definition at line 168 of file ParameterFile.cpp.

◆ read()

void cbl::glob::ParameterFile::read ( const std::string  parameter_file)

member to read a parameter file

Parameters
parameter_filestring with path and name of the parameter file to read

Definition at line 91 of file ParameterFile.cpp.

◆ set_key() [1/2]

void cbl::glob::ParameterFile::set_key ( const std::string  key,
const std::vector< std::string >  values 
)

Method to set entries of the parameter file.

Override values for a parameter. This method throws an error if the keys has not been found

Parameters
keystd::string, parameter name
valuesthe parameter values

Definition at line 202 of file ParameterFile.cpp.

◆ set_key() [2/2]

void cbl::glob::ParameterFile::set_key ( const std::string  key,
std::string  value,
const size_t  pos = 0 
)

Method to set entries of the parameter file.

Modify a parameter value. This method throws an error if the keys has not been found It also throws an error if pos is larger than m_parameters[key].size()+1

Parameters
keystd::string, parameter name
valuethe parameter value
posposition in the values vector

Definition at line 181 of file ParameterFile.cpp.

◆ write()

void cbl::glob::ParameterFile::write ( const std::string  parameter_file)

member to write a parameter file

Parameters
parameter_filestring with path and name of the parameter file to write

Definition at line 138 of file ParameterFile.cpp.


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