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
71 _type(t), _index(i) {}
82 int index()
const {
return _index; }
121 void create_keyword_list();
123 void set_default_entries();
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),
231 sapar[key].push_back(val); }
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];
273BCP_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) {
279There's a too long (>= %i characters) line in the parameter file.\n\
280This 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);
351 for (ind = keys.
begin(); ind != keys.
end(); ++ind) {
352 if (ind->first == keyword) {
356 printf(
"%s %s\n", keyword, value_expanded.c_str());
358 set_entry((*ind).second, value_expanded.c_str());
363 for (obs_ind = obsolete_keys.begin();
364 obs_ind != obsolete_keys.end();
366 if (*obs_ind == keyword) {
368 printf(
"***WARNING*** : Obsolete keyword `%s' is found.\n",
376BCP_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];
478 const int size = keys.size();
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() <<
" "
489 << ipar[par.
index()] <<
"\n";
492 outstream << key.
c_str() <<
" "
493 << dpar[par.
index()] <<
"\n";
496 outstream << key.
c_str() <<
" "
497 << spar[par.
index()].c_str() <<
"\n";
500 for (
size_t j = 0; j < sapar[par.
index()].size(); ++j) {
501 outstream << key.
c_str() <<
" "
502 << sapar[par.
index()][j].c_str() <<
"\n";
509BCP_parameters::write_to_stream ERROR: Unrecognized parameter type!\n");
523 buf.
pack(cpar, Par::end_of_chr_params)
524 .
pack(ipar, Par::end_of_int_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) {
529 buf.
pack(sapar[i].size());
530 for (
size_t j = 0; j < sapar[i].size(); ++j)
531 buf.
pack(sapar[i][j]);
538 dummy =
static_cast<int>(Par::end_of_chr_params);
539 buf.
unpack(cpar, dummy,
false);
540 dummy =
static_cast<int>(Par::end_of_int_params);
541 buf.
unpack(ipar, dummy,
false);
542 dummy =
static_cast<int>(Par::end_of_dbl_params);
543 buf.
unpack(dpar, dummy,
false);
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) {
549 sapar[i].reserve(str_size);
550 for (
size_t j = 0; j < str_size; ++j){
552 buf.
unpack(sapar[i].back());
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]),
569 spar(new
BCP_string[static_cast<int>(Par::end_of_str_params)+1]),
572 create_keyword_list();
573 set_default_entries();
BCP_parameter_t
This enumerative constant describes the possible parameter types.
@ BCP_NoPar
The type is not yet specified.
@ BCP_StringArrayPar
The parameter is an array of strings.
@ BCP_StringPar
String parameter.
@ BCP_IntPar
Integer parameter.
@ BCP_CharPar
Character parameter.
@ BCP_DoublePar
Double parameter.
This class describes the message buffer used for all processes of BCP.
BCP_buffer & pack(const T &value)
Pack a single object of type T.
BCP_buffer & unpack(T &value)
Unpack a single object of type T.
Currently there isn't any error handling in BCP.
void set_entry(const int_params key, const int val)
void read_from_file(const char *paramfile)
Simply invoke reading from a stream.
BCP_parameter_set< Par > & operator=(const BCP_parameter_set< Par > &x)
void pack(BCP_buffer &buf)
Pack the parameter set into the buffer.
Par::chr_params chr_params
Par::dbl_params dbl_params
void write_to_stream(std::ostream &outstream) const
Write keyword-value pairs to the stream specified in the argument.
double entry(const dbl_params key) const
BCP_parameter_set()
The default constructor creates a parameter set with from the template argument structure.
std::string expand(const char *value)
void read_from_stream(std::istream &parstream)
Read the parameters from the stream specified in the argument.
Par::int_params int_params
void set_entry(const str_array_params key, const char *val)
void set_entry(const str_params key, const char *val)
const BCP_string & entry(const str_params key) const
~BCP_parameter_set()
The destructor deletes all data members.
char entry(const chr_params key) const
void set_entry(const chr_params key, const char val)
const BCP_vec< BCP_string > & entry(const str_array_params key) const
Par::str_array_params str_array_params
Par::str_params str_params
void unpack(BCP_buffer &buf)
Unpack the parameter set from the buffer.
void set_entry(const chr_params key, const bool val)
void set_entry(const dbl_params key, const double val)
int entry(const int_params key) const
void set_entry(const BCP_parameter key, const char *val)
void read_from_arglist(const int argnum, const char *const *arglist)
Simply invoke reading from a stream.
This parameter indeintifies a single parameter entry.
~BCP_parameter()
The destructor.
BCP_parameter()
The default constructor creates a phony parameter.
int index() const
Return the index of the parameter within all parameters of the same type.
BCP_parameter(const BCP_parameter_t t, const int i)
Constructor where members are specified.
BCP_parameter_t type() const
Return the type of the parameter.
This class is a very simple impelementation of a constant length string.
const char * c_str() const
The class BCP_vec serves the same purpose as the vector class in the standard template library.
iterator end()
Return an iterator to the end of the object.
iterator begin()
Return an iterator to the beginning of the object.