This is the class serves as a holder for a set of parameters. More...
#include <BCP_parameters.hpp>
Public Types | |
typedef Par::chr_params | chr_params |
typedef Par::int_params | int_params |
typedef Par::dbl_params | dbl_params |
typedef Par::str_params | str_params |
typedef Par::str_array_params | str_array_params |
Public Member Functions | |
Query methods | |
The members of the parameter set can be queried for using the overloaded entry() method. Using the example in the class documentation the user can get a parameter with the "<code>param.entry(USER_par::parameter_name)</code>" expression. | |
char | entry (const chr_params key) const |
int | entry (const int_params key) const |
double | entry (const dbl_params key) const |
const BCP_string & | entry (const str_params key) const |
const BCP_vec< BCP_string > & | entry (const str_array_params key) const |
Set methods | |
First, there is the assignment operator that sets the whole parameter set at once. Individual members of the parameter set can be set for using the overloaded set_entry() method. Using the example in the class documentation the user can set a parameter with the "<code>param.set_entry(USER_par::parameter_name, param_value)</code>" expression. | |
BCP_parameter_set< Par > & | operator= (const BCP_parameter_set< Par > &x) |
void | set_entry (const chr_params key, const char val) |
void | set_entry (const chr_params key, const bool val) |
void | set_entry (const int_params key, const int val) |
void | set_entry (const dbl_params key, const double val) |
void | set_entry (const str_params key, const char *val) |
void | set_entry (const str_array_params key, const char *val) |
void | set_entry (const BCP_parameter key, const char *val) |
Read parameters from a stream. | |
void | read_from_stream (std::istream &parstream) |
Read the parameters from the stream specified in the argument. | |
Expand parameter value (look for environment vars). | |
std::string | expand (const char *value) |
Read parameters from a file. | |
void | read_from_file (const char *paramfile) |
Simply invoke reading from a stream. | |
Read parameters from the command line | |
void | read_from_arglist (const int argnum, const char *const *arglist) |
Simply invoke reading from a stream. | |
Write parameters to a stream. | |
void | write_to_stream (std::ostream &outstream) const |
Write keyword-value pairs to the stream specified in the argument. | |
Packing/unpacking methods | |
void | pack (BCP_buffer &buf) |
Pack the parameter set into the buffer. | |
void | unpack (BCP_buffer &buf) |
Unpack the parameter set from the buffer. | |
Constructors and destructor. | |
BCP_parameter_set () | |
The default constructor creates a parameter set with from the template argument structure. | |
~BCP_parameter_set () | |
The destructor deletes all data members. | |
Private Member Functions | |
Private methods that must be defined for each parameter set. | |
void | create_keyword_list () |
Method for creating the list of keyword looked for in the parameter file. | |
void | set_default_entries () |
Method for setting the default values for the parameters. | |
Private Attributes | |
Data members. All of them are private. | |
BCP_vec< std::pair< BCP_string, BCP_parameter > > | keys |
The keyword, parameter pairs. | |
BCP_vec< BCP_string > | obsolete_keys |
list of obsolete keywords. | |
char * | cpar |
The character parameters. | |
int * | ipar |
The integer parameters. | |
double * | dpar |
The double parameters. | |
BCP_string * | spar |
The string (actually, BCP_string) parameters. | |
BCP_vec< BCP_string > * | sapar |
The string array parameters. |
This is the class serves as a holder for a set of parameters.
For example, BCP stores has a parameter set for each process. Of course, the user can use this class for her own parameters. To use this class the user must
struct
with the names of the parameters (see, e.g., BCP_tm_par. Assume that the structure is named USER_par
. BCP_parameter_set<USER_par>::create_keyword_list()
and BCP_parameter_set<USER_par>::set_default_entries()
. For an example look at the file BCP-common/TM/BCP_tm_param.cpp
. Essentially, the first method defines what keywords should be looked for in the parameter file, and if one is found which parameter should take the corresponding value; the other method specifies the default values for each parameter. After this the user can read in the parameters from a file, she can set/access the parameters in the parameter, etc.
Definition at line 113 of file BCP_parameters.hpp.
typedef Par::chr_params BCP_parameter_set< Par >::chr_params |
Definition at line 129 of file BCP_parameters.hpp.
typedef Par::int_params BCP_parameter_set< Par >::int_params |
Definition at line 130 of file BCP_parameters.hpp.
typedef Par::dbl_params BCP_parameter_set< Par >::dbl_params |
Definition at line 131 of file BCP_parameters.hpp.
typedef Par::str_params BCP_parameter_set< Par >::str_params |
Definition at line 132 of file BCP_parameters.hpp.
typedef Par::str_array_params BCP_parameter_set< Par >::str_array_params |
Definition at line 133 of file BCP_parameters.hpp.
BCP_parameter_set< Par >::BCP_parameter_set | ( | ) | [inline] |
The default constructor creates a parameter set with from the template argument structure.
The keyword list is created and the defaults are set.
Definition at line 564 of file BCP_parameters.hpp.
BCP_parameter_set< Par >::~BCP_parameter_set | ( | ) | [inline] |
The destructor deletes all data members.
Definition at line 576 of file BCP_parameters.hpp.
void BCP_parameter_set< Par >::create_keyword_list | ( | ) | [private] |
Method for creating the list of keyword looked for in the parameter file.
void BCP_parameter_set< Par >::set_default_entries | ( | ) | [private] |
Method for setting the default values for the parameters.
char BCP_parameter_set< Par >::entry | ( | const chr_params | key | ) | const [inline] |
Definition at line 168 of file BCP_parameters.hpp.
int BCP_parameter_set< Par >::entry | ( | const int_params | key | ) | const [inline] |
Definition at line 171 of file BCP_parameters.hpp.
double BCP_parameter_set< Par >::entry | ( | const dbl_params | key | ) | const [inline] |
Definition at line 174 of file BCP_parameters.hpp.
const BCP_string& BCP_parameter_set< Par >::entry | ( | const str_params | key | ) | const [inline] |
Definition at line 177 of file BCP_parameters.hpp.
const BCP_vec<BCP_string>& BCP_parameter_set< Par >::entry | ( | const str_array_params | key | ) | const [inline] |
Definition at line 180 of file BCP_parameters.hpp.
BCP_parameter_set<Par>& BCP_parameter_set< Par >::operator= | ( | const BCP_parameter_set< Par > & | x | ) | [inline] |
Definition at line 196 of file BCP_parameters.hpp.
void BCP_parameter_set< Par >::set_entry | ( | const chr_params | key, | |
const char | val | |||
) | [inline] |
Definition at line 215 of file BCP_parameters.hpp.
void BCP_parameter_set< Par >::set_entry | ( | const chr_params | key, | |
const bool | val | |||
) | [inline] |
Definition at line 218 of file BCP_parameters.hpp.
void BCP_parameter_set< Par >::set_entry | ( | const int_params | key, | |
const int | val | |||
) | [inline] |
Definition at line 221 of file BCP_parameters.hpp.
void BCP_parameter_set< Par >::set_entry | ( | const dbl_params | key, | |
const double | val | |||
) | [inline] |
Definition at line 224 of file BCP_parameters.hpp.
void BCP_parameter_set< Par >::set_entry | ( | const str_params | key, | |
const char * | val | |||
) | [inline] |
Definition at line 227 of file BCP_parameters.hpp.
void BCP_parameter_set< Par >::set_entry | ( | const str_array_params | key, | |
const char * | val | |||
) | [inline] |
Definition at line 230 of file BCP_parameters.hpp.
void BCP_parameter_set< Par >::set_entry | ( | const BCP_parameter | key, | |
const char * | val | |||
) | [inline] |
Definition at line 233 of file BCP_parameters.hpp.
void BCP_parameter_set< Par >::read_from_stream | ( | std::istream & | parstream | ) | [inline] |
Read the parameters from the stream specified in the argument.
The stream is interpreted as a lines separated by newline characters. The first word on each line is tested for match with the keywords specified in the create_keyword_list() method. If there is a match then the second word will be interpreted as the value for the corresponding parameter. Any further words on the line are discarded. Every non-matching line is discarded.
If the keyword corresponds to a non-array parameter then the new value simply overwrites the old one. Otherwise, i.e., if it is a StringArrayPar, the value is appended to the list of strings in that array.
Definition at line 262 of file BCP_parameters.hpp.
std::string BCP_parameter_set< Par >::expand | ( | const char * | value | ) | [inline] |
Definition at line 385 of file BCP_parameters.hpp.
void BCP_parameter_set< Par >::read_from_file | ( | const char * | paramfile | ) | [inline] |
Simply invoke reading from a stream.
Definition at line 441 of file BCP_parameters.hpp.
void BCP_parameter_set< Par >::read_from_arglist | ( | const int | argnum, | |
const char *const * | arglist | |||
) | [inline] |
Simply invoke reading from a stream.
Definition at line 454 of file BCP_parameters.hpp.
void BCP_parameter_set< Par >::write_to_stream | ( | std::ostream & | outstream | ) | const [inline] |
Write keyword-value pairs to the stream specified in the argument.
Each keyword-value pair is separated by a newline character.
Definition at line 476 of file BCP_parameters.hpp.
void BCP_parameter_set< Par >::pack | ( | BCP_buffer & | buf | ) | [inline] |
Pack the parameter set into the buffer.
Definition at line 522 of file BCP_parameters.hpp.
void BCP_parameter_set< Par >::unpack | ( | BCP_buffer & | buf | ) | [inline] |
Unpack the parameter set from the buffer.
Definition at line 535 of file BCP_parameters.hpp.
BCP_vec< std::pair<BCP_string, BCP_parameter> > BCP_parameter_set< Par >::keys [private] |
The keyword, parameter pairs.
Used when the parameter file is read in.
Definition at line 140 of file BCP_parameters.hpp.
BCP_vec<BCP_string> BCP_parameter_set< Par >::obsolete_keys [private] |
list of obsolete keywords.
If any of these is encountered a warning is printed.
Definition at line 143 of file BCP_parameters.hpp.
char* BCP_parameter_set< Par >::cpar [private] |
The character parameters.
Definition at line 145 of file BCP_parameters.hpp.
int* BCP_parameter_set< Par >::ipar [private] |
The integer parameters.
Definition at line 147 of file BCP_parameters.hpp.
double* BCP_parameter_set< Par >::dpar [private] |
The double parameters.
Definition at line 149 of file BCP_parameters.hpp.
BCP_string* BCP_parameter_set< Par >::spar [private] |
The string (actually, BCP_string) parameters.
Definition at line 151 of file BCP_parameters.hpp.
BCP_vec<BCP_string>* BCP_parameter_set< Par >::sapar [private] |
The string array parameters.
Definition at line 153 of file BCP_parameters.hpp.