GetPot Class Reference
#include <getpot.h>
Classes | |
| struct | variable |
Public Member Functions | |
| GetPot () | |
| GetPot (const GetPot &) | |
| GetPot (int argc_, char **argv_) | |
| GetPot (const char *FileName) | |
| GetPot (const std::string &FileName) | |
| ~GetPot () | |
| GetPot & | operator= (const GetPot &) |
| void | parse_command_line (int argc_, char **argv_) |
| void | parse_input_file (const std::string &FileName) |
| void | parse_input_file (const char *FileName) |
| const char * | operator[] (unsigned Idx) const |
| int | get (unsigned Idx, int Default) const |
| double | get (unsigned Idx, double Default) const |
| const char * | get (unsigned Idx, const char *Default) const |
| unsigned | size () const |
| bool | options_contain (const char *FlagList) const |
| bool | argument_contains (unsigned Idx, const char *FlagList) const |
| bool | have_variable (const char *VarName) const |
| bool | operator() (const char *VarName, bool Default) const |
| int | operator() (const char *VarName, int Default) const |
| unsigned int | operator() (const char *VarName, unsigned int Default) const |
| double | operator() (const char *VarName, double Default) const |
| long double | operator() (const char *VarName, long double Default) const |
| const char * | operator() (const char *VarName, const char *Default) const |
| std::string | operator() (const char *VarName, const std::string &Default) const |
| int | operator() (const char *VarName, int Default, unsigned Idx) const |
| double | operator() (const char *VarName, double Default, unsigned Idx) const |
| const char * | operator() (const char *VarName, const char *Default, unsigned Idx) const |
| std::string | operator() (const char *VarName, const std::string &Default, unsigned Idx) const |
| unsigned | vector_variable_size (const char *VarName) const |
| std::vector< std::string > | get_variable_names () const |
| std::vector< std::string > | get_section_names () const |
| void | set_prefix (const char *Prefix) |
| void | set_prefix (const std::string &Prefix) |
| bool | search_failed () const |
| void | disable_loop () |
| void | enable_loop () |
| void | reset_cursor () |
| void | init_multiple_occurrence () |
| bool | search (const char *option) |
| bool | search (const std::string &option) |
| bool | search (unsigned No, const char *P,...) |
| int | next (int Default) |
| double | next (double Default) |
| const char * | next (const char *Default) |
| std::string | next (const std::string &Default) |
| int | follow (int Default, const char *Option) |
| double | follow (double Default, const char *Option) |
| const char * | follow (const char *Default, const char *Option) |
| int | follow (int Default, unsigned No, const char *Option,...) |
| double | follow (double Default, unsigned No, const char *Option,...) |
| const char * | follow (const char *Default, unsigned No, const char *Option,...) |
| int | direct_follow (int Default, const char *Option) |
| double | direct_follow (double Default, const char *Option) |
| const char * | direct_follow (const char *Default, const char *Option) |
| void | reset_nominus_cursor () |
| std::vector< std::string > | nominus_vector () const |
| unsigned | nominus_size () const |
| const char * | next_nominus () |
| std::vector< std::string > | unidentified_arguments (const std::vector< std::string > &Knowns) const |
| std::vector< std::string > | unidentified_options (const std::vector< std::string > &Knowns) const |
| std::vector< std::string > | unidentified_variables (const std::vector< std::string > &Knowns) const |
| std::vector< std::string > | unidentified_sections (const std::vector< std::string > &Knowns) const |
| std::vector< std::string > | unidentified_nominuses (const std::vector< std::string > &Knowns) const |
| std::string | unidentified_flags (const char *Known, int ArgumentNumber) const |
| std::vector< std::string > | unidentified_arguments (unsigned Number, const char *Known,...) const |
| std::vector< std::string > | unidentified_options (unsigned Number, const char *Known,...) const |
| std::vector< std::string > | unidentified_variables (unsigned Number, const char *Known,...) const |
| std::vector< std::string > | unidentified_sections (unsigned Number, const char *Known,...) const |
| std::vector< std::string > | unidentified_nominuses (unsigned Number, const char *Known,...) const |
| int | print () const |
Private Member Functions | |
| void | __basic_initialization () |
| void | __parse_argument_vector (const std::vector< std::string > &ARGV) |
| const variable * | __find_variable (const char *) const |
| const char * | __match_starting_string (const char *StartString) |
| bool | __check_flags (const std::string &Str, const char *FlagList) const |
| int | __convert_to_type (const std::string &String, int Default) const |
| unsigned int | __convert_to_type (const std::string &String, unsigned int Default) const |
| double | __convert_to_type (const std::string &String, double Default) const |
| long double | __convert_to_type (const std::string &String, long double Default) const |
| bool | __convert_to_type (const std::string &String, bool Default) const |
| const std::string | __get_remaining_string (const std::string &String, const std::string &Start) const |
| bool | __search_string_vector (const std::vector< std::string > &Vec, const std::string &Str) const |
| void | __skip_whitespace (std::istream &istr) |
| const std::string | __get_next_token (std::istream &istr) |
| const std::string | __get_string (std::istream &istr) |
| const std::string | __get_until_closing_bracket (std::istream &istr) |
| std::vector< std::string > | __read_in_stream (std::istream &istr) |
| std::vector< std::string > | __read_in_file (const char *FileName) |
| std::string | __process_section_label (const std::string &Section, std::vector< std::string > §ion_stack) |
| std::string | __DBE_expand_string (const std::string &str) |
| std::string | __DBE_expand (const std::string &str) |
| const GetPot::variable * | __DBE_get_variable (const std::string &str) |
| std::vector< std::string > | __DBE_get_expr_list (const std::string &str, const unsigned ExpectedNumber) |
| std::string | __double2string (double Value) const |
| std::string | __int2string (const int &Value) const |
Private Attributes | |
| std::string | prefix |
| std::string | section |
| std::vector< std::string > | section_list |
| std::vector< std::string > | argv |
| unsigned | cursor |
| bool | search_loop_f |
| bool | search_failed_f |
| int | nominus_cursor |
| std::vector< unsigned > | idx_nominus |
| std::vector< variable > | variables |
Detailed Description
Definition at line 59 of file getpot.h.
Constructor & Destructor Documentation
| GetPot::GetPot | ( | ) | [inline] |
Definition at line 312 of file getpot.h.
References __basic_initialization().
00313 { 00314 __basic_initialization(); 00315 }
| GetPot::GetPot | ( | const GetPot & | Other | ) | [inline] |
Definition at line 344 of file getpot.h.
References operator=().
00345 { 00346 GetPot::operator=(Other); 00347 }
| GetPot::GetPot | ( | int | argc_, | |
| char ** | argv_ | |||
| ) | [inline] |
Definition at line 320 of file getpot.h.
References parse_command_line().
00321 { 00322 parse_command_line (argc_, argv_); 00323 }
| GetPot::GetPot | ( | const char * | FileName | ) | [inline] |
Definition at line 328 of file getpot.h.
References parse_input_file().
00329 { 00330 parse_input_file (FileName); 00331 }
| GetPot::GetPot | ( | const std::string & | FileName | ) | [inline] |
Definition at line 336 of file getpot.h.
References parse_input_file().
00337 { 00338 parse_input_file (FileName); 00339 }
Member Function Documentation
| void GetPot::__basic_initialization | ( | ) | [inline, private] |
Definition at line 302 of file getpot.h.
References cursor, nominus_cursor, prefix, search_failed_f, search_loop_f, and section.
Referenced by GetPot(), parse_command_line(), and parse_input_file().
00303 { 00304 cursor = 0; nominus_cursor = -1; 00305 search_failed_f = true; search_loop_f = true; 00306 prefix = ""; section = ""; 00307 }
| bool GetPot::__check_flags | ( | const std::string & | Str, | |
| const char * | FlagList | |||
| ) | const [inline, private] |
Definition at line 1166 of file getpot.h.
Referenced by argument_contains(), and options_contain().
01167 { 01168 for(const char* p=FlagList; *p != '\0' ; p++) 01169 if( Str.find(*p) != std::string::npos ) return true; // found something 01170 return false; 01171 }
| bool GetPot::__convert_to_type | ( | const std::string & | String, | |
| bool | Default | |||
| ) | const [inline, private] |
Definition at line 741 of file getpot.h.
00742 { 00743 std::string newstring(String); 00744 //std::transform(newstring.begin(), newstring.end(), newstring.begin(), std::toupper); 00745 for (unsigned int i=0; i<newstring.length(); ++i) 00746 { 00747 newstring[i]=toupper(newstring[i]); 00748 } 00749 00750 if (newstring.find("TRUE")!=std::string::npos) return true; 00751 if (newstring.find("FALSE")!=std::string::npos) return false; 00752 return Default; 00753 }
| long double GetPot::__convert_to_type | ( | const std::string & | String, | |
| long double | Default | |||
| ) | const [inline, private] |
| double GetPot::__convert_to_type | ( | const std::string & | String, | |
| double | Default | |||
| ) | const [inline, private] |
| unsigned int GetPot::__convert_to_type | ( | const std::string & | String, | |
| unsigned int | Default | |||
| ) | const [inline, private] |
| int GetPot::__convert_to_type | ( | const std::string & | String, | |
| int | Default | |||
| ) | const [inline, private] |
Definition at line 724 of file getpot.h.
Referenced by __DBE_expand(), direct_follow(), get(), next(), and operator()().
00725 { 00726 int tmp; 00727 if( std::sscanf(String.c_str(),"%i", &tmp) != 1 ) return Default; 00728 return tmp; 00729 }
| std::string GetPot::__DBE_expand | ( | const std::string & | str | ) | [inline, private] |
Definition at line 1568 of file getpot.h.
References __convert_to_type(), __DBE_get_expr_list(), __DBE_get_variable(), __double2string(), __int2string(), GetPot::variable::name, GetPot::variable::original, Utility::pow(), and size().
Referenced by __DBE_expand_string(), and __DBE_get_expr_list().
01569 { 01570 // ${: } pure text 01571 if( expr[0] == ':' ) 01572 return expr.substr(1); 01573 01574 // ${& expr expr ... } text concatination 01575 else if( expr[0] == '&' ) { 01576 const std::vector<std::string> A = __DBE_get_expr_list(expr.substr(1), 1); 01577 01578 std::vector<std::string>::const_iterator it = A.begin(); 01579 std::string result = *it++; 01580 for(; it != A.end(); it++) result += *it; 01581 01582 return result; 01583 } 01584 01585 // ${<-> expr expr expr} text replacement 01586 else if( expr.length() >= 3 && expr.substr(0, 3) == "<->" ) { 01587 std::vector<std::string> A = __DBE_get_expr_list(expr.substr(3), 3); 01588 std::string::size_type tmp = 0; 01589 const std::string::size_type L = A[1].length(); 01590 while( (tmp = A[0].find(A[1])) != std::string::npos ) { 01591 A[0].replace(tmp, L, A[2]); 01592 } 01593 return A[0]; 01594 } 01595 // ${+ ...}, ${- ...}, ${* ...}, ${/ ...} expressions 01596 else if( expr[0] == '+' ) { 01597 std::vector<std::string> A = __DBE_get_expr_list(expr.substr(1), 2); 01598 std::vector<std::string>::const_iterator it = A.begin(); 01599 double result = __convert_to_type(*it++, 0.0); 01600 for(; it != A.end(); it++) 01601 result += __convert_to_type(*it, 0.0); 01602 01603 return __double2string(result); 01604 } 01605 else if( expr[0] == '-' ) { 01606 std::vector<std::string> A = __DBE_get_expr_list(expr.substr(1), 2); 01607 std::vector<std::string>::const_iterator it = A.begin(); 01608 double result = __convert_to_type(*it++, 0.0); 01609 for(; it != A.end(); it++) 01610 result -= __convert_to_type(*it, 0.0); 01611 01612 return __double2string(result); 01613 } 01614 else if( expr[0] == '*' ) { 01615 std::vector<std::string> A = __DBE_get_expr_list(expr.substr(1), 2); 01616 std::vector<std::string>::const_iterator it = A.begin(); 01617 double result = __convert_to_type(*it++, 0.0); 01618 for(; it != A.end(); it++) 01619 result *= __convert_to_type(*it, 0.0); 01620 01621 return __double2string(result); 01622 } 01623 else if( expr[0] == '/' ) { 01624 std::vector<std::string> A = __DBE_get_expr_list(expr.substr(1), 2); 01625 std::vector<std::string>::const_iterator it = A.begin(); 01626 double result = __convert_to_type(*it++, 0.0); 01627 if( result == 0 ) return "0.0"; 01628 for(; it != A.end(); it++) { 01629 const double Q = __convert_to_type(*it, 0.0); 01630 if( Q == 0.0 ) return "0.0"; 01631 result /= Q; 01632 } 01633 return __double2string(result); 01634 } 01635 01636 // ${^ ... } power expressions 01637 else if( expr[0] == '^' ) { 01638 std::vector<std::string> A = __DBE_get_expr_list(expr.substr(1), 2); 01639 std::vector<std::string>::const_iterator it = A.begin(); 01640 double result = __convert_to_type(*it++, 0.0); 01641 for(; it != A.end(); it++) 01642 result = pow(result, __convert_to_type(*it, 0.0)); 01643 return __double2string(result); 01644 } 01645 01646 // ${== } ${<= } ${>= } comparisons (return the number of the first 'match' 01647 else if( expr.length() >= 2 && 01648 ( expr.substr(0,2) == "==" || expr.substr(0,2) == ">=" || 01649 expr.substr(0,2) == "<=" || expr[0] == '>' || expr[0] == '<')) { 01650 // differentiate between two and one sign operators 01651 unsigned op = 0; 01652 enum { EQ, GEQ, LEQ, GT, LT }; 01653 if ( expr.substr(0, 2) == "==" ) op = EQ; 01654 else if ( expr.substr(0, 2) == ">=" ) op = GEQ; 01655 else if ( expr.substr(0, 2) == "<=" ) op = LEQ; 01656 else if ( expr[0] == '>' ) op = GT; 01657 else /* "<" */ op = LT; 01658 01659 std::vector<std::string> a; 01660 if ( op == GT || op == LT ) a = __DBE_get_expr_list(expr.substr(1), 2); 01661 else a = __DBE_get_expr_list(expr.substr(2), 2); 01662 01663 std::string x_orig = a[0]; 01664 double x = __convert_to_type(x_orig, 1e37); 01665 unsigned i = 1; 01666 01667 std::vector<std::string>::const_iterator y_orig = a.begin(); 01668 for(y_orig++; y_orig != a.end(); y_orig++) { 01669 double y = __convert_to_type(*y_orig, 1e37); 01670 01671 // set the strings as reference if one wasn't a number 01672 if ( x == 1e37 || y == 1e37 ) { 01673 // it's a string comparison 01674 if( (op == EQ && x_orig == *y_orig) || (op == GEQ && x_orig >= *y_orig) || 01675 (op == LEQ && x_orig <= *y_orig) || (op == GT && x_orig > *y_orig) || 01676 (op == LT && x_orig < *y_orig) ) 01677 return __int2string(i); 01678 } 01679 else { 01680 // it's a number comparison 01681 if( (op == EQ && x == y) || (op == GEQ && x >= y) || 01682 (op == LEQ && x <= y) || (op == GT && x > y) || 01683 (op == LT && x < y) ) 01684 return __int2string(i); 01685 } 01686 i++; 01687 } 01688 01689 // nothing fulfills the condition => return 0 01690 return "0"; 01691 } 01692 // ${?? expr expr} select 01693 else if( expr.length() >= 2 && expr.substr(0, 2) == "??" ) { 01694 std::vector<std::string> a = __DBE_get_expr_list(expr.substr(2), 2); 01695 double x = __convert_to_type(a[0], 1e37); 01696 // last element is always the default argument 01697 if( x == 1e37 || x < 0 || x >= a.size() - 1 ) return a[a.size()-1]; 01698 01699 // round x to closest integer 01700 return a[int(x+0.5)]; 01701 } 01702 // ${? expr expr expr} if then else conditions 01703 else if( expr[0] == '?' ) { 01704 std::vector<std::string> a = __DBE_get_expr_list(expr.substr(1), 2); 01705 if( __convert_to_type(a[0], 0.0) == 1.0 ) return a[1]; 01706 else if( a.size() > 2 ) return a[2]; 01707 } 01708 // ${! expr} maxro expansion 01709 else if( expr[0] == '!' ) { 01710 const GetPot::variable* Var = __DBE_get_variable(expr.substr(1)); 01711 // error 01712 if( Var->name == "" ) return std::string(Var->original); 01713 01714 const std::vector<std::string> A = __DBE_get_expr_list(Var->original, 2); 01715 return A[0]; 01716 } 01717 // ${@: } - string subscription 01718 else if( expr.length() >= 2 && expr.substr(0,2) == "@:" ) { 01719 const std::vector<std::string> A = __DBE_get_expr_list(expr.substr(2), 2); 01720 double x = __convert_to_type(A[1], 1e37); 01721 01722 // last element is always the default argument 01723 if( x == 1e37 || x < 0 || x >= A[0].size() - 1) 01724 return "<<1st index out of range>>"; 01725 01726 if( A.size() > 2 ) { 01727 double y = __convert_to_type(A[2], 1e37); 01728 if ( y != 1e37 && y > 0 && y <= A[0].size() - 1 && y > x ) 01729 return A[0].substr(int(x+0.5), int(y+1.5) - int(x+0.5)); 01730 else if( y == -1 ) 01731 return A[0].substr(int(x+0.5)); 01732 return "<<2nd index out of range>>"; 01733 } 01734 else { 01735 char* tmp = new char[2]; 01736 tmp[0] = A[0][int(x+0.5)]; tmp[1] = '\0'; 01737 std::string result(tmp); 01738 delete [] tmp; 01739 return result; 01740 } 01741 } 01742 // ${@ } - vector subscription 01743 else if( expr[0] == '@' ) { 01744 std::vector<std::string> A = __DBE_get_expr_list(expr.substr(1), 2); 01745 const GetPot::variable* Var = __DBE_get_variable(A[0]); 01746 // error 01747 if( Var->name == "" ) { 01748 // make a copy of the string if an error occured 01749 // (since the error variable is a static variable inside get_variable()) 01750 return std::string(Var->original); 01751 } 01752 01753 double x = __convert_to_type(A[1], 1e37); 01754 01755 // last element is always the default argument 01756 if (x == 1e37 || x < 0 || x >= Var->value.size() ) 01757 return "<<1st index out of range>>"; 01758 01759 if ( A.size() > 2) { 01760 double y = __convert_to_type(A[2], 1e37); 01761 int begin = int(x+0.5); 01762 int end = 0; 01763 if ( y != 1e37 && y > 0 && y <= Var->value.size() && y > x) 01764 end = int(y+1.5); 01765 else if( y == -1 ) 01766 end = Var->value.size(); 01767 else 01768 return "<<2nd index out of range>>"; 01769 01770 std::string result = *(Var->get_element(begin)); 01771 for(int i = begin+1; i < end; i++) 01772 result += std::string(" ") + *(Var->get_element(i)); 01773 return result; 01774 } 01775 else 01776 return *(Var->get_element(int(x+0.5))); 01777 } 01778 01779 const std::vector<std::string> A = __DBE_get_expr_list(expr, 1); 01780 const GetPot::variable* B = __DBE_get_variable(A[0]); 01781 01782 // make a copy of the string if an error occured 01783 // (since the error variable is a static variable inside get_variable()) 01784 if( B->name == "" ) 01785 return std::string(B->original); 01786 01787 //else 01788 01789 return B->original; 01790 }
| std::string GetPot::__DBE_expand_string | ( | const std::string & | str | ) | [inline, private] |
Definition at line 1437 of file getpot.h.
References __DBE_expand().
Referenced by __parse_argument_vector().
01438 { 01439 // Parses for closing operators '${ }' and expands them letting 01440 // white spaces and other letters as they are. 01441 std::string new_string = ""; 01442 unsigned open_brackets = 0; 01443 unsigned first = 0; 01444 for(unsigned i = 0; i<str.size(); i++) { 01445 if( i < str.size() - 2 && str.substr(i, 2) == "${" ) { 01446 if( open_brackets == 0 ) first = i+2; 01447 open_brackets++; 01448 } 01449 else if( str[i] == '}' && open_brackets > 0) { 01450 open_brackets -= 1; 01451 if( open_brackets == 0 ) { 01452 const std::string Replacement = __DBE_expand(str.substr(first, i - first)); 01453 new_string += Replacement; 01454 } 01455 } 01456 else if( open_brackets == 0 ) 01457 new_string += str[i]; 01458 } 01459 return new_string; 01460 }
| std::vector< std::string > GetPot::__DBE_get_expr_list | ( | const std::string & | str, | |
| const unsigned | ExpectedNumber | |||
| ) | [inline, private] |
Definition at line 1465 of file getpot.h.
References __DBE_expand().
Referenced by __DBE_expand().
01468 { 01469 std::string str = str_; 01470 // Separates expressions by non-bracketed whitespaces, expands them 01471 // and puts them into a list. 01472 01473 unsigned i=0; 01474 // (1) eat initial whitespaces 01475 for(; i < str.size(); i++) 01476 if( ! isspace(str[i]) ) break; 01477 01478 std::vector<std::string> expr_list; 01479 unsigned open_brackets = 0; 01480 std::vector<unsigned> start_idx; 01481 unsigned start_new_string = i; 01482 unsigned l = str.size(); 01483 01484 // (2) search for ${ } expressions ... 01485 while( i < l ) { 01486 const char letter = str[i]; 01487 // whitespace -> end of expression 01488 if( isspace(letter) && open_brackets == 0) { 01489 expr_list.push_back(str.substr(start_new_string, i - start_new_string)); 01490 bool no_breakout_f = true; 01491 for(i++; i < l ; i++) { 01492 if( ! isspace(str[i]) ) 01493 { no_breakout_f = false; start_new_string = i; break; } 01494 } 01495 if( no_breakout_f ) { 01496 // end of expression list 01497 if( expr_list.size() < ExpectedNumber ) { 01498 const std::string pre_tmp("<< ${ }: missing arguments>>"); 01499 std::vector<std::string> tmp(ExpectedNumber - expr_list.size(), pre_tmp); 01500 expr_list.insert(expr_list.end(), tmp.begin(), tmp.end()); 01501 } 01502 return expr_list; 01503 } 01504 } 01505 01506 // dollar-bracket expression 01507 if( str.length() >= i+2 && str.substr(i, 2) == "${" ) { 01508 open_brackets++; 01509 start_idx.push_back(i+2); 01510 } 01511 else if( letter == '}' && open_brackets > 0) { 01512 unsigned start = start_idx[start_idx.size()-1]; 01513 start_idx.pop_back(); 01514 const std::string Replacement = __DBE_expand(str.substr(start, i-start)); 01515 if( start < 3) 01516 str = Replacement + str.substr(i+1); 01517 else 01518 str = str.substr(0, start-2) + Replacement + str.substr(i+1); 01519 l = str.size(); 01520 i = start + Replacement.size() - 3; 01521 open_brackets--; 01522 } 01523 i++; 01524 } 01525 01526 // end of expression list 01527 expr_list.push_back(str.substr(start_new_string, i-start_new_string)); 01528 01529 if( expr_list.size() < ExpectedNumber ) { 01530 const std::string pre_tmp("<< ${ }: missing arguments>>"); 01531 std::vector<std::string> tmp(ExpectedNumber - expr_list.size(), pre_tmp); 01532 expr_list.insert(expr_list.end(), tmp.begin(), tmp.end()); 01533 } 01534 01535 return expr_list; 01536 }
| const GetPot::variable * GetPot::__DBE_get_variable | ( | const std::string & | str | ) | [inline, private] |
Definition at line 1541 of file getpot.h.
References __find_variable(), GetPot::variable::name, GetPot::variable::original, prefix, and section.
Referenced by __DBE_expand().
01542 { 01543 static GetPot::variable ev; 01544 std::string secure_Prefix = prefix; 01545 01546 prefix = section; 01547 // (1) first search in currently active section 01548 const GetPot::variable* var = __find_variable(VarName.c_str()); 01549 if( var != 0 ) { prefix = secure_Prefix; return var; } 01550 01551 // (2) search in root name space 01552 prefix = ""; 01553 var = __find_variable(VarName.c_str()); 01554 if( var != 0 ) { prefix = secure_Prefix; return var; } 01555 01556 prefix = secure_Prefix; 01557 01558 // error occured => variable name == "" 01559 char* tmp = new char[VarName.length() + 25]; 01560 std::sprintf(tmp, "<<${ } variable '%s' undefined>>", VarName.c_str()); 01561 ev.name = ""; 01562 ev.original = std::string(tmp); 01563 delete [] tmp; 01564 return &ev; 01565 }
| std::string GetPot::__double2string | ( | double | Value | ) | const [inline, private] |
Definition at line 280 of file getpot.h.
Referenced by __DBE_expand().
00280 { 00281 char* tmp = new char[128]; 00282 std::sprintf(tmp, "%e", Value); 00283 std::string result(tmp); 00284 delete [] tmp; 00285 return result; 00286 }
| const GetPot::variable * GetPot::__find_variable | ( | const char * | Name | ) | const [inline, private] |
Definition at line 1360 of file getpot.h.
References QuadratureRules::name(), prefix, and variables.
Referenced by __DBE_get_variable(), __parse_argument_vector(), have_variable(), operator()(), and vector_variable_size().
01361 { 01362 std::string name = prefix + Name; 01363 for(std::vector<variable>::const_iterator it = variables.begin(); 01364 it != variables.end(); 01365 it++) 01366 if( (*it).name == name ) return &(*it); 01367 return 0; 01368 }
| const std::string GetPot::__get_next_token | ( | std::istream & | istr | ) | [inline, private] |
Definition at line 567 of file getpot.h.
References __get_string(), and __get_until_closing_bracket().
Referenced by __read_in_stream().
00570 { 00571 std::string token; 00572 int tmp = 0; 00573 int last_letter = 0; 00574 while(1+1 == 2) { 00575 last_letter = tmp; tmp = istr.get(); 00576 if( tmp == EOF 00577 || ((tmp == ' ' || tmp == '\t' || tmp == '\n') && last_letter != '\\') ) { 00578 return token; 00579 } 00580 else if( tmp == '\'' && last_letter != '\\' ) { 00581 // QUOTES: un-backslashed quotes => it's a string 00582 token += __get_string(istr); 00583 continue; 00584 } 00585 else if( tmp == '{' && last_letter == '$') { 00586 token += '{' + __get_until_closing_bracket(istr); 00587 continue; 00588 } 00589 else if( tmp == '$' && last_letter == '\\') { 00590 token += tmp; tmp = 0; // so that last_letter will become = 0, not '$'; 00591 continue; 00592 } 00593 else if( tmp == '\\' && last_letter != '\\') 00594 continue; // don't append un-backslashed backslashes 00595 token += tmp; 00596 } 00597 00598 return token; 00599 }
| const std::string GetPot::__get_remaining_string | ( | const std::string & | String, | |
| const std::string & | Start | |||
| ) | const [inline, private] |
Definition at line 761 of file getpot.h.
Referenced by argument_contains(), get_variable_names(), next(), options_contain(), unidentified_arguments(), unidentified_flags(), unidentified_nominuses(), unidentified_options(), unidentified_sections(), and unidentified_variables().
00764 { 00765 if( Start == "" ) return String; 00766 // note: java.lang.String: substring(a,b) = from a to b-1 00767 // C++ string: substr(a,b) = from a to a + b 00768 if( String.find(Start) == 0 ) return String.substr(Start.length()); 00769 else return ""; 00770 }
| const std::string GetPot::__get_string | ( | std::istream & | istr | ) | [inline, private] |
Definition at line 604 of file getpot.h.
Referenced by __get_next_token().
00606 { 00607 std::string str; 00608 int tmp = 0; 00609 int last_letter = 0; 00610 while(1 + 1 == 2) { 00611 last_letter = tmp; tmp = istr.get(); 00612 if( tmp == EOF) return str; 00613 // un-backslashed quotes => it's the end of the string 00614 else if( tmp == '\'' && last_letter != '\\') return str; 00615 else if( tmp == '\\' && last_letter != '\\') continue; // don't append 00616 00617 str += tmp; 00618 } 00619 00620 return str; 00621 }
| const std::string GetPot::__get_until_closing_bracket | ( | std::istream & | istr | ) | [inline, private] |
Definition at line 626 of file getpot.h.
Referenced by __get_next_token().
00628 { 00629 std::string str = ""; 00630 int tmp = 0; 00631 int last_letter = 0; 00632 int brackets = 1; 00633 while(1 + 1 == 2) { 00634 last_letter = tmp; tmp = istr.get(); 00635 if( tmp == EOF) return str; 00636 else if( tmp == '{' && last_letter == '$') brackets += 1; 00637 else if( tmp == '}') { 00638 brackets -= 1; 00639 // un-backslashed brackets => it's the end of the string 00640 if( brackets == 0) return str + '}'; 00641 else if( tmp == '\\' && last_letter != '\\') 00642 continue; // do not append an unbackslashed backslash 00643 } 00644 str += tmp; 00645 } 00646 00647 return str; 00648 }
| std::string GetPot::__int2string | ( | const int & | Value | ) | const [inline, private] |
Definition at line 287 of file getpot.h.
Referenced by __DBE_expand().
00287 { 00288 char* tmp = new char[128]; 00289 std::sprintf(tmp, "%i", Value); 00290 std::string result(tmp); 00291 delete [] tmp; 00292 return result; 00293 }
| const char * GetPot::__match_starting_string | ( | const char * | StartString | ) | [inline, private] |
Definition at line 1087 of file getpot.h.
References argv, cursor, search_failed_f, and search_loop_f.
Referenced by direct_follow().
01091 { 01092 const unsigned N = std::strlen(StartString); 01093 unsigned OldCursor = cursor; 01094 if( OldCursor >= argv.size() ) OldCursor = argv.size() - 1; 01095 search_failed_f = true; 01096 01097 // (*) first loop from cursor position until end 01098 unsigned c = cursor; 01099 for(; c < argv.size(); c++) { 01100 if( std::strncmp(StartString, argv[c].c_str(), N) == 0) 01101 { cursor = c; search_failed_f = false; return &(argv[c].c_str()[N]); } 01102 } 01103 01104 if( ! search_loop_f ) return false; 01105 01106 // (*) second loop from 0 to old cursor position 01107 for(c = 1; c < OldCursor; c++) { 01108 if( std::strncmp(StartString, argv[c].c_str(), N) == 0) 01109 { cursor = c; search_failed_f = false; return &(argv[c].c_str()[N]); } 01110 } 01111 return 0; 01112 }
| void GetPot::__parse_argument_vector | ( | const std::vector< std::string > & | ARGV | ) | [inline, private] |
Definition at line 422 of file getpot.h.
References __DBE_expand_string(), __find_variable(), __process_section_label(), argv, idx_nominus, section, section_list, and variables.
Referenced by parse_command_line(), and parse_input_file().
00423 { 00424 // build internal databases: 00425 // 1) array with no-minus arguments (usually used as filenames) 00426 // 2) variable assignments: 00427 // 'variable name' '=' number | string 00428 section = ""; 00429 std::vector<std::string> section_stack; 00430 unsigned i=0; 00431 std::vector<std::string>::const_iterator it = ARGV.begin(); 00432 std::vector<std::string>::const_iterator it_end = ARGV.end(); 00433 argv.push_back(*it); 00434 00435 for(++it; it != it_end; ++it, i++) { 00436 std::string arg = *it; 00437 if( arg.length() == 0 ) continue; 00438 00439 // -- [section] labels 00440 if( (arg.length() > 1) && 00441 (arg[0] == '[' ) && 00442 (arg[arg.length()-1] == ']') ) { 00443 const std::string Name = __DBE_expand_string(arg.substr(1, arg.length()-2)); 00444 section = __process_section_label(Name, section_stack); 00445 // new section --> append to list of sections 00446 if( std::find(section_list.begin(), section_list.end(), section) == section_list.end() ) 00447 if( section.length() != 0 ) section_list.push_back(section); 00448 argv.push_back(arg); 00449 } 00450 else { 00451 arg = section + __DBE_expand_string(arg); 00452 argv.push_back(arg); 00453 } 00454 00455 // -- separate array for nominus arguments 00456 if( arg[0] != '-' ) idx_nominus.push_back(unsigned(i)); 00457 00458 // -- variables: does arg contain a '=' operator ? 00459 for(const char* p = arg.c_str(); *p ; p++) { 00460 if( *p == '=' ) { 00461 // set terminating 'zero' to treat first part as single string 00462 // => arg (from start to 'p') = Name of variable 00463 // p+1 (until terminating zero) = value of variable 00464 char* o = (char*)p++; 00465 *o = '\0'; 00466 const GetPot::variable* Var = __find_variable(arg.c_str()); 00467 00468 if( Var == 0 ) 00469 variables.push_back(variable(arg.c_str(), p)); 00470 else 00471 ((GetPot::variable*)Var)->take(p); 00472 00473 *o = '='; 00474 break; 00475 } 00476 } 00477 } 00478 }
| std::string GetPot::__process_section_label | ( | const std::string & | Section, | |
| std::vector< std::string > & | section_stack | |||
| ) | [inline, private] |
Definition at line 653 of file getpot.h.
Referenced by __parse_argument_vector().
00655 { 00656 std::string sname = Section; 00657 // 1) subsection of actual section ('./' prefix) 00658 if( sname.length() >= 2 && sname.substr(0, 2) == "./" ) { 00659 sname = sname.substr(2); 00660 } 00661 // 2) subsection of parent section ('../' prefix) 00662 else if( sname.length() >= 3 && sname.substr(0, 3) == "../" ) { 00663 do { 00664 if( section_stack.end() != section_stack.begin() ) 00665 section_stack.pop_back(); 00666 sname = sname.substr(3); 00667 } while( sname.substr(0, 3) == "../" ); 00668 } 00669 // 3) subsection of the root-section 00670 else { 00671 section_stack.erase(section_stack.begin(), section_stack.end()); 00672 // [] => back to root section 00673 } 00674 00675 if( sname != "" ) { 00676 // parse section name for 'slashes' 00677 unsigned i=0; 00678 while( i < sname.length() ) { 00679 if( sname[i] == '/' ) { 00680 section_stack.push_back(sname.substr(0,i)); 00681 if( i+1 < sname.length()-1 ) 00682 sname = sname.substr(i+1); 00683 i = 0; 00684 } 00685 else 00686 i++; 00687 } 00688 section_stack.push_back(sname); 00689 } 00690 std::string section_name = ""; 00691 if( section_stack.size() != 0 ) 00692 victorate(std::string, section_stack, it) { 00693 section_name += *it + "/"; 00694 } 00695 return section_name; 00696 }
| std::vector< std::string > GetPot::__read_in_file | ( | const char * | FileName | ) | [inline, private] |
Definition at line 483 of file getpot.h.
References __read_in_stream().
Referenced by parse_input_file().
00484 { 00485 std::ifstream i(FileName); 00486 if( ! i ) return std::vector<std::string>(); 00487 // argv[0] == the filename of the file that was read in 00488 return __read_in_stream(i); 00489 }
| std::vector< std::string > GetPot::__read_in_stream | ( | std::istream & | istr | ) | [inline, private] |
Definition at line 494 of file getpot.h.
References __get_next_token(), and __skip_whitespace().
Referenced by __read_in_file().
00495 { 00496 std::vector<std::string> brute_tokens; 00497 while(istr) { 00498 __skip_whitespace(istr); 00499 const std::string Token = __get_next_token(istr); 00500 if( Token.empty() || 00501 (Token[0] == static_cast<std::string::value_type>(EOF)) ) break; 00502 brute_tokens.push_back(Token); 00503 } 00504 00505 // -- reduce expressions of token1'='token2 to a single 00506 // string 'token1=token2' 00507 // -- copy everything into 'argv' 00508 // -- arguments preceded by something like '[' name ']' (section) 00509 // produce a second copy of each argument with a prefix '[name]argument' 00510 unsigned i1 = 0; 00511 unsigned i2 = 1; 00512 unsigned i3 = 2; 00513 00514 std::vector<std::string> arglist; 00515 while( i1 < brute_tokens.size() ) { 00516 const std::string& SRef = brute_tokens[i1]; 00517 // 1) concatinate 'abcdef' '=' 'efgasdef' to 'abcdef=efgasdef' 00518 // note: java.lang.String: substring(a,b) = from a to b-1 00519 // C++ string: substr(a,b) = from a to a + b 00520 if( i2 < brute_tokens.size() && brute_tokens[i2] == "=" ) { 00521 if( i3 >= brute_tokens.size() ) 00522 arglist.push_back(brute_tokens[i1] + brute_tokens[i2]); 00523 else 00524 arglist.push_back(brute_tokens[i1] + brute_tokens[i2] + brute_tokens[i3]); 00525 i1 = i3+1; i2 = i3+2; i3 = i3+3; 00526 continue; 00527 } 00528 else { 00529 arglist.push_back(SRef); 00530 i1=i2; i2=i3; i3++; 00531 } 00532 } 00533 return arglist; 00534 }
| bool GetPot::__search_string_vector | ( | const std::vector< std::string > & | Vec, | |
| const std::string & | Str | |||
| ) | const [inline, private] |
Definition at line 1799 of file getpot.h.
Referenced by unidentified_arguments(), unidentified_nominuses(), unidentified_options(), unidentified_sections(), and unidentified_variables().
01800 { 01801 victorate(std::string, VecStr, itk) { 01802 if( *itk == Str ) return true; 01803 } 01804 return false; 01805 }
| void GetPot::__skip_whitespace | ( | std::istream & | istr | ) | [inline, private] |
Definition at line 539 of file getpot.h.
Referenced by __read_in_stream().
00541 { 00542 int tmp = istr.get(); 00543 do { 00544 while( isspace(tmp) ) { 00545 tmp = istr.get(); 00546 if( ! istr ) return; 00547 } 00548 // found a non whitespace 00549 if( tmp == '#' ) { 00550 // comment => skip until end of line 00551 while( tmp != '\n' ) { 00552 if( ! istr ) { istr.unget(); return; } 00553 tmp = istr.get(); 00554 } 00555 continue; 00556 } 00557 else { 00558 istr.unget(); 00559 return; 00560 } 00561 } while( istr ); 00562 }
| bool GetPot::argument_contains | ( | unsigned | Idx, | |
| const char * | FlagList | |||
| ) | const [inline] |
Definition at line 1139 of file getpot.h.
References __check_flags(), __get_remaining_string(), argv, and prefix.
01140 { 01141 if( Idx >= argv.size() ) return false; 01142 01143 if( prefix == "" ) 01144 // search argument for any flag in flag list 01145 return __check_flags(argv[Idx], FlagList); 01146 01147 // if a prefix is set, then the argument index is the index 01148 // inside the 'namespace' 01149 // => only check list of arguments that start with prefix 01150 unsigned no_matches = 0; 01151 for(unsigned i=0; i<argv.size(); i++) { 01152 const std::string Remain = __get_remaining_string(argv[i], prefix); 01153 if( Remain != "") { 01154 no_matches += 1; 01155 if( no_matches == Idx) 01156 return __check_flags(Remain, FlagList); 01157 } 01158 } 01159 // no argument in this namespace 01160 return false; 01161 }
| const char * GetPot::direct_follow | ( | const char * | Default, | |
| const char * | Option | |||
| ) | [inline] |
Definition at line 1075 of file getpot.h.
References __match_starting_string(), argv, cursor, and search_failed_f.
01076 { 01077 if( search_failed_f ) return Default; 01078 const char* FollowStr = __match_starting_string(Option); 01079 if( FollowStr == 0 ) return Default; 01080 if( ++cursor >= argv.size() ) cursor = argv.size(); 01081 return FollowStr; 01082 }
| double GetPot::direct_follow | ( | double | Default, | |
| const char * | Option | |||
| ) | [inline] |
Definition at line 1064 of file getpot.h.
References __convert_to_type(), __match_starting_string(), argv, and cursor.
01065 { 01066 const char* FollowStr = __match_starting_string(Option); 01067 if( FollowStr == 0 ) return Default; 01068 if( ++cursor >= argv.size() ) cursor = argv.size(); 01069 return __convert_to_type(FollowStr, Default); 01070 }
| int GetPot::direct_follow | ( | int | Default, | |
| const char * | Option | |||
| ) | [inline] |
Definition at line 1053 of file getpot.h.
References __convert_to_type(), __match_starting_string(), argv, and cursor.
01054 { 01055 const char* FollowStr = __match_starting_string(Option); 01056 if( FollowStr == 0 ) return Default; 01057 if( ++cursor >= argv.size() ) cursor = argv.size(); 01058 return __convert_to_type(FollowStr, Default); 01059 }
| void GetPot::disable_loop | ( | ) | [inline] |
Definition at line 115 of file getpot.h.
References search_loop_f.
Referenced by init_multiple_occurrence().
00115 { search_loop_f = false; }
| void GetPot::enable_loop | ( | ) | [inline] |
| const char * GetPot::follow | ( | const char * | Default, | |
| unsigned | No, | |||
| const char * | Option, | |||
| ... | ||||
| ) | [inline] |
Definition at line 1026 of file getpot.h.
References next(), and search().
01027 { 01028 if( No == 0 ) return Default; 01029 if( search(P) == true ) return next(Default); 01030 01031 std::va_list ap; 01032 va_start(ap, P); 01033 for(unsigned i=1; i<No; i++) { 01034 char* Opt = va_arg(ap, char *); 01035 if( search(Opt) == true ) { 01036 va_end(ap); 01037 return next(Default); 01038 } 01039 } 01040 va_end(ap); 01041 return Default; 01042 }
| double GetPot::follow | ( | double | Default, | |
| unsigned | No, | |||
| const char * | Option, | |||
| ... | ||||
| ) | [inline] |
Definition at line 1005 of file getpot.h.
References next(), and search().
01006 { 01007 if( No == 0 ) return Default; 01008 if( search(P) == true ) return next(Default); 01009 01010 std::va_list ap; 01011 va_start(ap, P); 01012 for(unsigned i=1; i<No; i++) { 01013 char* Opt = va_arg(ap, char *); 01014 if( search(Opt) == true ) { 01015 va_end(ap); 01016 return next(Default); 01017 } 01018 } 01019 va_end(ap); 01020 return Default; 01021 }
| int GetPot::follow | ( | int | Default, | |
| unsigned | No, | |||
| const char * | Option, | |||
| ... | ||||
| ) | [inline] |
Definition at line 984 of file getpot.h.
References next(), and search().
00985 { 00986 if( No == 0 ) return Default; 00987 if( search(P) == true ) return next(Default); 00988 00989 std::va_list ap; 00990 va_start(ap, P); 00991 for(unsigned i=1; i<No; i++) { 00992 char* Opt = va_arg(ap, char *); 00993 if( search(Opt) == true ) { 00994 va_end(ap); 00995 return next(Default); 00996 } 00997 } 00998 va_end(ap); 00999 return Default; 01000 }
| const char * GetPot::follow | ( | const char * | Default, | |
| const char * | Option | |||
| ) | [inline] |
| double GetPot::follow | ( | double | Default, | |
| const char * | Option | |||
| ) | [inline] |
| int GetPot::follow | ( | int | Default, | |
| const char * | Option | |||
| ) | [inline] |
| const char * GetPot::get | ( | unsigned | Idx, | |
| const char * | Default | |||
| ) | const [inline] |
| double GetPot::get | ( | unsigned | Idx, | |
| double | Default | |||
| ) | const [inline] |
Definition at line 867 of file getpot.h.
References __convert_to_type(), and argv.
00868 { 00869 if( Idx >= argv.size() ) return Default; 00870 return __convert_to_type(argv[Idx], Default); 00871 }
| int GetPot::get | ( | unsigned | Idx, | |
| int | Default | |||
| ) | const [inline] |
Definition at line 858 of file getpot.h.
References __convert_to_type(), and argv.
00859 { 00860 if( Idx >= argv.size() ) return Default; 00861 return __convert_to_type(argv[Idx], Default); 00862 }
| std::vector< std::string > GetPot::get_section_names | ( | ) | const [inline] |
| std::vector< std::string > GetPot::get_variable_names | ( | ) | const [inline] |
Definition at line 1342 of file getpot.h.
References __get_remaining_string(), prefix, and variables.
01343 { 01344 std::vector<std::string> result; 01345 for(std::vector<GetPot::variable>::const_iterator it = variables.begin(); 01346 it != variables.end(); it++) { 01347 const std::string Tmp = __get_remaining_string((*it).name, prefix); 01348 if( Tmp != "" ) result.push_back(Tmp); 01349 } 01350 return result; 01351 }
| bool GetPot::have_variable | ( | const char * | VarName | ) | const [inline] |
Definition at line 1213 of file getpot.h.
References __find_variable().
01214 { 01215 const variable* sv = __find_variable(VarName); 01216 if (sv == 0) return false; 01217 return true; 01218 }
| void GetPot::init_multiple_occurrence | ( | ) | [inline] |
Definition at line 842 of file getpot.h.
References disable_loop(), and reset_cursor().
00843 { disable_loop(); reset_cursor(); }
| std::string GetPot::next | ( | const std::string & | Default | ) | [inline] |
Definition at line 936 of file getpot.h.
References __get_remaining_string(), argv, cursor, prefix, and search_failed_f.
00937 { 00938 if( search_failed_f ) return Default; 00939 cursor++; 00940 00941 if( cursor >= argv.size() ) 00942 { cursor = argv.size(); return Default; } 00943 00944 const std::string Remain = __get_remaining_string(argv[cursor], prefix); 00945 00946 return Remain != "" ? Remain : Default; 00947 }
| const char * GetPot::next | ( | const char * | Default | ) | [inline] |
Definition at line 920 of file getpot.h.
References __get_remaining_string(), argv, cursor, prefix, and search_failed_f.
00921 { 00922 if( search_failed_f ) return Default; 00923 cursor++; 00924 00925 if( cursor >= argv.size() ) 00926 { cursor = argv.size(); return Default; } 00927 00928 const std::string Remain = __get_remaining_string(argv[cursor], prefix); 00929 00930 return Remain != "" ? Remain.c_str() : Default; 00931 }
| double GetPot::next | ( | double | Default | ) | [inline] |
Definition at line 904 of file getpot.h.
References __convert_to_type(), __get_remaining_string(), argv, cursor, prefix, and search_failed_f.
00905 { 00906 if( search_failed_f ) return Default; 00907 cursor++; 00908 00909 if( cursor >= argv.size() ) 00910 { cursor = argv.size(); return Default; } 00911 00912 std::string Remain = __get_remaining_string(argv[cursor], prefix); 00913 00914 return Remain != "" ? __convert_to_type(Remain, Default) : Default; 00915 }
| int GetPot::next | ( | int | Default | ) | [inline] |
Definition at line 889 of file getpot.h.
References __convert_to_type(), __get_remaining_string(), argv, cursor, prefix, and search_failed_f.
Referenced by follow().
00890 { 00891 if( search_failed_f ) return Default; 00892 cursor++; 00893 if( cursor >= argv.size() ) 00894 { cursor = argv.size(); return Default; } 00895 00896 const std::string Remain = __get_remaining_string(argv[cursor], prefix); 00897 00898 return Remain != "" ? __convert_to_type(Remain, Default) : Default; 00899 }
| const char * GetPot::next_nominus | ( | ) | [inline] |
Definition at line 1193 of file getpot.h.
References argv, idx_nominus, and nominus_cursor.
01194 { 01195 if( nominus_cursor < int(idx_nominus.size()) - 1 ) 01196 return argv[idx_nominus[++nominus_cursor]].c_str(); 01197 return 0; 01198 }
| unsigned GetPot::nominus_size | ( | ) | const [inline] |
Definition at line 159 of file getpot.h.
References idx_nominus.
00159 { return idx_nominus.size(); }
| std::vector< std::string > GetPot::nominus_vector | ( | ) | const [inline] |
Definition at line 1178 of file getpot.h.
References argv, and idx_nominus.
01180 { 01181 std::vector<std::string> nv; 01182 for(std::vector<unsigned>::const_iterator it = idx_nominus.begin(); 01183 it != idx_nominus.end(); 01184 it++) { 01185 nv.push_back(argv[*it]); 01186 } 01187 return nv; 01188 }
| std::string GetPot::operator() | ( | const char * | VarName, | |
| const std::string & | Default, | |||
| unsigned | Idx | |||
| ) | const [inline] |
Definition at line 1321 of file getpot.h.
References __find_variable(), and GetPot::variable::get_element().
01322 { 01323 const variable* sv = __find_variable(VarName); 01324 if( sv == 0 ) return Default; 01325 const std::string* element = sv->get_element(Idx); 01326 if( element == 0 ) return Default; 01327 return *element; 01328 }
| const char * GetPot::operator() | ( | const char * | VarName, | |
| const char * | Default, | |||
| unsigned | Idx | |||
| ) | const [inline] |
Definition at line 1311 of file getpot.h.
References __find_variable(), and GetPot::variable::get_element().
01312 { 01313 const variable* sv = __find_variable(VarName); 01314 if( sv == 0 ) return Default; 01315 const std::string* element = sv->get_element(Idx); 01316 if( element == 0 ) return Default; 01317 return element->c_str(); 01318 }
| double GetPot::operator() | ( | const char * | VarName, | |
| double | Default, | |||
| unsigned | Idx | |||
| ) | const [inline] |
Definition at line 1299 of file getpot.h.
References __convert_to_type(), __find_variable(), and GetPot::variable::get_element().
01300 { 01301 const variable* sv = __find_variable(VarName); 01302 if( sv == 0 ) return Default; 01303 const std::string* element = sv->get_element(Idx); 01304 if( element == 0 ) return Default; 01305 return __convert_to_type(*element, Default); 01306 }
| int GetPot::operator() | ( | const char * | VarName, | |
| int | Default, | |||
| unsigned | Idx | |||
| ) | const [inline] |
Definition at line 1287 of file getpot.h.
References __convert_to_type(), __find_variable(), and GetPot::variable::get_element().
01288 { 01289 const variable* sv = __find_variable(VarName); 01290 if( sv == 0 ) return Default; 01291 const std::string* element = sv->get_element(Idx); 01292 if( element == 0 ) return Default; 01293 return __convert_to_type(*element, Default); 01294 }
| std::string GetPot::operator() | ( | const char * | VarName, | |
| const std::string & | Default | |||
| ) | const [inline] |
Definition at line 1277 of file getpot.h.
References __find_variable(), and GetPot::variable::original.
01278 { 01279 const variable* sv = __find_variable(VarName); 01280 if( sv == 0 ) return Default; 01281 return sv->original; 01282 }
| const char * GetPot::operator() | ( | const char * | VarName, | |
| const char * | Default | |||
| ) | const [inline] |
Definition at line 1267 of file getpot.h.
References __find_variable(), and GetPot::variable::original.
01268 { 01269 const variable* sv = __find_variable(VarName); 01270 if( sv == 0 ) return Default; 01271 return sv->original.c_str(); 01272 }
| long double GetPot::operator() | ( | const char * | VarName, | |
| long double | Default | |||
| ) | const [inline] |
Definition at line 1257 of file getpot.h.
References __convert_to_type(), __find_variable(), and GetPot::variable::original.
01258 { 01259 const variable* sv = __find_variable(VarName); 01260 if( sv == 0 ) return Default; 01261 return __convert_to_type(sv->original, Default); 01262 }
| double GetPot::operator() | ( | const char * | VarName, | |
| double | Default | |||
| ) | const [inline] |
Definition at line 1247 of file getpot.h.
References __convert_to_type(), __find_variable(), and GetPot::variable::original.
01248 { 01249 const variable* sv = __find_variable(VarName); 01250 if( sv == 0 ) return Default; 01251 return __convert_to_type(sv->original, Default); 01252 }
| unsigned int GetPot::operator() | ( | const char * | VarName, | |
| unsigned int | Default | |||
| ) | const [inline] |
Definition at line 1239 of file getpot.h.
References __convert_to_type(), __find_variable(), and GetPot::variable::original.
01240 { 01241 const variable* sv = __find_variable(VarName); 01242 if( sv == 0 ) return Default; 01243 return __convert_to_type(sv->original, Default); 01244 }
| int GetPot::operator() | ( | const char * | VarName, | |
| int | Default | |||
| ) | const [inline] |
Definition at line 1231 of file getpot.h.
References __convert_to_type(), __find_variable(), and GetPot::variable::original.
01232 { 01233 const variable* sv = __find_variable(VarName); 01234 if( sv == 0 ) return Default; 01235 return __convert_to_type(sv->original, Default); 01236 }
| bool GetPot::operator() | ( | const char * | VarName, | |
| bool | Default | |||
| ) | const [inline] |
Definition at line 1221 of file getpot.h.
References __convert_to_type(), __find_variable(), and GetPot::variable::original.
01222 { 01223 const variable* sv = __find_variable(VarName); 01224 if ( sv == 0 ) return Default; 01225 return __convert_to_type(sv->original, Default); 01226 }
Definition at line 405 of file getpot.h.
References argv, cursor, idx_nominus, nominus_cursor, search_failed_f, search_loop_f, and variables.
Referenced by GetPot().
00406 { 00407 if (&Other != this) { 00408 argv = Other.argv; 00409 variables = Other.variables; 00410 cursor = Other.cursor; 00411 nominus_cursor = Other.nominus_cursor; 00412 search_failed_f = Other.search_failed_f; 00413 idx_nominus = Other.idx_nominus; 00414 search_loop_f = Other.search_loop_f; 00415 } 00416 return *this; 00417 }
| const char * GetPot::operator[] | ( | unsigned | Idx | ) | const [inline] |
| bool GetPot::options_contain | ( | const char * | FlagList | ) | const [inline] |
Definition at line 1121 of file getpot.h.
References __check_flags(), __get_remaining_string(), argv, and prefix.
01122 { 01123 // go through all arguments that start with a '-' (but not '--') 01124 std::string str; 01125 for(std::vector<std::string>::const_iterator it = argv.begin(); 01126 it != argv.end(); 01127 it++) { 01128 str = __get_remaining_string(*it, prefix); 01129 01130 if( str.length() >= 2 && str[0] == '-' && str[1] != '-' ) 01131 if( __check_flags(str, FlagList) ) return true; 01132 } 01133 return false; 01134 }
| void GetPot::parse_command_line | ( | int | argc_, | |
| char ** | argv_ | |||
| ) | [inline] |
Definition at line 359 of file getpot.h.
References __basic_initialization(), and __parse_argument_vector().
Referenced by GetPot().
00360 { 00361 __basic_initialization(); 00362 00363 // -- make an internal copy of the argument list: 00364 std::vector<std::string> __argv; 00365 __argv.reserve (argc_); 00366 00367 for(int i=0; i<argc_; i++) { 00368 std::string tmp(argv_[i]); 00369 __argv.push_back(tmp); 00370 } 00371 __parse_argument_vector(__argv); 00372 }
| void GetPot::parse_input_file | ( | const char * | FileName | ) | [inline] |
Definition at line 391 of file getpot.h.
References __basic_initialization(), __parse_argument_vector(), and __read_in_file().
00392 { 00393 __basic_initialization(); 00394 00395 std::vector<std::string> __argv; 00396 __argv.push_back(FileName); 00397 std::vector<std::string> args = __read_in_file(FileName); 00398 __argv.insert(__argv.begin()+1, args.begin(), args.end()); 00399 __parse_argument_vector(__argv); 00400 }
| void GetPot::parse_input_file | ( | const std::string & | FileName | ) | [inline] |
Definition at line 377 of file getpot.h.
References __basic_initialization(), __parse_argument_vector(), and __read_in_file().
Referenced by GetPot().
00378 { 00379 __basic_initialization(); 00380 00381 std::vector<std::string> __argv; 00382 __argv.push_back(FileName); 00383 std::vector<std::string> args = __read_in_file(FileName.c_str()); 00384 __argv.insert(__argv.begin()+1, args.begin(), args.end()); 00385 __parse_argument_vector(__argv); 00386 }
| int GetPot::print | ( | ) | const [inline] |
Definition at line 1377 of file getpot.h.
References argv.
01378 { 01379 std::cout << "argc = " << argv.size() << std::endl; 01380 for(std::vector<std::string>::const_iterator it = argv.begin(); it != argv.end(); it++) 01381 std::cout << *it << std::endl; 01382 std::cout << std::endl; 01383 return 1; 01384 }
| void GetPot::reset_cursor | ( | ) | [inline] |
Definition at line 836 of file getpot.h.
References cursor, and search_failed_f.
Referenced by init_multiple_occurrence().
00837 { search_failed_f = false; cursor = 0; }
| void GetPot::reset_nominus_cursor | ( | ) | [inline] |
| bool GetPot::search | ( | unsigned | No, | |
| const char * | P, | |||
| ... | ||||
| ) | [inline] |
Definition at line 813 of file getpot.h.
References search().
00814 { 00815 if( No == 0 ) return false; 00816 00817 // search for the first argument 00818 if( search(P) == true ) return true; 00819 00820 // start interpreting variable argument list 00821 std::va_list ap; 00822 va_start(ap, P); 00823 for(unsigned i=1; i<No; i++) { 00824 char* Opt = va_arg(ap, char *); 00825 if( search(Opt) == true ) 00826 { va_end(ap); return true; } 00827 } 00828 va_end(ap); 00829 return false; 00830 }
| bool GetPot::search | ( | const std::string & | option | ) | [inline] |
| bool GetPot::search | ( | const char * | option | ) | [inline] |
Definition at line 784 of file getpot.h.
References argv, cursor, prefix, search_failed_f, and search_loop_f.
Referenced by follow(), and search().
00785 { 00786 unsigned OldCursor = cursor; 00787 const std::string SearchTerm = prefix + Option; 00788 00789 if( OldCursor >= argv.size() ) OldCursor = argv.size() - 1; 00790 search_failed_f = true; 00791 00792 // (*) first loop from cursor position until end 00793 unsigned c = cursor; 00794 for(; c < argv.size(); c++) { 00795 if( argv[c] == SearchTerm ) 00796 { cursor = c; search_failed_f = false; return true; } 00797 } 00798 if( ! search_loop_f ) return false; 00799 00800 // (*) second loop from 0 to old cursor position 00801 for(c = 0; c < OldCursor; c++) { 00802 if( argv[c] == SearchTerm ) 00803 { cursor = c; search_failed_f = false; return true; } 00804 } 00805 // in case nothing is found the cursor stays where it was 00806 return false; 00807 }
| bool GetPot::search_failed | ( | ) | const [inline] |
Definition at line 112 of file getpot.h.
References search_failed_f.
00112 { return search_failed_f; }
| void GetPot::set_prefix | ( | const std::string & | Prefix | ) | [inline] |
| void GetPot::set_prefix | ( | const char * | Prefix | ) | [inline] |
| unsigned GetPot::size | ( | ) | const [inline] |
Definition at line 885 of file getpot.h.
References argv.
Referenced by __DBE_expand().
00886 { return argv.size(); }
| std::vector< std::string > GetPot::unidentified_arguments | ( | unsigned | Number, | |
| const char * | Known, | |||
| ... | ||||
| ) | const [inline] |
Definition at line 1809 of file getpot.h.
References unidentified_arguments().
01811 { 01812 std::vector<std::string> known_arguments; 01813 01814 // (1) create a vector of known arguments 01815 if( Number == 0 ) return std::vector<std::string>(); 01816 01817 std::va_list ap; 01818 va_start(ap, KnownArgument1); 01819 known_arguments.push_back(std::string(KnownArgument1)); 01820 for(unsigned i=1; i<Number; i++) 01821 known_arguments.push_back(std::string(va_arg(ap, char *))); 01822 va_end(ap); 01823 01824 return unidentified_arguments(known_arguments); 01825 }
| std::vector< std::string > GetPot::unidentified_arguments | ( | const std::vector< std::string > & | Knowns | ) | const [inline] |
Definition at line 1972 of file getpot.h.
References __get_remaining_string(), __search_string_vector(), argv, and prefix.
Referenced by unidentified_arguments().
01973 { 01974 std::vector<std::string> ufos; 01975 std::vector<std::string>::const_iterator it = argv.begin(); 01976 it++; // forget about argv[0] (application or filename) 01977 for(; it != argv.end(); it++) { 01978 // -- argument belongs to prefixed section ? 01979 const std::string arg = __get_remaining_string(*it, prefix); 01980 if( arg == "" ) continue; 01981 01982 // -- check if in list 01983 if( __search_string_vector(Knowns, arg) == false) 01984 ufos.push_back(*it); 01985 } 01986 return ufos; 01987 }
| std::string GetPot::unidentified_flags | ( | const char * | Known, | |
| int | ArgumentNumber = -1 | |||
| ) | const [inline] |
Definition at line 1915 of file getpot.h.
References __get_remaining_string(), argv, and prefix.
01916 : 01917 // ArgumentNumber >= 0 check specific argument 01918 // ArgumentNumber == -1 check all options starting with one '-' 01919 // for flags 01920 { 01921 std::string ufos; 01922 std::vector<std::string> known_arguments; 01923 std::string KFL(KnownFlagList); 01924 01925 // (2) iteration over '-' arguments (options) 01926 if( ArgumentNumber == -1 ) { 01927 std::vector<std::string>::const_iterator it = argv.begin(); 01928 it++; // forget about argv[0] (application or filename) 01929 for(; it != argv.end(); it++) { 01930 // -- argument belongs to prefixed section ? 01931 const std::string arg = __get_remaining_string(*it, prefix); 01932 if( arg == "" ) continue; 01933 01934 // -- does arguments start with '-' (but not '--') 01935 if ( arg.length() < 2 ) continue; 01936 else if( arg[0] != '-' ) continue; 01937 else if( arg[1] == '-' ) continue; 01938 01939 // -- check out if flags inside option are contained in KnownFlagList 01940 const char* p=arg.c_str(); 01941 p++; // skip starting minus 01942 for(; *p != '\0' ; p++) 01943 if( KFL.find(*p) == std::string::npos ) ufos += *p; 01944 } 01945 } 01946 // (1) check specific argument 01947 else { 01948 // -- only check arguments that start with prefix 01949 int no_matches = 0; 01950 for(unsigned i=1; i<argv.size(); i++) { 01951 const std::string Remain = __get_remaining_string(argv[i], prefix); 01952 if( Remain != "") { 01953 no_matches++; 01954 if( no_matches == ArgumentNumber) { 01955 // -- the right argument number inside the section is found 01956 // => check it for flags 01957 const char* p = Remain.c_str(); 01958 p++; // skip starting minus 01959 for(; *p != '\0' ; p++) 01960 if( KFL.find(*p) == std::string::npos ) ufos += *p; 01961 return ufos; 01962 } 01963 } 01964 } 01965 } 01966 return ufos; 01967 }
| std::vector< std::string > GetPot::unidentified_nominuses | ( | unsigned | Number, | |
| const char * | Known, | |||
| ... | ||||
| ) | const [inline] |
Definition at line 1890 of file getpot.h.
References unidentified_nominuses().
01891 { 01892 std::vector<std::string> known_nominuses; 01893 01894 // create vector of known arguments 01895 if( Number == 0 ) return std::vector<std::string>(); 01896 01897 std::va_list ap; 01898 va_start(ap, Known); 01899 known_nominuses.push_back(std::string(Known)); 01900 for(unsigned i=1; i<Number; i++) { 01901 std::string tmp = std::string(va_arg(ap, char *)); 01902 if( tmp.length() == 0 ) continue; 01903 known_nominuses.push_back(tmp); 01904 } 01905 va_end(ap); 01906 01907 return unidentified_nominuses(known_nominuses); 01908 }
| std::vector< std::string > GetPot::unidentified_nominuses | ( | const std::vector< std::string > & | Knowns | ) | const [inline] |
Definition at line 2054 of file getpot.h.
References __get_remaining_string(), __search_string_vector(), argv, and prefix.
Referenced by unidentified_nominuses().
02055 { 02056 std::vector<std::string> ufos; 02057 02058 // (2) iterate over all arguments 02059 std::vector<std::string>::const_iterator it = argv.begin(); 02060 it++; // forget about argv[0] (application or filename) 02061 for(; it != argv.end(); it++) { 02062 // -- check if nominus part of prefix 02063 const std::string arg = __get_remaining_string(*it, prefix); 02064 if( arg == "" ) continue; 02065 02066 if( arg.length() < 1 ) continue; 02067 // option ? --> not a nomius 02068 if( arg[0] == '-' ) continue; 02069 // section ? --> not a real nominus 02070 if( arg[0] == '[' && arg[arg.length()-1] == ']' ) continue; 02071 // variable definition ? --> not a real nominus 02072 bool continue_f = false; 02073 for(unsigned i=0; i<arg.length() ; i++) 02074 if( arg[i] == '=' ) { continue_f = true; break; } 02075 if( continue_f ) continue; 02076 02077 // real nominuses are compared with the given list 02078 if( __search_string_vector(Knowns, arg) == false ) 02079 ufos.push_back(*it); 02080 } 02081 return ufos; 02082 }
| std::vector< std::string > GetPot::unidentified_options | ( | unsigned | Number, | |
| const char * | Known, | |||
| ... | ||||
| ) | const [inline] |
Definition at line 1829 of file getpot.h.
References unidentified_options().
01831 { 01832 std::vector<std::string> known_options; 01833 01834 // (1) create a vector of known arguments 01835 if( Number == 0 ) return std::vector<std::string>(); 01836 01837 std::va_list ap; 01838 va_start(ap, KnownOption1); 01839 known_options.push_back(std::string(KnownOption1)); 01840 for(unsigned i=1; i<Number; i++) 01841 known_options.push_back(std::string(va_arg(ap, char *))); 01842 va_end(ap); 01843 01844 return unidentified_options(known_options); 01845 }
| std::vector< std::string > GetPot::unidentified_options | ( | const std::vector< std::string > & | Knowns | ) | const [inline] |
Definition at line 1992 of file getpot.h.
References __get_remaining_string(), __search_string_vector(), argv, and prefix.
Referenced by unidentified_options().
01993 { 01994 std::vector<std::string> ufos; 01995 std::vector<std::string>::const_iterator it = argv.begin(); 01996 it++; // forget about argv[0] (application or filename) 01997 for(; it != argv.end(); it++) { 01998 // -- argument belongs to prefixed section ? 01999 const std::string arg = __get_remaining_string(*it, prefix); 02000 if( arg == "" ) continue; 02001 02002 // is argument really an option (starting with '-') ? 02003 if( arg.length() < 1 || arg[0] != '-' ) continue; 02004 02005 if( __search_string_vector(Knowns, arg) == false) 02006 ufos.push_back(*it); 02007 } 02008 02009 return ufos; 02010 }
| std::vector< std::string > GetPot::unidentified_sections | ( | unsigned | Number, | |
| const char * | Known, | |||
| ... | ||||
| ) | const [inline] |
Definition at line 1867 of file getpot.h.
References unidentified_sections().
01869 { 01870 std::vector<std::string> known_sections; 01871 01872 // (1) create a vector of known arguments 01873 if( Number == 0 ) return std::vector<std::string>(); 01874 01875 std::va_list ap; 01876 va_start(ap, KnownSection1); 01877 known_sections.push_back(std::string(KnownSection1)); 01878 for(unsigned i=1; i<Number; i++) { 01879 std::string tmp = std::string(va_arg(ap, char *)); 01880 if( tmp.length() == 0 ) continue; 01881 if( tmp[tmp.length()-1] != '/' ) tmp += '/'; 01882 known_sections.push_back(tmp); 01883 } 01884 va_end(ap); 01885 01886 return unidentified_sections(known_sections); 01887 }
| std::vector< std::string > GetPot::unidentified_sections | ( | const std::vector< std::string > & | Knowns | ) | const [inline] |
Definition at line 2034 of file getpot.h.
References __get_remaining_string(), __search_string_vector(), prefix, and section_list.
Referenced by unidentified_sections().
02035 { 02036 std::vector<std::string> ufos; 02037 02038 victorate(std::string, section_list, it) { 02039 // -- check if section conform to prefix 02040 const std::string sec_name = __get_remaining_string(*it, prefix); 02041 if( sec_name == "" ) continue; 02042 02043 // -- check if section is known 02044 if( __search_string_vector(Knowns, sec_name) == false ) 02045 ufos.push_back(*it); 02046 } 02047 02048 return ufos; 02049 }
| std::vector< std::string > GetPot::unidentified_variables | ( | unsigned | Number, | |
| const char * | Known, | |||
| ... | ||||
| ) | const [inline] |
Definition at line 1848 of file getpot.h.
References unidentified_variables().
01850 { 01851 std::vector<std::string> known_variables; 01852 01853 // create vector of known arguments 01854 if( Number == 0 ) return std::vector<std::string>(); 01855 01856 std::va_list ap; 01857 va_start(ap, KnownVariable1); 01858 known_variables.push_back(std::string(KnownVariable1)); 01859 for(unsigned i=1; i<Number; i++) 01860 known_variables.push_back(std::string(va_arg(ap, char *))); 01861 va_end(ap); 01862 01863 return unidentified_variables(known_variables); 01864 }
| std::vector< std::string > GetPot::unidentified_variables | ( | const std::vector< std::string > & | Knowns | ) | const [inline] |
Definition at line 2015 of file getpot.h.
References __get_remaining_string(), __search_string_vector(), prefix, and variables.
Referenced by unidentified_variables().
02016 { 02017 std::vector<std::string> ufos; 02018 02019 victorate(GetPot::variable, variables, it) { 02020 // -- check if variable has specific prefix 02021 const std::string var_name = __get_remaining_string((*it).name, prefix); 02022 if( var_name == "" ) continue; 02023 02024 // -- check if variable is known 02025 if( __search_string_vector(Knowns, var_name) == false) 02026 ufos.push_back((*it).name); 02027 } 02028 return ufos; 02029 }
| unsigned GetPot::vector_variable_size | ( | const char * | VarName | ) | const [inline] |
Definition at line 1332 of file getpot.h.
References __find_variable(), and GetPot::variable::value.
01333 { 01334 const variable* sv = __find_variable(VarName); 01335 if( sv == 0 ) return 0; 01336 return sv->value.size(); 01337 }
Member Data Documentation
std::vector<std::string> GetPot::argv [private] |
Definition at line 214 of file getpot.h.
Referenced by __match_starting_string(), __parse_argument_vector(), argument_contains(), direct_follow(), get(), next(), next_nominus(), nominus_vector(), operator=(), operator[](), options_contain(), print(), search(), size(), unidentified_arguments(), unidentified_flags(), unidentified_nominuses(), and unidentified_options().
unsigned GetPot::cursor [private] |
Definition at line 215 of file getpot.h.
Referenced by __basic_initialization(), __match_starting_string(), direct_follow(), next(), operator=(), reset_cursor(), and search().
std::vector<unsigned> GetPot::idx_nominus [private] |
Definition at line 223 of file getpot.h.
Referenced by __parse_argument_vector(), next_nominus(), nominus_size(), nominus_vector(), and operator=().
int GetPot::nominus_cursor [private] |
Definition at line 222 of file getpot.h.
Referenced by __basic_initialization(), next_nominus(), operator=(), and reset_nominus_cursor().
std::string GetPot::prefix [private] |
Definition at line 210 of file getpot.h.
Referenced by __basic_initialization(), __DBE_get_variable(), __find_variable(), argument_contains(), get_variable_names(), next(), options_contain(), search(), set_prefix(), unidentified_arguments(), unidentified_flags(), unidentified_nominuses(), unidentified_options(), unidentified_sections(), and unidentified_variables().
bool GetPot::search_failed_f [private] |
Definition at line 218 of file getpot.h.
Referenced by __basic_initialization(), __match_starting_string(), direct_follow(), next(), operator=(), reset_cursor(), search(), and search_failed().
bool GetPot::search_loop_f [private] |
Definition at line 216 of file getpot.h.
Referenced by __basic_initialization(), __match_starting_string(), disable_loop(), enable_loop(), operator=(), and search().
std::string GetPot::section [private] |
Definition at line 211 of file getpot.h.
Referenced by __basic_initialization(), __DBE_get_variable(), and __parse_argument_vector().
std::vector<std::string> GetPot::section_list [private] |
Definition at line 212 of file getpot.h.
Referenced by __parse_argument_vector(), get_section_names(), and unidentified_sections().
std::vector<variable> GetPot::variables [private] |
Definition at line 227 of file getpot.h.
Referenced by __find_variable(), __parse_argument_vector(), get_variable_names(), operator=(), and unidentified_variables().
The documentation for this class was generated from the following file: