coin-Bcp
Public Types | List of all members
BCP_parameter_set< Par > Class Template Reference

This is the class serves as a holder for a set of parameters. More...

#include <BCP_parameters.hpp>

Inheritance diagram for BCP_parameter_set< Par >:
Inheritance graph
[legend]
Collaboration diagram for BCP_parameter_set< Par >:
Collaboration graph
[legend]

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_stringentry (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. More...
 
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. More...
 
Read parameters from the command line
void read_from_arglist (const int argnum, const char *const *arglist)
 Simply invoke reading from a stream. More...
 
Write parameters to a stream.
void write_to_stream (std::ostream &outstream) const
 Write keyword-value pairs to the stream specified in the argument. More...
 
Packing/unpacking methods
void pack (BCP_buffer &buf)
 Pack the parameter set into the buffer. More...
 
void unpack (BCP_buffer &buf)
 Unpack the parameter set from the buffer. More...
 
Constructors and destructor.
 BCP_parameter_set ()
 The default constructor creates a parameter set with from the template argument structure. More...
 
 ~BCP_parameter_set ()
 The destructor deletes all data members. More...
 

Private Member Functions

Private methods that must be defined for each parameter set.

If the user creates a new parameter set, she must define these two methods for the class.

void create_keyword_list ()
 Method for creating the list of keyword looked for in the parameter file. More...
 
void set_default_entries ()
 Method for setting the default values for the parameters. More...
 

Private Attributes

Data members. All of them are private.
BCP_vec< std::pair< BCP_string,
BCP_parameter > > 
keys
 The keyword, parameter pairs. More...
 
BCP_vec< BCP_stringobsolete_keys
 list of obsolete keywords. More...
 
char * cpar
 The character parameters. More...
 
int * ipar
 The integer parameters. More...
 
double * dpar
 The double parameters. More...
 
BCP_stringspar
 The string (actually, BCP_string) parameters. More...
 
BCP_vec< BCP_string > * sapar
 The string array parameters. More...
 

Detailed Description

template<class Par>
class BCP_parameter_set< Par >

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

  1. first create a struct with the names of the parameters (see, e.g., BCP_tm_par. Assume that the structure is named USER_par.
  2. define the member functions 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.
  3. in her source code declare a variable "<code>BCP_parameter_set<USER_par> param;</code>"

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.

Member Typedef Documentation

template<class Par>
typedef Par::chr_params BCP_parameter_set< Par >::chr_params

Definition at line 129 of file BCP_parameters.hpp.

template<class Par>
typedef Par::int_params BCP_parameter_set< Par >::int_params

Definition at line 130 of file BCP_parameters.hpp.

template<class Par>
typedef Par::dbl_params BCP_parameter_set< Par >::dbl_params

Definition at line 131 of file BCP_parameters.hpp.

template<class Par>
typedef Par::str_params BCP_parameter_set< Par >::str_params

Definition at line 132 of file BCP_parameters.hpp.

template<class Par>
typedef Par::str_array_params BCP_parameter_set< Par >::str_array_params

Definition at line 133 of file BCP_parameters.hpp.

Constructor & Destructor Documentation

template<class Par>
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.

template<class Par>
BCP_parameter_set< Par >::~BCP_parameter_set ( )
inline

The destructor deletes all data members.

Definition at line 576 of file BCP_parameters.hpp.

Member Function Documentation

template<class Par>
void BCP_parameter_set< Par >::create_keyword_list ( )
private

Method for creating the list of keyword looked for in the parameter file.

Referenced by BCP_parameter_set< BCP_tm_par >::BCP_parameter_set().

template<class Par>
void BCP_parameter_set< Par >::set_default_entries ( )
private

Method for setting the default values for the parameters.

Referenced by BCP_parameter_set< BCP_tm_par >::BCP_parameter_set().

template<class Par>
char BCP_parameter_set< Par >::entry ( const chr_params  key) const
inline
template<class Par>
int BCP_parameter_set< Par >::entry ( const int_params  key) const
inline

Definition at line 171 of file BCP_parameters.hpp.

template<class Par>
double BCP_parameter_set< Par >::entry ( const dbl_params  key) const
inline

Definition at line 174 of file BCP_parameters.hpp.

template<class Par>
const BCP_string& BCP_parameter_set< Par >::entry ( const str_params  key) const
inline

Definition at line 177 of file BCP_parameters.hpp.

template<class Par>
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.

template<class Par>
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.

template<class Par>
void BCP_parameter_set< Par >::set_entry ( const chr_params  key,
const char  val 
)
inline
template<class Par>
void BCP_parameter_set< Par >::set_entry ( const chr_params  key,
const bool  val 
)
inline

Definition at line 218 of file BCP_parameters.hpp.

template<class Par>
void BCP_parameter_set< Par >::set_entry ( const int_params  key,
const int  val 
)
inline

Definition at line 221 of file BCP_parameters.hpp.

template<class Par>
void BCP_parameter_set< Par >::set_entry ( const dbl_params  key,
const double  val 
)
inline

Definition at line 224 of file BCP_parameters.hpp.

template<class Par>
void BCP_parameter_set< Par >::set_entry ( const str_params  key,
const char *  val 
)
inline

Definition at line 227 of file BCP_parameters.hpp.

template<class Par>
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.

template<class Par>
void BCP_parameter_set< Par >::set_entry ( const BCP_parameter  key,
const char *  val 
)
inline

Definition at line 233 of file BCP_parameters.hpp.

template<class Par>
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.

Referenced by BCP_parameter_set< BCP_tm_par >::read_from_arglist(), and BCP_parameter_set< BCP_tm_par >::read_from_file().

template<class Par>
std::string BCP_parameter_set< Par >::expand ( const char *  value)
inline
template<class Par>
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.

Referenced by BCP_parameter_set< BCP_tm_par >::read_from_stream().

template<class Par>
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.

template<class Par>
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.

template<class Par>
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.

template<class Par>
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.

Member Data Documentation

template<class Par>
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.

Referenced by BCP_parameter_set< BCP_tm_par >::read_from_stream(), and BCP_parameter_set< BCP_tm_par >::write_to_stream().

template<class Par>
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.

Referenced by BCP_parameter_set< BCP_tm_par >::read_from_stream().

template<class Par>
char* BCP_parameter_set< Par >::cpar
private
template<class Par>
int* BCP_parameter_set< Par >::ipar
private
template<class Par>
double* BCP_parameter_set< Par >::dpar
private
template<class Par>
BCP_string* BCP_parameter_set< Par >::spar
private
template<class Par>
BCP_vec<BCP_string>* BCP_parameter_set< Par >::sapar
private

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