74 #ifndef __include_guard_GETPOT_H__ 75 #define __include_guard_GETPOT_H__ 77 #if defined(WIN32) || defined(SOLARIS_RAW) || (__GNUC__
== 2
) || defined(__HP_aCC) 78 #define strtok_r(a, b, c) strtok(a, b) 105 #define victorate(TYPE, VARIABLE, ITERATOR) 106 std::vector<TYPE>::const_iterator ITERATOR = (VARIABLE).begin(); 107 for(; (ITERATOR) != (VARIABLE).end(); (ITERATOR)++) 118 inline GetPot (
const int argc_,
char** argv_,
119 const char* FieldSeparator = 0x0);
120 inline GetPot (
const char* FileName,
121 const char* CommentStart = 0x0,
const char* CommentEnd = 0x0,
122 const char* FieldSeparator = 0x0);
125 template <
typename STRING>
126 inline GetPot (
const STRING& FileName,
127 const char* CommentStart = 0x0,
const char* CommentEnd = 0x0,
128 const char* FieldSeparator = 0x0);
153 inline const std::string
operator[] (
unsigned Idx)
const;
154 inline int get (
unsigned Idx,
int Default)
const;
155 inline double get (
unsigned Idx,
const double& Default)
const;
156 inline const std::string
get (
unsigned Idx,
const char* Default)
const;
157 inline unsigned size()
const;
167 inline bool operator() (
const char* VarName,
bool Default)
const;
170 inline int operator() (
const char* VarName,
int Default)
const;
171 inline double operator() (
const char* VarName,
const double& Default)
const;
172 inline const std::string
operator() (
const char* VarName,
const char* Default)
const;
176 inline bool operator() (
const char* VarName,
bool Default,
bool& found)
const;
177 inline int operator() (
const char* VarName,
int Default,
bool& found)
const;
178 inline double operator() (
const char* VarName,
const double& Default,
bool& found)
const;
179 inline const std::string
operator() (
const char* VarName,
const char* Default,
bool& found)
const;
183 inline bool operator() (
const char* VarName,
bool Default,
unsigned Idx)
const;
186 inline int operator() (
const char* VarName,
int Default,
unsigned Idx)
const;
187 inline double operator() (
const char* VarName,
const double& Default,
unsigned Idx)
const;
188 inline const std::string
operator() (
const char* VarName,
const char* Default,
unsigned Idx)
const;
193 inline void set (
const char* VarName,
const char* Value,
const bool Requested =
true);
194 inline void set (
const char* VarName,
const double& Value,
const bool Requested =
true);
195 inline void set (
const char* VarName,
const int Value,
const bool Requested =
true);
209 prefix = std::string (Prefix);
231 inline bool search (
const char* option);
232 inline bool search (
unsigned No,
const char* P, ...);
234 inline int next (
int Default);
235 inline double next (
const double& Default);
236 inline const std::string
next (
const char* Default);
238 inline int follow (
int Default,
const char* Option);
239 inline double follow (
const double& Default,
const char* Option);
240 inline const std::string
follow (
const char* Default,
const char* Option);
242 inline int follow (
int Default,
unsigned No,
const char* Option, ...);
243 inline double follow (
const double& Default,
unsigned No,
const char* Option, ...);
244 inline const std::string
follow (
const char* Default,
unsigned No,
const char* Option, ...);
251 inline double direct_follow (
const double& Default,
const char* Option);
252 inline const std::string
direct_follow (
const char* Default,
const char* Option);
262 return static_cast<
unsigned int> (idx_nominus.size() );
276 int ArgumentNumber )
const;
291 inline int print()
const;
304 variable (
const char* Name,
const char* Value,
const char* FieldSeparator);
308 void take (
const char* Value,
const char* FieldSeparator);
312 const std::string*
get_element (
unsigned Idx)
const;
366 inline void __set_variable (
const char* VarName,
const char* Value);
380 inline bool __check_flags (
const std::string& Str,
const char* FlagList)
const;
388 inline double __convert_to_type (
const std::string& String,
double Default)
const;
391 const std::string& Start)
const;
394 const std::string& Str)
const;
406 inline const std::string
__get_string (std::istream& istr);
423 char* tmp =
new char[128];
425 snprintf (tmp, (
int)
sizeof (
char) * 128,
"%e", Value);
427 _snprintf (tmp,
sizeof (
char) * 128,
"%e", Value);
429 std::string result (tmp);
437 char* tmp =
new char[128];
439 snprintf (tmp, (
int)
sizeof (
char) * 128,
"%i", Value);
441 _snprintf (tmp,
sizeof (
char) * 128,
"%i", Value);
443 std::string result (tmp);
453 const char* Start = FullPath.c_str();
455 for (
char* p = (
char*) Start; *p ; p++)
460 const std::string Section = Start;
462 result.push_back (Section);
489 _comment_start = std::string (
"#");
490 _comment_end = std::string (
"\n");
493 _field_separator =
" \t\n";
502 _apriori_argv.push_back (std::string (
"Empty") );
508 const char* FieldSeparator )
518 if ( FieldSeparator )
520 _field_separator = std::string (FieldSeparator);
529 _apriori_argv.push_back (std::string (argv_[0]) );
531 for (; i < argc_; ++i)
533 std::string tmp (argv_[i]);
534 _apriori_argv.push_back (tmp);
542 const char* CommentStart ,
const char* CommentEnd ,
543 const char* FieldSeparator)
550 _comment_start = std::string (CommentStart);
554 _comment_end = std::string (CommentEnd);
556 if ( FieldSeparator )
558 _field_separator = FieldSeparator;
564 _apriori_argv.push_back (std::string (FileName) );
567 _apriori_argv.insert (_apriori_argv.begin() + 1, args.begin(), args.end() );
572 template <
typename STRING>
575 const char* CommentStart ,
const char* CommentEnd ,
576 const char* FieldSeparator)
583 _comment_start = std::string (CommentStart);
587 _comment_end = std::string (CommentEnd);
589 if ( FieldSeparator )
591 _field_separator = FieldSeparator;
597 _apriori_argv.push_back (std::string (FileName) );
600 _apriori_argv.insert (_apriori_argv.begin() + 1, args.begin(), args.end() );
615 victorate (
char*, __internal_string_container, it)
630 variables = That.variables;
637 idx_nominus = That.idx_nominus;
649 __argv.push_back ( FileNameList[ 0 ] );
650 for ( STRING_VECTOR::const_iterator s = FileNameList.begin(); s != FileNameList.end(); ++s )
652 STRING_VECTOR args = __read_in_file ( s->c_str() );
653 __argv.insert ( __argv.end(), args.begin(), args.end() );
669 __tmp.erase (__tmp.begin() );
677 _requested_arguments.erase (_requested_arguments.begin(), _requested_arguments.end() );
678 _requested_variables.erase (_requested_variables.begin(), _requested_variables.end() );
679 _requested_sections.erase (_requested_sections.begin(), _requested_sections.end() );
685 if ( ARGV.size() == 0 )
695 STRING_VECTOR::const_iterator it = ARGV.begin();
701 argv.push_back (*it);
706 for (; it != ARGV.end(); ++it, ++i)
708 std::string arg = *it;
710 if ( arg.length() == 0 )
716 if ( arg.length() > 1 && arg[0] ==
'[' && arg[arg.length() - 1] ==
']' )
720 if ( __request_recording_f )
722 _requested_arguments.push_back (arg);
725 const std::string Name = __DBE_expand_string (arg.substr (1, arg.length() - 2) );
726 section = __process_section_label (Name, section_stack);
728 if ( find (section_list.begin(), section_list.end(), section) == section_list.end() )
729 if ( section.length() != 0 )
731 section_list.push_back (section);
733 argv.push_back (arg);
737 arg = section + __DBE_expand_string (arg);
738 argv.push_back (arg);
744 idx_nominus.push_back (
unsigned (i) );
748 const char* p = arg.c_str();
759 if ( __request_recording_f )
761 _requested_arguments.push_back (arg);
767 char* o = (
char*) p++;
772 const bool tmp = __request_recording_f;
773 __request_recording_f =
false;
774 __set_variable (arg.c_str(), p);
775 __request_recording_f = tmp;
787 std::ifstream i (FileName);
793 return __read_in_stream (i);
804 if ( Token.length() == 0 || Token[0] == EOF)
808 brute_tokens.push_back (Token);
821 while ( i1 < brute_tokens.size() )
823 const std::string& SRef = brute_tokens[i1];
827 if ( i2 < brute_tokens.size() && brute_tokens[i2] ==
"=" )
829 if ( i3 >= brute_tokens.size() )
831 arglist.push_back (brute_tokens[i1] + brute_tokens[i2]);
835 arglist.push_back (brute_tokens[i1] + brute_tokens[i2] + brute_tokens[i3]);
844 arglist.push_back (SRef);
857 int tmp = istr.get();
861 while ( isspace (tmp) )
872 for (; i < _comment_start.length() ; ++i)
874 if ( tmp != _comment_start[i] )
899 unsigned match_no = 0;
909 if ( tmp == _comment_end[match_no] )
912 if ( match_no == _comment_end.length() )
931 inline const std::string
944 || ( (tmp ==
' ' || tmp ==
'\t' || tmp ==
'\n') && last_letter !=
'\\') )
948 else if ( tmp ==
'\'' && last_letter !=
'\\' )
954 else if ( tmp ==
'{' && last_letter ==
'$')
959 else if ( tmp ==
'$' && last_letter ==
'\\')
965 else if ( tmp ==
'\\' && last_letter !=
'\\')
974 inline const std::string
990 else if ( tmp ==
'\'' && last_letter !=
'\\')
994 else if ( tmp ==
'\\' && last_letter !=
'\\')
1004 inline const std::string
1008 std::string str =
"";
1010 int last_letter = 0;
1020 else if ( tmp ==
'{' && last_letter ==
'$')
1024 else if ( tmp ==
'}')
1032 else if ( tmp ==
'\\' && last_letter !=
'\\')
1046 std::string sname = Section;
1048 if ( sname.length() >= 2 && sname.substr (0, 2) ==
"./" )
1050 sname = sname.substr (2);
1053 else if ( sname.length() >= 3 && sname.substr (0, 3) ==
"../" )
1057 if ( section_stack.end() != section_stack.begin() )
1059 section_stack.pop_back();
1061 sname = sname.substr (3);
1063 while ( sname.substr (0, 3) ==
"../" );
1068 section_stack.erase (section_stack.begin(), section_stack.end() );
1076 while ( i < sname.length() )
1078 if ( sname[i] ==
'/' )
1080 section_stack.push_back (sname.substr (0, i) );
1081 if ( i + 1 < sname.length() )
1083 sname = sname.substr (i + 1);
1092 section_stack.push_back (sname);
1094 std::string section =
"";
1095 if ( section_stack.size() != 0 )
1097 victorate (std::string, section_stack, it)
1098 section += *it +
"/";
1108 if (String.compare (
"false" ) == 0)
1112 if (String.compare (
"true" ) == 0)
1128 if ( sscanf (String.c_str(),
"%lf", &tmp) != 1 )
1148 inline const std::string
1159 if ( String.find (Start) == 0 )
1161 return String.substr (Start.length() );
1173 unsigned OldCursor =
cursor;
1174 const std::string SearchTerm = prefix + Option;
1177 __record_argument_request (SearchTerm);
1179 if ( OldCursor >= argv.size() )
1181 OldCursor =
static_cast<
unsigned int> (argv.size() ) - 1;
1187 for (; c < argv.size(); c++)
1189 if ( argv[c] == SearchTerm )
1192 search_failed_f =
false;
1202 for (c = 1; c < OldCursor; c++)
1204 if ( argv[c] == SearchTerm )
1237 char* Opt = va_arg (ap,
char*);
1252 char* Opt = va_arg (ap,
char*);
1254 __record_argument_request (Opt);
1282 inline const std::string
1285 return idx < argv.size() ? argv[idx] :
"";
1291 if ( Idx >= argv.size() )
1295 return __convert_to_type (argv[Idx], Default);
1301 if ( Idx >= argv.size() )
1305 return __convert_to_type (argv[Idx], Default);
1308 inline const std::string
1311 if ( Idx >= argv.size() )
1324 return static_cast<
unsigned int> (argv.size() );
1337 if ( cursor >= argv.size() )
1339 cursor =
static_cast<
unsigned int> (argv.size() );
1344 __record_argument_request (argv[cursor]);
1346 const std::string Remain = __get_remaining_string (argv[cursor], prefix);
1348 return Remain !=
"" ? __convert_to_type (Remain, Default) : Default;
1360 if ( cursor >= argv.size() )
1362 cursor =
static_cast<
unsigned int> (argv.size() );
1367 __record_argument_request (argv[cursor]);
1369 std::string Remain = __get_remaining_string (argv[cursor], prefix);
1371 return Remain !=
"" ? __convert_to_type (Remain, Default) : Default;
1374 inline const std::string
1377 using namespace std;
1385 if ( cursor >= argv.size() )
1387 cursor =
static_cast<
unsigned int> (argv.size() );
1392 __record_argument_request (argv[cursor]);
1394 const std::string Remain = __get_remaining_string (argv[cursor], prefix);
1406 char* result =
new char[Remain.length() + 1];
1407 strncpy (result, Remain.c_str(), Remain.length() + 1);
1410 __internal_string_container.push_back (result);
1439 inline const std::string
1470 char* Opt = va_arg (ap,
char*);
1496 for (
unsigned i = 1; i < No; ++i)
1498 char* Opt = va_arg (ap,
char*);
1509 inline const std::string
1527 char* Opt = va_arg (ap,
char*);
1546 std::vector<std::string> result_list;
1551 while ( 1 + 1 == 2 )
1554 if ( cursor >= argv.size() )
1556 cursor = argv.size() - 1;
1559 if ( argv[cursor].length() >= 1 )
1561 if ( argv[cursor][0] ==
'-' )
1566 __record_argument_request (argv[cursor]);
1568 result_list.push_back (argv[cursor]);
1577 std::vector<std::string> result_list;
1587 for (
unsigned i = 0; i < No; ++i)
1589 char* Option = va_arg (ap,
char*);
1590 std::vector<std::string> tmp = nominus_followers (Option);
1591 result_list.insert (result_list.end(), tmp.begin(), tmp.end() );
1614 if ( FollowStr == 0x0 )
1620 __record_argument_request (std::string (Option) + FollowStr);
1622 if ( ++cursor >=
static_cast<
unsigned int> (argv.size() ) )
1624 cursor =
static_cast<
unsigned int> (argv.size() );
1626 return __convert_to_type (FollowStr, Default);
1633 if ( FollowStr == 0 )
1639 __record_argument_request (std::string (Option) + FollowStr);
1641 if ( ++cursor >=
static_cast<
unsigned int> (argv.size() ) )
1643 cursor =
static_cast<
unsigned int> (argv.size() );
1645 return __convert_to_type (FollowStr, Default);
1648 inline const std::string
1656 if ( FollowStr == 0 )
1664 __record_argument_request (std::string (Option) + FollowStr);
1667 if ( ++cursor >=
static_cast<
unsigned int> (argv.size() ) )
1669 cursor =
static_cast<
unsigned int> (argv.size() );
1671 return std::string (FollowStr);
1677 std::vector<std::string> result;
1678 const unsigned N =
static_cast<
unsigned int> (strlen (StartString) );
1680 std::vector<std::string>::iterator it = argv.begin();
1683 while ( it != argv.end() )
1687 if ( strncmp (StartString, (*it).c_str(), N) != 0)
1695 result.push_back ( (*it).substr (N) );
1698 std::vector<
unsigned>::iterator nit = idx_nominus.begin();
1699 for (; nit != idx_nominus.end(); ++nit)
1703 idx_nominus.erase (nit);
1704 for (; nit != idx_nominus.end(); ++nit)
1733 std::vector<
int> result;
1734 const unsigned N =
static_cast<
unsigned int> (strlen (StartString) );
1736 std::vector<std::string>::iterator it = argv.begin();
1739 while ( it != argv.end() )
1743 if ( strncmp (StartString, (*it).c_str(), N) != 0)
1751 result.push_back (__convert_to_type ( (*it).substr (N), Default) );
1754 std::vector<
unsigned>::iterator nit = idx_nominus.begin();
1755 for (; nit != idx_nominus.end(); ++nit)
1759 idx_nominus.erase (nit);
1760 for (; nit != idx_nominus.end(); ++nit)
1790 std::vector<
double> result;
1791 const unsigned N =
static_cast<
unsigned int> (strlen (StartString) );
1793 std::vector<std::string>::iterator it = argv.begin();
1795 while ( it != argv.end() )
1799 if ( strncmp (StartString, (*it).c_str(), N) != 0)
1807 result.push_back (__convert_to_type ( (*it).substr (N), Default) );
1810 std::vector<
unsigned>::iterator nit = idx_nominus.begin();
1811 for (; nit != idx_nominus.end(); ++nit)
1815 idx_nominus.erase (nit);
1816 for (; nit != idx_nominus.end(); ++nit)
1852 const unsigned N =
static_cast<
unsigned int> (strlen (StartString) );
1853 unsigned OldCursor =
cursor;
1855 if ( OldCursor >=
static_cast<
unsigned int> (argv.size() ) )
1857 OldCursor =
static_cast<
unsigned int> (argv.size() ) - 1;
1863 for (; c < argv.size(); c++)
1865 if ( strncmp (StartString, argv[c].c_str(), N) == 0)
1868 search_failed_f =
false;
1869 return & (argv[c].c_str() [N]);
1879 for (c = 1; c < OldCursor; c++)
1881 if ( strncmp (StartString, argv[c].c_str(), N) == 0)
1885 return & (argv[c].c_str() [N]);
1900 STRING_VECTOR::const_iterator it = argv.begin();
1901 for (; it != argv.end(); ++it)
1903 str = __get_remaining_string (*it, prefix);
1905 if ( str.length() >= 2 && str[0] ==
'-' && str[1] !=
'-' )
1906 if ( __check_flags (str, FlagList) )
1917 if ( Idx >= argv.size() )
1924 ( (GetPot*)
this)->__record_argument_request (argv[Idx]);
1929 return __check_flags (argv[Idx], FlagList);
1935 unsigned no_matches = 0;
1937 for (; i < argv.size(); ++i)
1939 const std::string Remain = __get_remaining_string (argv[i], prefix);
1943 if ( no_matches == Idx)
1945 return __check_flags (Remain, FlagList);
1956 const char* p = FlagList;
1957 for (; *p !=
'\0' ; p++)
1958 if ( Str.find (*p) != std::string::npos )
1972 std::vector<
unsigned>::const_iterator it = idx_nominus.begin();
1973 for (; it != idx_nominus.end(); ++it)
1975 nv.push_back (argv[*it]);
1980 ( (GetPot*)
this)->__record_argument_request (argv[*it]);
1988 if ( nominus_cursor <
int (idx_nominus.size() ) - 1 )
1990 const std::string Tmp = argv[idx_nominus[++nominus_cursor]];
1999 return std::string (
"");
2044 inline const std::string
2100 inline const std::string
2170 inline const std::string
2196 _requested_arguments.push_back (Name);
2201 if ( find (_requested_sections.begin(), _requested_sections.end(), *it) == _requested_sections.end() )
2202 if ( section.length() != 0 )
2204 _requested_sections.push_back (*it);
2217 _requested_variables.push_back (Name);
2222 if ( find (_requested_sections.begin(), _requested_sections.end(), *it) == _requested_sections.end() )
2223 if ( section.length() != 0 )
2225 _requested_sections.push_back (*it);
2237 variables.push_back (variable (VarName, Value, _field_separator.c_str() ) );
2241 ( (GetPot::variable*) Var)->take (Value, _field_separator.c_str() );
2246 GetPot::
set (
const char* VarName,
const char* Value,
const bool Requested )
2248 const std::string Arg = prefix + std::string (VarName) + std::string (
"=") + std::string (Value);
2249 argv.push_back (Arg);
2261 GetPot::
set (
const char* VarName,
const double& Value,
const bool )
2263 __set_variable (VarName, __double2string (Value).c_str() );
2267 GetPot::
set (
const char* VarName,
const int Value,
const bool )
2269 __set_variable (VarName, __int2string (Value).c_str() );
2298 return static_cast<
unsigned int> (sv->value.size() );
2305 std::vector<GetPot::variable>::const_iterator it = variables.begin();
2306 for (; it != variables.end(); ++it)
2308 const std::string Tmp = __get_remaining_string ( (*it).name, prefix);
2311 result.push_back (Tmp);
2326 const std::string Name = prefix + VarName;
2329 ( (GetPot*)
this)->__record_variable_request (Name);
2331 std::vector<variable>::const_iterator it = variables.begin();
2332 for (; it != variables.end(); ++it)
2334 if ( (*it).name == Name )
2349 std::cout <<
"argc = " <<
static_cast<
unsigned int> (argv.size() ) << std::endl;
2350 STRING_VECTOR::const_iterator it = argv.begin();
2351 for (; it != argv.end(); ++it)
2353 std::cout << *it << std::endl;
2355 std::cout << std::endl;
2412 std::string new_string =
"";
2413 unsigned open_brackets = 0;
2416 for (; i < str.size(); ++i)
2418 if ( i < str.size() - 2 && str.substr (i, 2) ==
"${" )
2420 if ( open_brackets == 0 )
2426 else if ( str[i] ==
'}' && open_brackets > 0)
2429 if ( open_brackets == 0 )
2431 const std::string Replacement = __DBE_expand (str.substr (first, i - first) );
2432 new_string += Replacement;
2435 else if ( open_brackets == 0 )
2437 new_string += str[i];
2448 std::string str = str_;
2454 for (; i < str.size(); ++i)
2455 if ( ! isspace (str[i]) )
2461 unsigned open_brackets = 0;
2462 std::vector<
unsigned> start_idx;
2463 unsigned start_new_string = i;
2464 unsigned l =
static_cast<
unsigned int> (str.size() );
2469 const char letter = str[i];
2471 if ( isspace (letter) && open_brackets == 0)
2473 expr_list.push_back (str.substr (start_new_string, i - start_new_string) );
2474 bool no_breakout_f =
true;
2475 for (++i; i < l ; ++i)
2477 if ( ! isspace (str[i]) )
2479 no_breakout_f =
false;
2480 start_new_string = i;
2484 if ( no_breakout_f )
2487 if ( expr_list.size() < ExpectedNumber )
2489 const std::string pre_tmp (
"<< ${ }: missing arguments>>");
2490 STRING_VECTOR tmp (ExpectedNumber - expr_list.size(), pre_tmp);
2491 expr_list.insert (expr_list.end(), tmp.begin(), tmp.end() );
2498 if ( str.length() >= i + 2 && str.substr (i, 2) ==
"${" )
2501 start_idx.push_back (i + 2);
2503 else if ( letter ==
'}' && open_brackets > 0)
2505 int start = start_idx[start_idx.size() - 1];
2506 start_idx.pop_back();
2507 const std::string Replacement = __DBE_expand (str.substr (start, i - start) );
2508 if ( start - 3 < (
int) 0)
2510 str = Replacement + str.substr (i + 1);
2514 str = str.substr (0, start - 2) + Replacement + str.substr (i + 1);
2516 l =
static_cast<
unsigned int> (str.size() );
2517 i = start +
static_cast<
unsigned int> (Replacement.size() ) - 3;
2524 expr_list.push_back (str.substr (start_new_string, i - start_new_string) );
2526 if ( expr_list.size() < ExpectedNumber )
2528 const std::string pre_tmp (
"<< ${ }: missing arguments>>");
2529 STRING_VECTOR tmp (ExpectedNumber - expr_list.size(), pre_tmp);
2530 expr_list.insert (expr_list.end(), tmp.begin(), tmp.end() );
2537 GetPot::__DBE_get_variable (std::string VarName)
2540 std::string secure_Prefix =
prefix;
2544 const GetPot::
variable* var = __find_variable (VarName.c_str() );
2553 var = __find_variable (VarName.c_str() );
2563 char* tmp =
new char[VarName.length() + 25];
2565 snprintf (tmp, (
int)
sizeof (
char) * (VarName.length() + 25),
2567 _snprintf (tmp,
sizeof (
char) * (VarName.length() + 25),
2569 "<<${ } variable '%s' undefined>>", VarName.c_str() );
2571 ev.original = std::string (tmp);
2580 if ( expr[0] ==
':' )
2582 return expr.substr (1);
2586 else if ( expr[0] ==
'&' )
2588 const STRING_VECTOR A = __DBE_get_expr_list (expr.substr (1), 1);
2590 STRING_VECTOR::const_iterator it = A.begin();
2591 std::string result = *it++;
2592 for (; it != A.end(); ++it)
2601 else if ( expr.length() >= 3 && expr.substr (0, 3) ==
"<->" )
2604 std::string::size_type tmp = 0;
2605 const std::string::size_type L = A[1].length();
2606 while ( (tmp = A[0].find (A[1]) ) != std::string::npos )
2608 A[0].replace (tmp, L, A[2]);
2613 else if ( expr[0] ==
'+' )
2616 STRING_VECTOR::const_iterator it = A.begin();
2617 double result = __convert_to_type (*it++, 0.0);
2618 for (; it != A.end(); ++it)
2620 result += __convert_to_type (*it, 0.0);
2625 else if ( expr[0] ==
'-' )
2628 STRING_VECTOR::const_iterator it = A.begin();
2629 double result = __convert_to_type (*it++, 0.0);
2630 for (; it != A.end(); ++it)
2632 result -= __convert_to_type (*it, 0.0);
2637 else if ( expr[0] ==
'*' )
2640 STRING_VECTOR::const_iterator it = A.begin();
2641 double result = __convert_to_type (*it++, 0.0);
2642 for (; it != A.end(); ++it)
2644 result *= __convert_to_type (*it, 0.0);
2649 else if ( expr[0] ==
'/' )
2653 STRING_VECTOR::const_iterator it = A.begin();
2654 double result = __convert_to_type (*it++, 0.0);
2659 for (; it != A.end(); ++it)
2661 const double Q = __convert_to_type (*it, 0.0);
2672 else if ( expr[0] ==
'^' )
2675 STRING_VECTOR::const_iterator it = A.begin();
2676 double result = __convert_to_type (*it++, 0.0);
2677 for (; it != A.end(); ++it)
2679 result = std::pow (result, __convert_to_type (*it, 0.0) );
2685 else if ( expr.length() >= 2 &&
2686 ( expr.substr (0, 2) ==
"==" || expr.substr (0, 2) ==
">=" ||
2687 expr.substr (0, 2) ==
"<=" || expr[0] ==
'>' || expr[0] ==
'<') )
2691 enum { EQ, GEQ, LEQ, GT, LT };
2692 if ( expr.substr (0, 2) ==
"==" )
2696 else if ( expr.substr (0, 2) ==
">=" )
2700 else if ( expr.substr (0, 2) ==
"<=" )
2704 else if ( expr[0] ==
'>' )
2714 if ( op == GT || op == LT )
2716 a = __DBE_get_expr_list (expr.substr (1), 2);
2720 a = __DBE_get_expr_list (expr.substr (2), 2);
2723 std::string x_orig = a[0];
2727 STRING_VECTOR::const_iterator y_orig = a.begin();
2728 for (y_orig++; y_orig != a.end(); y_orig++)
2730 double y = __convert_to_type (*y_orig, 1e37);
2733 if ( x == 1e37 || y == 1e37 )
2736 if ( (op == EQ && x_orig == *y_orig) || (op == GEQ && x_orig >= *y_orig) ||
2737 (op == LEQ && x_orig <= *y_orig) || (op == GT && x_orig > *y_orig) ||
2738 (op == LT && x_orig < *y_orig) )
2740 return __int2string (i);
2746 if ( (op == EQ && x == y) || (op == GEQ && x >= y) ||
2747 (op == LEQ && x <= y) || (op == GT && x > y) ||
2748 (op == LT && x < y) )
2750 return __int2string (i);
2760 else if ( expr.length() >= 2 && expr.substr (0, 2) ==
"??" )
2763 double x = __convert_to_type (a[0], 1e37);
2765 if ( x == 1e37 || x < 0 || x >= a.size() - 1 )
2767 return a[a.size() - 1];
2771 return a[
int (x + 0.5)];
2774 else if ( expr[0] ==
'?' )
2777 if ( __convert_to_type (a[0], 0.0) == 1.0 )
2781 else if ( a.size() > 2 )
2787 else if ( expr[0] ==
'!' )
2789 const GetPot::
variable* Var = __DBE_get_variable (expr.substr (1) );
2791 if ( Var->name ==
"" )
2800 else if ( expr.length() >= 2 && expr.substr (0, 2) ==
"@:" )
2802 const STRING_VECTOR A = __DBE_get_expr_list (expr.substr (2), 2);
2803 double x = __convert_to_type (A[1], 1e37);
2806 if ( x == 1e37 || x < 0 || x >= A[0].size() - 1)
2808 return "<<1st index out of range>>";
2813 double y = __convert_to_type (A[2], 1e37);
2814 if ( y != 1e37 && y > 0 && y <= A[0].size() - 1 && y > x )
2816 return A[0].substr (
int (x + 0.5),
int (y + 1.5) -
int (x + 0.5) );
2820 return A[0].substr (
int (x + 0.5) );
2822 return "<<2nd index out of range>>";
2826 char* tmp =
new char[2];
2827 tmp[0] = A[0][
int (x + 0.5)];
2829 std::string result (tmp);
2835 else if ( expr[0] ==
'@' )
2840 if ( Var->name ==
"" )
2847 double x = __convert_to_type (A[1], 1e37);
2850 if (x == 1e37 || x < 0 || x >= Var->value.size() )
2852 return "<<1st index out of range>>";
2857 double y = __convert_to_type (A[2], 1e37);
2858 int begin =
int (x + 0.5);
2860 if ( y != 1e37 && y > 0 && y <= Var->value.size() && y > x)
2862 end =
int (y + 1.5);
2866 end =
static_cast<
unsigned int> (Var->value.size() );
2870 return "<<2nd index out of range>>";
2875 for (; i < end; ++i)
2877 result += std::string (
" ") + * (Var->get_element (i) );
2892 if ( B->name ==
"" )
2921 const char* KnownArgument1, ...)
const 2932 va_start (ap, KnownArgument1);
2933 known_arguments.push_back (std::string (KnownArgument1) );
2935 for (; i < Number; ++i)
2937 known_arguments.push_back (std::string (va_arg (ap,
char*) ) );
2954 STRING_VECTOR::const_iterator it = argv.begin();
2956 for (; it != argv.end(); ++it)
2959 const std::string arg = __get_remaining_string (*it, prefix);
2966 if ( __search_string_vector (Knowns, arg) ==
false)
2968 ufos.push_back (*it);
2976 const char* KnownOption1, ...)
const 2987 va_start (ap, KnownOption1);
2988 known_options.push_back (std::string (KnownOption1) );
2990 for (; i < Number; ++i)
2992 known_options.push_back (std::string (va_arg (ap,
char*) ) );
3009 victorate (std::string, _requested_arguments, it)
3011 const std::string arg = *it;
3012 if ( arg.length() == 0 )
3016 if ( arg[0] ==
'-' )
3018 option_list.push_back (arg);
3028 STRING_VECTOR::const_iterator it = argv.begin();
3030 for (; it != argv.end(); ++it)
3033 const std::string arg = __get_remaining_string (*it, prefix);
3040 if ( arg.length() < 1 || arg[0] !=
'-' )
3045 if ( __search_string_vector (Knowns, arg) ==
false)
3047 ufos.push_back (*it);
3063 std::string KFL (KnownFlagList);
3066 if ( ArgumentNumber == -1 )
3068 STRING_VECTOR::const_iterator it = argv.begin();
3070 for (; it != argv.end(); ++it)
3073 const std::string arg = __get_remaining_string (*it, prefix);
3080 if ( arg.length() < 2 )
3084 else if ( arg[0] !=
'-' )
3088 else if ( arg[1] ==
'-' )
3094 const char* p = arg.c_str();
3096 for (; *p !=
'\0' ; p++)
3097 if ( KFL.find (*p) == std::string::npos )
3109 for (; i < argv.size(); ++i)
3111 const std::string Remain = __get_remaining_string (argv[i], prefix);
3115 if ( no_matches == ArgumentNumber)
3119 const char* p = Remain.c_str();
3121 for (; *p !=
'\0' ; p++)
3122 if ( KFL.find (*p) == std::string::npos )
3136 const char* KnownVariable1, ...)
const 3147 va_start (ap, KnownVariable1);
3148 known_variables.push_back (std::string (KnownVariable1) );
3150 for (; i < Number; ++i)
3152 known_variables.push_back (std::string (va_arg (ap,
char*) ) );
3164 victorate (GetPot::variable, variables, it)
3167 const std::string var_name = __get_remaining_string ( (*it).name, prefix);
3168 if ( var_name ==
"" )
3174 if ( __search_string_vector (Knowns, var_name) ==
false)
3176 ufos.push_back ( (*it).name);
3191 const char* KnownSection1, ...)
const 3202 va_start (ap, KnownSection1);
3203 known_sections.push_back (std::string (KnownSection1) );
3205 for (; i < Number; ++i)
3207 std::string tmp = std::string (va_arg (ap,
char*) );
3208 if ( tmp.length() == 0 )
3212 if ( tmp[tmp.length() - 1] !=
'/' )
3216 known_sections.push_back (tmp);
3234 victorate (std::string, section_list, it)
3237 const std::string sec_name = __get_remaining_string (*it, prefix);
3238 if ( sec_name ==
"" )
3244 if ( __search_string_vector (Knowns, sec_name) ==
false )
3246 ufos.push_back (*it);
3266 va_start (ap, Known);
3267 known_nominuses.push_back (std::string (Known) );
3269 for (; i < Number; ++i)
3271 std::string tmp = std::string (va_arg (ap,
char*) );
3272 if ( tmp.length() == 0 )
3276 known_nominuses.push_back (tmp);
3302 STRING_VECTOR::const_iterator it = argv.begin();
3304 for (; it != argv.end(); ++it)
3307 const std::string arg = __get_remaining_string (*it, prefix);
3313 if ( arg.length() < 1 )
3318 if ( arg[0] ==
'-' )
3323 if ( arg[0] ==
'[' && arg[arg.length() - 1] ==
']' )
3328 bool continue_f =
false;
3330 for (; i < arg.length() ; ++i)
3331 if ( arg[i] ==
'=' )
3342 if ( __search_string_vector (Knowns, arg) ==
false )
3344 ufos.push_back (*it);
3378 inline const std::string*
3381 if ( Idx >= value.size() )
3387 return & (value[Idx]);
3394 using namespace std;
3396 original = std::string (Value);
3402 char* copy =
new char[strlen (Value) + 1];
3403 strcpy (copy, Value);
3404 char* follow_token = strtok_r (copy, FieldSeparator, &spt);
3405 if ( value.size() != 0 )
3407 value.erase (value.begin(), value.end() );
3409 while (follow_token != 0)
3411 value.push_back (std::string (follow_token) );
3412 follow_token = strtok_r (NULL, FieldSeparator, &spt);
bool search(const char *option)
STRING_VECTOR unidentified_options(unsigned Number, const char *Known,...) const
STRING_VECTOR unidentified_variables() const
std::string next_nominus()
double next(const double &Default)
double operator()(const char *VarName, const double &Default, unsigned Idx) const
double operator()(const char *VarName, const double &Default, bool &found) const
const std::string * get_element(unsigned Idx) const
double __convert_to_type(const std::string &String, double Default) const
double operator()(const char *VarName, const double &Default) const
std::vector< variable > variables
STRING_VECTOR unidentified_nominuses(const STRING_VECTOR &Knowns) const
const std::string operator[](unsigned Idx) const
std::string unidentified_flags(const char *Known, int ArgumentNumber) const
void take(const char *Value, const char *FieldSeparator)
const std::string get(unsigned Idx, const char *Default) const
void __skip_whitespace(std::istream &istr)
STRING_VECTOR _requested_arguments
std::vector< std::string > STRING_VECTOR
#define victorate(TYPE, VARIABLE, ITERATOR)
int get(unsigned Idx, int Default) const
GetPot(const int argc_, char **argv_, const char *FieldSeparator=0x0)
STRING_VECTOR get_section_names() const
std::string __double2string(const double &Value) const
std::string __int2string(const int &Value) const
void init_multiple_occurrence()
std::string __DBE_expand(const std::string str)
std::string __process_section_label(const std::string &Section, STRING_VECTOR §ion_stack)
std::vector< unsigned > idx_nominus
STRING_VECTOR __DBE_get_expr_list(const std::string str, const unsigned ExpectedNumber)
void __record_variable_request(const std::string &Arg)
STRING_VECTOR unidentified_options() const
void enable_request_recording()
double follow(const double &Default, const char *Option)
void set_prefix(const char *Prefix)
double follow(const double &Default, unsigned No, const char *Option,...)
std::vector< std::string > nominus_followers(unsigned No,...)
GetPot & operator=(const GetPot &)
const std::string operator()(const char *VarName, const char *Default, unsigned Idx) const
std::vector< std::string > string_tails(const char *StartString)
const std::string __get_remaining_string(const std::string &String, const std::string &Start) const
STRING_VECTOR unidentified_variables(const STRING_VECTOR &Knowns) const
std::vector< std::string > nominus_followers(const char *Option)
const std::string __get_next_token(std::istream &istr)
bool search_failed() const
const GetPot::variable * __DBE_get_variable(const std::string str)
STRING_VECTOR unidentified_nominuses() const
bool __convert_to_type(const std::string &String, bool Default) const
bool checkVariable(const char *VarName) const
std::string _comment_start
STRING_VECTOR __get_section_tree(const std::string &FullPath)
STRING_VECTOR unidentified_variables(unsigned Number, const char *Known,...) const
bool operator()(const char *VarName, bool Default, bool &found) const
const std::string __get_string(std::istream &istr)
const std::string next(const char *Default)
int operator()(const char *VarName, int Default, bool &found) const
const char * __match_starting_string(const char *StartString)
const variable * __find_variable(const char *) const
STRING_VECTOR unidentified_options(const STRING_VECTOR &Knowns) const
STRING_VECTOR __read_in_file(const char *FileName)
variable(const char *Name, const char *Value, const char *FieldSeparator)
int direct_follow(int Default, const char *Option)
int __convert_to_type(const std::string &String, int Default) const
void set(const char *VarName, const int Value, const bool Requested=true)
bool __check_flags(const std::string &Str, const char *FlagList) const
const std::string __get_until_closing_bracket(std::istream &istr)
STRING_VECTOR unidentified_arguments(unsigned Number, const char *Known,...) const
STRING_VECTOR unidentified_sections(unsigned Number, const char *Known,...) const
void set(const char *VarName, const double &Value, const bool Requested=true)
unsigned nominus_size() const
int follow(int Default, const char *Option)
const std::string direct_follow(const char *Default, const char *Option)
bool __search_string_vector(const STRING_VECTOR &Vec, const std::string &Str) const
void __basic_initialization()
GetPot(const char *FileName, const char *CommentStart=0x0, const char *CommentEnd=0x0, const char *FieldSeparator=0x0)
variable(const variable &)
double get(unsigned Idx, const double &Default) const
STRING_VECTOR nominus_vector() const
void disable_request_recording()
std::vector< char * > __internal_string_container
std::string __DBE_expand_string(const std::string str)
int operator()(const char *VarName, int Default, unsigned Idx) const
void set(const char *VarName, const char *Value, const bool Requested=true)
int operator()(const char *VarName, int Default) const
STRING_VECTOR _requested_variables
void __parse_argument_vector(const STRING_VECTOR &ARGV)
bool search(unsigned No, const char *P,...)
const std::string operator()(const char *VarName, const char *Default) const
const std::string follow(const char *Default, const char *Option)
GetPot(const STRING &FileName, const char *CommentStart=0x0, const char *CommentEnd=0x0, const char *FieldSeparator=0x0)
bool __request_recording_f
std::vector< int > int_tails(const char *StartString, const int Default=1)
STRING_VECTOR get_variable_names() const
void __record_argument_request(const std::string &Arg)
variable & operator=(const variable &That)
bool argument_contains(unsigned Idx, const char *FlagList) const
std::string _field_separator
std::vector< double > double_tails(const char *StartString, const double Default=1.0)
GetPot(const STRING_VECTOR &FileNameList)
void absorb(const GetPot &That)
STRING_VECTOR unidentified_nominuses(unsigned Number, const char *Known,...) const
double direct_follow(const double &Default, const char *Option)
bool operator()(const char *VarName, bool Default) const
const std::string follow(const char *Default, unsigned No, const char *Option,...)
STRING_VECTOR unidentified_arguments(const STRING_VECTOR &Knowns) const
bool operator()(const char *VarName, bool Default, unsigned Idx) const
void __set_variable(const char *VarName, const char *Value)
STRING_VECTOR __read_in_stream(std::istream &istr)
STRING_VECTOR unidentified_arguments() const
STRING_VECTOR unidentified_sections() const
STRING_VECTOR _requested_sections
STRING_VECTOR section_list
const std::string operator()(const char *VarName, const char *Default, bool &found) const
int follow(int Default, unsigned No, const char *Option,...)
bool options_contain(const char *FlagList) const
STRING_VECTOR unidentified_sections(const STRING_VECTOR &Knowns) const
unsigned vector_variable_size(const char *VarName) const