3 #ifndef _BCP_PARAMETERS_H
4 #define _BCP_PARAMETERS_H
15 #if defined(__GNUC__) && (__GNUC__ >= 3)
18 # define BCP_STRINGSTREAM std::istringstream
22 # define BCP_STRINGSTREAM std::istrstream
201 std::copy(x.
cpar, x.
cpar + static_cast<int>(Par::end_of_chr_params),
203 std::copy(x.
ipar, x.
ipar + static_cast<int>(Par::end_of_int_params),
205 std::copy(x.
dpar, x.
dpar + static_cast<int>(Par::end_of_dbl_params),
207 std::copy(x.
spar, x.
spar + static_cast<int>(Par::end_of_str_params),
210 x.
sapar + static_cast<int>(Par::end_of_str_array_params),
265 const int MAX_PARAM_LINE_LENGTH = 1024;
266 char line[MAX_PARAM_LINE_LENGTH], *end_of_line, *keyword, *ctmp;
267 char value[MAX_PARAM_LINE_LENGTH];
273 BCP_parameters::read_from_stream Scanning parameter stream.\n");
274 while (!parstream.eof()) {
275 parstream.getline(line, MAX_PARAM_LINE_LENGTH);
276 const int len = strlen(line);
277 if (len == MAX_PARAM_LINE_LENGTH - 1) {
279 There's a too long (>= %i characters) line in the parameter file.\n\
280 This is absurd.\n", MAX_PARAM_LINE_LENGTH);
284 end_of_line = line + len;
288 for (keyword = line; keyword < end_of_line; ++keyword) {
289 if (isgraph(*keyword))
292 if (keyword == end_of_line)
295 for (ctmp = keyword; ctmp < end_of_line; ++ctmp) {
301 for ( ; ctmp < end_of_line; ++ctmp) {
305 if (ctmp == end_of_line)
311 for (i = 0; ctmp < end_of_line; ++ctmp) {
313 if (++ctmp == end_of_line)
326 for (i = 0; ctmp < end_of_line; ++ctmp) {
327 if (!isspace(*ctmp)) {
337 if (strcmp(keyword,
"ParamFile") == 0) {
342 if (strcmp(keyword,
"Quiet") == 0) {
343 int val = atoi(value);
348 std::string value_expanded =
expand(value);
352 if (ind->first == keyword) {
356 printf(
"%s %s\n", keyword, value_expanded.c_str());
358 set_entry((*ind).second, value_expanded.c_str());
366 if (*obs_ind == keyword) {
368 printf(
"***WARNING*** : Obsolete keyword `%s' is found.\n",
376 BCP_parameters::read_from_stream Finished scanning parameter stream.\n\n");
389 const int MAX_PARAM_LINE_LENGTH = 1024;
390 char valueBuf[MAX_PARAM_LINE_LENGTH];
391 bool bDollar =
false;
393 for(
int i = 0; value[i] !=
'\0'; i++){
394 char cval = value[i];
400 valueBuf[j++] = cval;
405 char envBuf[MAX_PARAM_LINE_LENGTH];
410 while((c = value[i++]) !=
')' && c !=
'\0')
413 char* eVal = getenv(envBuf);
416 valueBuf[j++] = *eVal++;
422 valueBuf[j++] = cval;
428 std::string sExpand(valueBuf);
443 std::ifstream parstream(paramfile);
456 std::string argstring;
457 for (
int i = 1; i < argnum; i += 2) {
458 argstring += arglist[i];
461 argstring += arglist[i+1];
479 for (
int i = 0; i < size; ++i) {
482 switch (par.
type()) {
484 outstream << key.
c_str() <<
" "
485 <<
static_cast<int>(
cpar[par.
index()]) <<
"\n";
488 outstream << key.
c_str() <<
" "
492 outstream << key.
c_str() <<
" "
496 outstream << key.
c_str() <<
" "
501 outstream << key.
c_str() <<
" "
509 BCP_parameters::write_to_stream ERROR: Unrecognized parameter type!\n");
523 buf.
pack(
cpar, Par::end_of_chr_params)
525 .
pack(
dpar, Par::end_of_dbl_params);
526 for (
int i = 0; i < Par::end_of_str_params; ++i)
528 for (
int i = 0; i < Par::end_of_str_array_params; ++i) {
538 dummy =
static_cast<int>(Par::end_of_chr_params);
540 dummy =
static_cast<int>(Par::end_of_int_params);
542 dummy =
static_cast<int>(Par::end_of_dbl_params);
544 for (
int i = 0; i < Par::end_of_str_params; ++i)
546 for (
int i = 0; i < Par::end_of_str_array_params; ++i) {
550 for (
size_t j = 0;
j < str_size; ++
j){
566 cpar(new char[static_cast<
int>(Par::end_of_chr_params)+1]),
567 ipar(new
int[static_cast<
int>(Par::end_of_int_params)+1]),
568 dpar(new double[static_cast<
int>(Par::end_of_dbl_params)+1]),
Par::dbl_params dbl_params
const BCP_vec< BCP_string > & entry(const str_array_params key) const
BCP_vec< BCP_string > obsolete_keys
list of obsolete keywords.
BCP_buffer & pack(const T &value)
Pack a single object of type T.
std::string expand(const char *value)
BCP_buffer & unpack(T &value)
Unpack a single object of type T.
void create_keyword_list()
Method for creating the list of keyword looked for in the parameter file.
dbl_params
Double parameters.
char entry(const chr_params key) const
const char * c_str() const
void set_entry(const BCP_parameter key, const char *val)
The parameter is an array of strings.
Par::str_params str_params
iterator begin()
Return an iterator to the beginning of the object.
BCP_parameter_set()
The default constructor creates a parameter set with from the template argument structure.
void set_entry(const dbl_params key, const double val)
int * ipar
The integer parameters.
void set_default_entries()
Method for setting the default values for the parameters.
void reserve(const size_t n)
Reallocate the object to make space for n entries.
void read_from_arglist(const int argnum, const char *const *arglist)
Simply invoke reading from a stream.
BCP_vec< std::pair< BCP_string, BCP_parameter > > keys
The keyword, parameter pairs.
This class is a very simple impelementation of a constant length string.
void write_to_stream(std::ostream &outstream) const
Write keyword-value pairs to the stream specified in the argument.
void push_back(const_reference x)
Append x to the end of the vector.
chr_params
Character parameters.
BCP_string * spar
The string (actually, BCP_string) parameters.
void set_entry(const int_params key, const int val)
void read_from_stream(std::istream &parstream)
Read the parameters from the stream specified in the argument.
This is the class serves as a holder for a set of parameters.
Par::int_params int_params
int entry(const int_params key) const
const BCP_string & entry(const str_params key) const
~BCP_parameter_set()
The destructor deletes all data members.
BCP_vec< BCP_string > * sapar
The string array parameters.
Par::str_array_params str_array_params
void read_from_file(const char *paramfile)
Simply invoke reading from a stream.
void set_entry(const str_params key, const char *val)
void set_entry(const chr_params key, const char val)
BCP_parameter_t type() const
Return the type of the parameter.
int _index
The index of this parameter within all parameters of the same type.
BCP_parameter_t _type
The type of the parameter (e.g., BCP_IntPar).
This parameter indeintifies a single parameter entry.
BCP_parameter(const BCP_parameter_t t, const int i)
Constructor where members are specified.
BCP_parameter()
The default constructor creates a phony parameter.
Currently there isn't any error handling in BCP.
char * cpar
The character parameters.
int_params
Integer parameters.
void set_entry(const chr_params key, const bool val)
size_t size() const
Return the current number of entries.
iterator end()
Return an iterator to the end of the object.
The class BCP_vec serves the same purpose as the vector class in the standard template library...
This class describes the message buffer used for all processes of BCP.
void unchecked_push_back(const_reference x)
Append x to the end of the vector.
BCP_parameter_t
This enumerative constant describes the possible parameter types.
~BCP_parameter()
The destructor.
void unpack(BCP_buffer &buf)
Unpack the parameter set from the buffer.
double entry(const dbl_params key) const
int index() const
Return the index of the parameter within all parameters of the same type.
Par::chr_params chr_params
void pack(BCP_buffer &buf)
Pack the parameter set into the buffer.
void set_entry(const str_array_params key, const char *val)
str_params
String parameters.
The type is not yet specified.
double * dpar
The double parameters.
void fint fint fint real fint real * x
BCP_parameter_set< Par > & operator=(const BCP_parameter_set< Par > &x)