3 #ifndef __READ_STEER_INC__ 4 #define __READ_STEER_INC__ 356 #define READ(X) read_steer::readfile(X) 358 #define BOOL(X) read_steer::getbool(#X) 359 #define INT(X) read_steer::getint(#X) 360 #define DOUBLE(X) read_steer::getdouble(#X) 361 #define CHAR(X) read_steer::getstring(#X).c_str() 362 #define STRING(X) read_steer::getstring(#X) 364 #define BOOL_ARR(X) read_steer::getboolarray(#X) 365 #define INT_ARR(X) read_steer::getintarray(#X) 366 #define DOUBLE_ARR(X) read_steer::getdoublearray(#X) 367 #define STRING_ARR(X) read_steer::getstringarray(#X) 369 #define BOOL_COL(X,Y) read_steer::getboolcolumn(#X,#Y) 370 #define INT_COL(X,Y) read_steer::getintcolumn(#X,#Y) 371 #define DOUBLE_COL(X,Y) read_steer::getdoublecolumn(#X,#Y) 372 #define STRING_COL(X,Y) read_steer::getstringcolumn(#X,#Y) 373 #define TABLEHEADER(X) read_steer::gettableheader(#X) 375 #define INT_TAB(X) read_steer::getinttable(#X) 376 #define DOUBLE_TAB(X) read_steer::getdoubletable(#X) 377 #define STRING_TAB(X) read_steer::getstringtable(#X) 379 #define ADD(X,Y) read_steer::addvalue(X,Y) 380 #define ADDARRAY(X,Y) read_steer::addarray(X,Y) 381 #define ADDTABLE(X,Y,Z) read_steer::addtable(X,Y,Z) 386 #define READ_NS(X,NS) read_steer::readfile(X,NS) 388 #define BOOL_NS(X,NS) read_steer::getbool(#X,NS) 389 #define INT_NS(X,NS) read_steer::getint(#X,NS) 390 #define DOUBLE_NS(X,NS) read_steer::getdouble(#X,NS) 391 #define CHAR_NS(X,NS) read_steer::getstring(#X,NS).c_str() 392 #define STRING_NS(X,NS) read_steer::getstring(#X,NS) 394 #define BOOL_ARR_NS(X,NS) read_steer::getboolarray(#X,NS) 395 #define INT_ARR_NS(X,NS) read_steer::getintarray(#X,NS) 396 #define DOUBLE_ARR_NS(X,NS) read_steer::getdoublearray(#X,NS) 397 #define STRING_ARR_NS(X,NS) read_steer::getstringarray(#X,NS) 399 #define BOOL_COL_NS(X,Y,NS) read_steer::getboolcolumn(#X,#Y,NS) 400 #define INT_COL_NS(X,Y,NS) read_steer::getintcolumn(#X,#Y,NS) 401 #define DOUBLE_COL_NS(X,Y,NS) read_steer::getdoublecolumn(#X,#Y,NS) 402 #define STRING_COL_NS(X,Y,NS) read_steer::getstringcolumn(#X,#Y,NS) 403 #define TABLEHEADER_NS(X,NS) read_steer::gettableheader(#X,NS) 405 #define INT_TAB_NS(X,NS) read_steer::getinttable(#X,NS) 406 #define DOUBLE_TAB_NS(X,NS) read_steer::getdoubletable(#X,NS) 407 #define STRING_TAB_NS(X,NS) read_steer::getstringtable(#X,NS) 409 #define ADD_NS(X,Y,NS) read_steer::addvalue(X,Y,NS) 410 #define ADDARRAY_NS(X,Y,NS) read_steer::addarray(X,Y,NS) 411 #define ADDTABLE_NS(X,Y,Z,NS) read_steer::addtable(X,Y,Z,NS) 414 #define PARSE(X,Y) read_steer::parsecommandline(X,Y) 415 #define PARSEV(X) read_steer::parsecommandline(X) 416 #define PRINTALL() read_steer::printall() 419 #define EXIST(X) read_steer::getexist(#X) 420 #define EXIST_NS(X,NS) read_steer::getexist(#X,NS) 423 #define EXISTARRAY_NS(X,NS) read_steer::getarrayexist(#X, NS) 424 #define CONTAINKEYARRAY_NS(X,A,NS) read_steer::getarraycontainkey(#X, #A, NS) 425 #define PUSHBACKARRAY_NS(X,A,NS) read_steer::arraypushback_steer(X, #A, NS) 430 static std::string stdID;
434 static read_steer* Steering(std::string steerID=read_steer::stdID);
435 static void destroy();
440 bool getb(
const std::string& label);
441 int geti(
const std::string& label);
442 double getd(
const std::string& label);
443 std::string gets(
const std::string& label);
445 std::vector<bool> getbf(
const std::string& label);
446 std::vector<int> getif(
const std::string& label);
447 std::vector<double> getdf(
const std::string& label);
448 std::vector<std::string> getsf(
const std::string& label);
450 std::vector<std::string> getsthead(
const std::string& label);
451 std::vector<std::vector<int> > getit(
const std::string& label);
452 std::vector<std::vector<double> > getdt(
const std::string& label);
453 std::vector<std::vector<std::string> > getst(
const std::string& label);
454 std::vector<bool> getbtcol(
const std::string& label,
const std::string& col);
455 std::vector<int> getitcol(
const std::string& label,
const std::string& col);
456 std::vector<double> getdtcol(
const std::string& label,
const std::string& col);
457 std::vector<std::string> getstcol(
const std::string& label,
const std::string& col);
460 bool exist(
const std::string& label) {
461 bool ret = ( fstrings.count(label) > 0 || ffields.count(label) > 0 || ftables.count(label) > 0 );
463 bool arrayexist(
const std::string& label) {
464 return ffields.count(label) > 0;}
465 bool arraycontainkey(
const std::string& key,
const std::string& label) {
466 if (ffields.count(label) == 0)
return false;
467 for (
size_t i = 0; i < ffields[label].size(); ++i) {
468 if (ffields[label][i].find(key+
"=") == std::string::npos) {
473 void arraypushback(
const std::string& value,
const std::string& label) {
474 ffields[label].push_back(value);}
476 void AddLabel(
const std::string& key,
const std::string& value);
477 template <
typename T>
void AddLabel (
const std::string& key, T value);
478 void AddArray(
const std::string& key,
const std::vector<std::string>& values);
479 template <
typename T>
void AddArray (
const std::string& key,
const std::vector<T>& values);
480 void AddTable(
const std::string& key,
const std::vector<std::string>& header,
const std::vector<std::vector<std::string> >& values);
481 template <
typename T>
void AddTable (
const std::string& key,
const std::vector<std::string>& header,
const std::vector<std::vector<T> >& values);
482 void AppendToArray(
const std::string& key,
const std::string& entry);
483 template <
typename T>
void AppendToArray (
const std::string& key,
const T& entry);
484 void AppendToTable(
const std::string& key,
const std::vector<std::string>& entry);
485 template <
typename T>
void AppendToTable (
const std::string& key,
const std::vector<T>& entry);
488 int inits(std::string filename);
489 int initnmspc(std::ifstream& strm, std::string filename);
491 static void initnamespace(std::ifstream& strm,std::string filename, std::string steerID=read_steer::stdID) {
492 read_steer::Steering(steerID)->initnmspc(strm,filename); }
495 std::set<std::string> GetAvailableLabels()
const;
496 std::set<std::string> GetAvailableArrrays()
const;
497 std::set<std::string> GetAvailableTables()
const;
500 static bool CheckInt(
const std::string& str);
501 static int separatetag(std::string& vallhs, std::string& valrhs,
const std::string& sep);
503 static const std::string& GetDefaultNamespace(){
return stdID;}
504 static void SetDefaultNamespace(
const std::string& nspc){ stdID = nspc;}
509 static std::map<std::string,read_steer*>* instances;
511 int read_stdin(
const std::string& filename);
512 int readstrm(std::ifstream& strm,
unsigned int lstart=0,
unsigned int lend=0,
bool incfile=
false);
513 bool ParseString(std::string value);
514 bool ParseFindString(
const std::string& str,
const std::string& tag)
const;
515 std::string ParseEnclosedString(
const std::string&)
const;
516 bool EnclosedStringToOneEntity(std::string&)
const;
517 int ReplaceVariables(std::string& value);
518 bool StringToBool(
const std::string& str,
const std::string& label=
"")
const;
519 static int cmdlinetag(
const char* arg, std::string& label, std::string& value);
521 std::map<std::string,std::string> fstrings;
522 std::map<std::string,std::vector<std::string> > ffields;
523 std::map<std::string,std::vector<std::vector<std::string> > > ftables;
524 std::map<std::string,std::vector<std::string> > ftableheaders;
525 bool fParseFieldMode;
527 std::string ffieldlabel;
528 std::vector<std::string> ffieldvalues;
529 std::vector<std::vector<std::string> > ftablevalues;
530 std::string ffilename;
531 std::string fcurrentfilename;
534 const std::string str_sep;
535 const std::string str_cmt;
536 const std::string str_arrbeg;
537 const std::string str_arrend;
538 const std::string str_tabbeg;
539 const std::string str_tabend;
540 const std::string str_nmspcbeg;
541 const std::string str_nmspcend;
542 const std::string str_inc;
544 const std::string oW;
545 const std::string oI;
546 const std::string oE;
550 static int readfile(std::string filename,std::string steerID=read_steer::stdID) {
551 return read_steer::Steering(steerID)->inits(filename); }
554 static int fVerbosity;
555 static void setVerbosity(
int iVerbosity) {
556 read_steer::fVerbosity = iVerbosity; }
559 static int getVerbosity() {
560 return read_steer::fVerbosity; }
562 static bool getbool(std::string label,std::string steerID=read_steer::stdID) {
563 return read_steer::Steering(steerID)->getb(label); }
564 static int getint(std::string label,std::string steerID=read_steer::stdID) {
565 return read_steer::Steering(steerID)->geti(label); }
566 static double getdouble(std::string label,std::string steerID=read_steer::stdID) {
567 return read_steer::Steering(steerID)->getd(label); }
568 static std::string getstring(std::string label,std::string steerID=read_steer::stdID) {
569 return read_steer::Steering(steerID)->gets(label); }
571 static std::vector<bool> getboolarray(std::string label,std::string steerID=read_steer::stdID) {
572 return read_steer::Steering(steerID)->getbf(label); }
573 static std::vector<int> getintarray(std::string label,std::string steerID=read_steer::stdID) {
574 return read_steer::Steering(steerID)->getif(label); }
575 static std::vector<double> getdoublearray(std::string label,std::string steerID=read_steer::stdID) {
576 return read_steer::Steering(steerID)->getdf(label); }
577 static std::vector<std::string> getstringarray(std::string label,std::string steerID=read_steer::stdID) {
578 return read_steer::Steering(steerID)->getsf(label); }
580 static std::vector<std::string> gettableheader(std::string label,std::string steerID=read_steer::stdID) {
581 return read_steer::Steering(steerID)->getsthead(label); }
583 static std::vector<std::vector<int> > getinttable(std::string label,std::string steerID=read_steer::stdID) {
584 return read_steer::Steering(steerID)->getit(label); }
585 static std::vector<std::vector<double> > getdoubletable(std::string label,std::string steerID=read_steer::stdID) {
586 return read_steer::Steering(steerID)->getdt(label); }
587 static std::vector<std::vector<std::string> > getstringtable(std::string label,std::string steerID=read_steer::stdID) {
588 return read_steer::Steering(steerID)->getst(label); }
590 static std::vector<bool> getboolcolumn(std::string label,std::string column,std::string steerID=read_steer::stdID) {
591 return read_steer::Steering(steerID)->getbtcol(label,column); }
592 static std::vector<int> getintcolumn(std::string label,std::string column,std::string steerID=read_steer::stdID) {
593 return read_steer::Steering(steerID)->getitcol(label,column); }
594 static std::vector<double> getdoublecolumn(std::string label,std::string column,std::string steerID=read_steer::stdID) {
595 return read_steer::Steering(steerID)->getdtcol(label,column); }
596 static std::vector<std::string> getstringcolumn(std::string label,std::string column,std::string steerID=read_steer::stdID) {
597 return read_steer::Steering(steerID)->getstcol(label,column); }
599 static bool getexist(
const std::string& label, std::string steerID=read_steer::stdID ){
600 if ( read_steer::instances->count(steerID) == 0 )
return false;
601 return read_steer::Steering(steerID)->exist(label);}
602 static bool getarrayexist(
const std::string& label, std::string steerID=read_steer::stdID ){
603 if ( read_steer::instances->count(steerID) == 0 )
return false;
604 return read_steer::Steering(steerID)->arrayexist(label);}
605 static bool getarraycontainkey(
const std::string& key,
const std::string& label, std::string steerID=read_steer::stdID ){
606 if ( read_steer::instances->count(steerID) == 0 )
return false;
607 return read_steer::Steering(steerID)->arraycontainkey(key, label);}
608 static void arraypushback_steer(
const std::string& value,
const std::string& label, std::string steerID=read_steer::stdID ){
609 if ( read_steer::instances->count(steerID) == 0 )
return;
610 read_steer::Steering(steerID)->arraypushback(value, label);}
612 template <
typename T>
613 static void addvalue(
const std::string& key,
const T& val,std::string steerID=read_steer::stdID) {
614 read_steer::Steering(steerID)->AddLabel(key,val); }
615 template <
typename T>
616 static void addarray(
const std::string& key,
const std::vector<T>& val,std::string steerID=read_steer::stdID) {
617 read_steer::Steering(steerID)->AddArray(key,val); }
618 template <
typename T>
619 static void addtable(
const std::string& key,
const std::vector<std::string>& header,
const std::vector<std::vector<T> >& values,std::string steerID=read_steer::stdID) {
620 read_steer::Steering(steerID)->AddTable(key,header,values); }
621 template <
typename T>
622 static void appendtoarray(
const std::string& key,
const T& entry, std::string steerID=read_steer::stdID) {
623 read_steer::Steering(steerID)->AppendToArray(key,entry); }
624 template <
typename T>
625 static void appendtotable(
const std::string& key,
const std::vector<T>& entry, std::string steerID=read_steer::stdID) {
628 static void printall();
629 static void print(std::string steerID=read_steer::stdID);
636 template <
typename T>
637 void read_steer::AddLabel (
const std::string& key, T val) {
638 std::stringstream ss;
640 AddLabel(key,ss.str());
643 template <
typename T>
644 void read_steer::AddArray (
const std::string& key,
const std::vector<T>& val) {
645 std::vector<std::string> str(val.size());
646 for (
unsigned int i = 0 ; i<val.size() ; i++ ) {
647 std::stringstream ss;
654 template <
typename T>
655 void read_steer::AddTable (
const std::string& key,
const std::vector<std::string>& header,
const std::vector<std::vector<T> >& values) {
656 std::vector<std::vector<std::string> > str(values.size());
657 for (
unsigned int i = 0 ; i<values.size() ; i++ ) {
658 str[i].resize(values[i].size());
659 for (
unsigned int j = 0 ; j<values[i].size() ; j++ ) {
660 std::stringstream ss;
665 AddTable(key,header,str);
668 template <
typename T>
669 void read_steer::AppendToArray (
const std::string& key,
const T& entry ) {
670 std::stringstream ss;
672 std::string str=ss.str();
673 AppendToArray(key,entry);
676 template <
typename T>
678 std::vector<std::string > str(entry.size());
679 for (
unsigned int j = 0 ; j<entry.size() ; j++ ) {
680 std::stringstream ss;
Definition: read_steer.h:427
static bool parsecommandline(int argc, char **argv)
Definition: read_steer.cc:782
void AppendToTable(const std::string &key, const std::vector< std::string > &entry)
Definition: read_steer.cc:424
static bool CheckInt(const std::string &str)
Definition: read_steer.cc:441
static bool CheckNumber(const std::string &str)
Definition: read_steer.cc:435