![]() |
CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
|
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 | |
cbl::glob::ParameterFile::ParameterFile | ( | const std::string | parameter_file | ) |
Constructor.
parameter_file | std::string with path and name of the parameter file to read |
Definition at line 82 of file ParameterFile.cpp.
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.
key | std::string, parameter name |
default_value | parameter to return if the key is not found |
pos | position in the values vector |
Definition at line 215 of file ParameterFile.cpp.
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.
key | std::string, parameter name |
default_values | parameter to return if the key is not found |
Definition at line 236 of file ParameterFile.cpp.
|
private |
Remove white spaces treading and leading each std::string (private function)
inStr | std::string read in the parameter file (after '=') |
Definition at line 46 of file ParameterFile.cpp.
|
private |
Stores values contained in between curly brackets in a vector of std::string (private function)
inStr | std::string read in the parameter file (after '=', in between curly brackets '{', '}'); values inside brackets must be separated by comas ',' |
Definition at line 57 of file ParameterFile.cpp.
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
key | std::string, parameter name |
Definition at line 168 of file ParameterFile.cpp.
void cbl::glob::ParameterFile::read | ( | const std::string | parameter_file | ) |
member to read a parameter file
parameter_file | string with path and name of the parameter file to read |
Definition at line 91 of file ParameterFile.cpp.
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
key | std::string, parameter name |
values | the parameter values |
Definition at line 202 of file ParameterFile.cpp.
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
key | std::string, parameter name |
value | the parameter value |
pos | position in the values vector |
Definition at line 181 of file ParameterFile.cpp.
void cbl::glob::ParameterFile::write | ( | const std::string | parameter_file | ) |
member to write a parameter file
parameter_file | string with path and name of the parameter file to write |
Definition at line 138 of file ParameterFile.cpp.