28 #ifndef __INCLUDE_GUARD_GETPOT_CPP__ 29 #define __INCLUDE_GUARD_GETPOT_CPP__ 31 #if defined(WIN32) || defined(SOLARIS_RAW) || (__GNUC__ == 2) || defined(__HP_aCC) 33 # define GETPOT_STRTOK(a, b, c) strtok_r(a, b, c) 34 # define GETPOT_STRTOK_3_ARGS 36 # define GETPOT_STRTOK(a, b, c) strtok(a, b) 40 # define GETPOT_SNPRINTF(STR, SIZE, FORMAT_STR, ...) \ 41 _snprintf(tmp, (size_t)SIZE, FORMAT_STR, __VA_ARGS__) 43 # define GETPOT_SNPRINTF(STR, SIZE, FORMAT_STR, ...) \ 44 snprintf(tmp, (int)SIZE, FORMAT_STR, __VA_ARGS__) 49 #ifndef __GETPOT_INLINE 50 # define __GETPOT_INLINE 57 #ifdef GETPOT_SETTING_NAMESPACE 58 namespace GETPOT_SETTING_NAMESPACE {
61 #define victorate(TYPE, VARIABLE, ITERATOR) \ 62 for(std::vector<TYPE >::const_iterator ITERATOR = (VARIABLE).begin(); \ 63 (ITERATOR) != (VARIABLE).end(); ++(ITERATOR)) 68 public:
static const char*
name() {
return "bool"; }
71 static bool convert(
bool&
X) {
return (
bool)X; }
75 public:
static const char*
name() {
return "string"; }
78 static const char*
convert(
const char*
X) {
return (
const char*)X; }
82 public:
static const char*
name() {
return "integer"; }
89 static const char*
convert(std::string&
X) {
return (
const char*)
"inadmissible"; }
93 {
public:
static int convert(
unsigned int&
X) {
return (
int)X; } };
95 {
public:
static int convert(
char&
X) {
return (
int)X; } };
97 {
public:
static int convert(
unsigned char&
X) {
return (
int)X; } };
99 {
public:
static int convert(
short&
X) {
return (
int)X; } };
101 {
public:
static int convert(
unsigned short&
X) {
return (
int)X; } };
103 {
public:
static int convert(
long&
X) {
return (
int)X; } };
105 {
public:
static int convert(
unsigned long&
X) {
return (
int)X; } };
108 public:
static const char*
name() {
return "double"; }
111 static double convert(
double&
X) {
return (
double)X; }
114 {
public:
static double convert(
float&
X) {
return (
double)X; } };
124 cursor = 0; nominus_cursor = -1;
125 search_failed_f =
true; search_loop_f =
true;
126 prefix =
""; section =
"";
129 __request_recording_f =
true;
132 _comment_start = std::string(
"#");
133 _comment_end = std::string(
"\n");
136 _field_separator =
" \t\n";
150 _apriori_argv.push_back(std::string(
"Empty"));
176 _apriori_argv.push_back(std::string(argv_[0]));
178 for(; i<argc_; ++i) {
179 std::string tmp(argv_[i]);
180 _apriori_argv.push_back(tmp);
213 if (&That ==
this)
return *
this;
241 if (&That ==
this)
return;
245 __tmp.erase(__tmp.begin());
261 if( ARGV.size() == 0 )
return;
268 STRING_VECTOR::const_iterator it = ARGV.begin();
279 for(; it != ARGV.end(); ++it, ++i) {
280 std::string arg = *it;
282 if( arg.length() == 0 )
continue;
285 if( arg.length() > 1 && arg[0] ==
'[' && arg[arg.length()-1] ==
']' ) {
303 if( arg[0] !=
'-' )
idx_nominus.push_back(
unsigned(i));
307 for(std::string::iterator it = arg.begin(); it != arg.end(); ++it, ++i) {
308 if( *it !=
'=' )
continue;
331 std::ifstream i(FileName.c_str());
347 if( Token.length() == 0 || Token[0] == EOF)
break;
348 brute_tokens.push_back(Token);
361 while( i1 < brute_tokens.size() ) {
362 const std::string& SRef = brute_tokens[i1];
366 if( i2 < brute_tokens.size() && brute_tokens[i2] ==
"=" ) {
367 if( i3 >= brute_tokens.size() )
368 arglist.push_back(brute_tokens[i1] + brute_tokens[i2]);
370 arglist.push_back(brute_tokens[i1] + brute_tokens[i2] + brute_tokens[i3]);
371 i1 = i3+1; i2 = i3+2; i3 = i3+3;
375 arglist.push_back(SRef);
386 int tmp = istr.get();
389 while( isspace(tmp) ) {
404 do istr.unget();
while( i-- != 0 );
408 if( ! istr ) { istr.unget();
return; }
416 if( ! istr ) { istr.unget();
return; }
444 last_letter = tmp; tmp = istr.get();
446 || ((tmp ==
' ' || tmp ==
'\t' || tmp ==
'\n') && last_letter !=
'\\') ) {
449 else if( tmp ==
'\'' && last_letter !=
'\\' ) {
454 else if( tmp ==
'{' && last_letter ==
'$') {
458 else if( tmp ==
'$' && last_letter ==
'\\') {
459 token += tmp; tmp = 0;
462 else if( tmp ==
'\\' && last_letter !=
'\\')
476 last_letter = tmp; tmp = istr.get();
477 if( tmp == EOF)
return str;
479 else if( tmp ==
'\'' && last_letter !=
'\\')
return str;
480 else if( tmp ==
'\\' && last_letter !=
'\\')
continue;
490 std::string str =
"";
495 last_letter = tmp; tmp = istr.get();
496 if( tmp == EOF)
return str;
497 else if( tmp ==
'{' && last_letter ==
'$') brackets += 1;
498 else if( tmp ==
'}') {
501 if( brackets == 0)
return str +
'}';
502 else if( tmp ==
'\\' && last_letter !=
'\\')
513 std::string sname = Section;
515 if( sname.length() >= 2 && sname.substr(0, 2) ==
"./" ) {
516 sname = sname.substr(2);
519 else if( sname.length() >= 3 && sname.substr(0, 3) ==
"../" ) {
521 if( section_stack.end() != section_stack.begin() )
522 section_stack.pop_back();
523 sname = sname.substr(3);
524 }
while( sname.substr(0, 3) ==
"../" );
528 section_stack.erase(section_stack.begin(), section_stack.end());
535 size_t prev_slash_i = -1;
536 const size_t L = sname.length();
538 for(i = 0; i < L; ++i) {
539 if( sname[i] !=
'/' )
continue;
540 if( i - prev_slash_i > 1 ) {
541 const size_t Delta = i - (prev_slash_i + 1);
542 section_stack.push_back(sname.substr(prev_slash_i + 1, Delta));
547 if( i - prev_slash_i > 1 ) {
548 const size_t Delta = i - (prev_slash_i + 1);
549 section_stack.push_back(sname.substr(prev_slash_i + 1, Delta));
553 if( section_stack.size() != 0 ) {
554 victorate(std::string, section_stack, it) {
555 section += *it +
"/";
563 GetPot::__convert_to_type<bool>(
const std::string& String,
bool Default,
564 bool ThrowExceptionF )
const 570 if( String == *it1 )
return true;
574 if( String == *it2 )
return false;
577 if( ThrowExceptionF ) {
587 GetPot::__convert_to_type<double>(
const std::string& String,
double Default,
588 bool ThrowExceptionF )
const 592 if( sscanf(String.c_str(),
"%lf", &tmp) == 1 )
return tmp;
594 if( ThrowExceptionF )
603 GetPot::__convert_to_type<int>(
const std::string& String,
int Default,
604 bool ThrowExceptionF )
const 614 GetPot::__convert_to_type<const char*>(
const std::string& String,
const char* Default,
615 bool ThrowExceptionF )
const 623 std::vector<char>* c_str_copy =
new std::vector<char>(String.length() + 1,
'\0');
624 std::copy(String.begin(), String.end(), c_str_copy->begin());
626 ((
GetPot*)
this)->__internal_string_container.push_back(c_str_copy);
627 return &(*c_str_copy)[0];
638 if( Start ==
"" )
return String;
641 if( String.find(Start) == 0 )
return String.substr(Start.length());
649 unsigned OldCursor =
cursor;
650 std::string search_term;
652 if( ! Option )
return false;
654 search_term =
prefix + Option;
659 if( OldCursor >=
argv.size() ) OldCursor = static_cast<unsigned int>(
argv.size()) - 1;
664 for(; c <
argv.size(); c++) {
665 if(
argv[c] == search_term )
671 for(c = 1; c < OldCursor; c++) {
672 if(
argv[c] == search_term )
684 if( No == 0 )
return false;
687 if(
search(P) ==
true )
return true;
694 char* Opt = va_arg(ap,
char *);
695 if(
search(Opt) ==
true )
break;
704 char* Opt = va_arg(ap,
char *);
735 va_start(ap, StringForTrue);
737 char* Opt = va_arg(ap,
char *);
753 va_start(ap, StringForFalse);
755 char* Opt = va_arg(ap,
char *);
766 {
return idx <
argv.size() ?
argv[idx] :
""; }
771 if( Idx >=
argv.size() )
return Default;
776 GetPot::get<const char*>(
unsigned Idx,
const char* Default)
const 778 if( Idx >=
argv.size() )
return Default;
785 return get<T>(VarName, (
const char*)0x0);
791 return __get<T>(VarName, Constraint,
true);
802 {
return static_cast<unsigned int>(
argv.size()); }
812 {
cursor =
static_cast<unsigned int>(
argv.size());
return Default; }
828 if(
search(Option) ==
false )
return Default;
829 return next(Default);
839 if( No == 0 )
return Default;
846 char* Opt = va_arg(ap,
char *);
847 if(
search(Opt) ==
true ) {
849 return next(Default);
864 if( FollowStr == 0x0 )
return Default;
869 if( ++
cursor >= static_cast<unsigned int>(
argv.size()) )
cursor =
static_cast<unsigned int>(
argv.size());
876 std::vector<std::string> result;
877 const unsigned N =
static_cast<unsigned int>(strlen(StartString));
879 std::vector<std::string>::iterator it =
argv.begin();
882 while( it !=
argv.end() ) {
885 if( (*it).compare(0, N, StartString) != 0 ) { ++it; ++idx;
continue; }
888 result.push_back((*it).substr(N));
891 std::vector<unsigned>::iterator nit =
idx_nominus.begin();
907 if(
argv.empty() )
break;
918 std::vector<int> result;
919 const unsigned N =
static_cast<unsigned int>(strlen(StartString));
921 std::vector<std::string>::iterator it =
argv.begin();
924 while( it !=
argv.end() ) {
927 if( (*it).compare(0, N, StartString) != 0 ) { ++it; ++idx;
continue; }
933 std::vector<unsigned>::iterator nit =
idx_nominus.begin();
949 if(
argv.empty() )
break;
959 const double Default )
961 std::vector<double> result;
962 const unsigned N =
static_cast<unsigned int>(strlen(StartString));
964 std::vector<std::string>::iterator it =
argv.begin();
966 while( it !=
argv.end() ) {
969 if( (*it).compare(0, N, StartString) != 0 ) { ++it; ++idx;
continue; }
975 std::vector<unsigned>::iterator nit =
idx_nominus.begin();
991 if(
argv.empty() )
break;
1005 std::vector<std::string> result_list;
1006 if(
search(Option) ==
false )
return result_list;
1007 while( 1 + 1 == 2 ) {
1020 result_list.push_back(
argv[cursor]);
1028 std::vector<std::string> result_list;
1031 if( No == 0 )
return result_list;
1035 for(
unsigned i=0; i<No; ++i) {
1036 char* Option = va_arg(ap,
char *);
1038 result_list.insert(result_list.end(), tmp.begin(), tmp.end());
1059 const unsigned N =
static_cast<unsigned int>(strlen(StartString));
1060 unsigned OldCursor =
cursor;
1063 if( OldCursor >= static_cast<unsigned int>(
argv.size()) ) OldCursor =
static_cast<unsigned int>(
argv.size()) - 1;
1068 for(; c <
argv.size(); c++) {
1069 if(
argv[c].compare(0, N, StartString) == 0 ) {
1079 for(c = 1; c < OldCursor; c++) {
1080 if(
argv[c].compare(0, N, StartString) == 0 ) {
1098 STRING_VECTOR::const_iterator it =
argv.begin();
1099 for(; it !=
argv.end(); ++it) {
1102 if( str.length() >= 2 && str[0] ==
'-' && str[1] !=
'-' )
1111 if( Idx >=
argv.size() )
return false;
1115 ((
GetPot*)
this)->__record_argument_request(
argv[Idx]);
1124 unsigned no_matches = 0;
1126 for(; i<
argv.size(); ++i) {
1130 if( no_matches == Idx)
1141 const char* p=FlagList;
1142 for(; *p !=
'\0' ; p++)
1143 if( Str.find(*p) != std::string::npos )
return true;
1154 std::vector<unsigned>::const_iterator it =
idx_nominus.begin();
1156 nv.push_back(
argv[*it]);
1161 ((
GetPot*)
this)->__record_argument_request(
argv[*it]);
1174 return std::string(
"");
1213 bool ThrowExceptionF)
const 1222 const std::string* element = sv->
get_element(Idx, ThrowExceptionF);
1227 if( Constraint != 0x0 && !
__constraint_check(*element, Constraint, ThrowExceptionF) )
1230 return __convert_to_type<typename TypeInfo<T>::type>(*element,
TypeInfo<T>::convert(Default), ThrowExceptionF);
1235 T Default,
bool ThrowExceptionF)
const 1242 const std::string* element = sv->
get_element(Idx, ThrowExceptionF);
1247 else if( Constraint != 0x0 && !
__constraint_check(*element, Constraint, ThrowExceptionF) )
1250 return __convert_to_type<typename TypeInfo<T>::type>(*element,
TypeInfo<T>::convert(Default), ThrowExceptionF);
1259 {
return __get_element<T>(VarName, Idx, Constraint,
true); }
1307 const std::string& CommentStart,
const std::string& CommentEnd,
1308 const std::string& FieldSeparator)
1314 if( CommentStart.length() != 0 )
_comment_start = std::string(CommentStart);
1315 if( CommentEnd.length() != 0 )
_comment_end = std::string(CommentEnd);
1321 _apriori_argv.push_back(std::string(FileName));
1324 _apriori_argv.insert(_apriori_argv.begin()+1, args.begin(), args.end());
1331 std::string delimiters )
1336 std::string::size_type index_beg, index_end;
1338 index_beg = str.find_first_not_of(delimiters);
1340 while (index_beg != std::string::npos) {
1341 index_end = str.find_first_of(delimiters, index_beg);
1342 tmp = str.substr(index_beg, index_end == std::string::npos ?
1343 std::string::npos : (index_end - index_beg));
1344 vect.push_back(tmp);
1345 index_beg = str.find_first_not_of(delimiters, index_end);
1355 const std::string EmptyString(
"");
1367 GetPot::set_variable<const char*>(
const StringOrCharP VarName,
const char* Value,
const bool Requested )
1369 const std::string Arg =
prefix + VarName.content + std::string(
"=") + std::string(Value);
1370 argv.push_back(Arg);
1379 GetPot::set_variable<double>(
const StringOrCharP VarName,
double Value,
const bool Requested )
1383 GetPot::set_variable<int>(
const StringOrCharP VarName,
int Value,
const bool Requested )
1387 GetPot::set_variable<bool>(
const StringOrCharP VarName,
bool Value,
const bool Requested )
1400 Value = get<T>(VarName);
1407 Value = get<T>(VarName, Constraint);
1410 template <
class T,
class U>
1414 Value = get<U>(VarName, Constraint, Default);
1420 const std::string EmptyString(
"");
1423 if( sv == 0 )
return 0;
1424 return static_cast<unsigned int>(sv->
value.size());
1431 std::vector<GetPot::variable>::const_iterator it =
variables.begin();
1434 if( Tmp !=
"" ) result.push_back(Tmp);
1445 bool ThrowExceptionF)
const 1447 const std::string Name =
prefix + VarName;
1450 ((
GetPot*)
this)->__record_variable_request(Name);
1453 std::vector<variable>::const_iterator it =
variables.begin();
1455 if( (*it).name == Name )
return &(*it);
1458 if( ThrowExceptionF ) {
1460 msg += std::string(
"\"") +
filename +
"\": ";
1462 msg += VarName +
"\' ";
1466 throw std::runtime_error(msg);
1480 std::cout <<
"argc = " <<
static_cast<unsigned int>(
argv.size()) << std::endl;
1481 STRING_VECTOR::const_iterator it =
argv.begin();
1482 for(; it !=
argv.end(); ++it)
1483 std::cout << *it << std::endl;
1484 std::cout << std::endl;
1541 std::string new_string =
"";
1542 unsigned open_brackets = 0;
1545 for(; i<str.size(); ++i) {
1546 if( i < str.size() - 2 && str.substr(i, 2) ==
"${" ) {
1547 if( open_brackets == 0 ) first = i+2;
1550 else if( str[i] ==
'}' && open_brackets > 0) {
1552 if( open_brackets == 0 ) {
1553 const std::string Replacement =
__DBE_expand(str.substr(first, i - first));
1554 new_string += Replacement;
1557 else if( open_brackets == 0 )
1558 new_string += str[i];
1568 std::string str = str_;
1574 for(; i < str.size(); ++i)
1575 if( ! isspace(str[i]) )
break;
1578 unsigned open_brackets = 0;
1579 std::vector<unsigned> start_idx;
1580 unsigned start_new_string = i;
1581 unsigned l =
static_cast<unsigned int>(str.size());
1585 const char letter = str[i];
1587 if( isspace(letter) && open_brackets == 0) {
1588 expr_list.push_back(str.substr(start_new_string, i - start_new_string));
1589 bool no_breakout_f =
true;
1590 for(++i; i < l ; ++i) {
1591 if( ! isspace(str[i]) )
1592 { no_breakout_f =
false; start_new_string = i;
break; }
1594 if( no_breakout_f ) {
1596 if( expr_list.size() < ExpectedNumber ) {
1597 const std::string pre_tmp(
"<< ${ }: missing arguments>>");
1598 STRING_VECTOR tmp(ExpectedNumber - expr_list.size(), pre_tmp);
1599 expr_list.insert(expr_list.end(), tmp.begin(), tmp.end());
1606 if( str.length() >= i+2 && str.substr(i, 2) ==
"${" ) {
1608 start_idx.push_back(i+2);
1610 else if( letter ==
'}' && open_brackets > 0) {
1611 int start = start_idx[start_idx.size()-1];
1612 start_idx.pop_back();
1613 const std::string Replacement =
__DBE_expand(str.substr(start, i-start));
1614 if( start - 3 < (
int)0)
1615 str = Replacement + str.substr(i+1);
1617 str = str.substr(0, start-2) + Replacement + str.substr(i+1);
1618 l =
static_cast<unsigned int>(str.size());
1619 i = start +
static_cast<unsigned int>(Replacement.size()) - 3;
1626 expr_list.push_back(str.substr(start_new_string, i-start_new_string));
1628 if( expr_list.size() < ExpectedNumber ) {
1629 const std::string pre_tmp(
"<< ${ }: missing arguments>>");
1630 STRING_VECTOR tmp(ExpectedNumber - expr_list.size(), pre_tmp);
1631 expr_list.insert(expr_list.end(), tmp.begin(), tmp.end());
1641 const std::string EmptyString(
"");
1643 std::string secure_Prefix =
prefix;
1648 if( var != 0 ) {
prefix = secure_Prefix;
return var; }
1653 if( var != 0 ) {
prefix = secure_Prefix;
return var; }
1658 char* tmp =
new char[VarName.length() + 25];
1660 "<<${ } variable '%s' undefined>>", VarName.c_str());
1671 if( expr[0] ==
':' )
1672 return expr.substr(1);
1675 else if( expr[0] ==
'&' ) {
1678 STRING_VECTOR::const_iterator it = A.begin();
1679 std::string result = *it++;
1680 for(; it != A.end(); ++it) result += *it;
1686 else if( expr.length() >= 3 && expr.substr(0, 3) ==
"<->" ) {
1688 std::string::size_type tmp = 0;
1689 const std::string::size_type L = A[1].length();
1690 while( (tmp = A[0].find(A[1])) != std::string::npos ) {
1691 A[0].replace(tmp, L, A[2]);
1696 else if( expr[0] ==
'+' ) {
1698 STRING_VECTOR::const_iterator it = A.begin();
1700 for(; it != A.end(); ++it)
1705 else if( expr[0] ==
'-' ) {
1707 STRING_VECTOR::const_iterator it = A.begin();
1709 for(; it != A.end(); ++it)
1714 else if( expr[0] ==
'*' ) {
1716 STRING_VECTOR::const_iterator it = A.begin();
1718 for(; it != A.end(); ++it)
1723 else if( expr[0] ==
'/' ) {
1726 STRING_VECTOR::const_iterator it = A.begin();
1728 if( result == 0 )
return "0.0";
1729 for(; it != A.end(); ++it) {
1731 if( Q == 0.0 )
return "0.0";
1738 else if( expr[0] ==
'^' ) {
1740 STRING_VECTOR::const_iterator it = A.begin();
1742 for(; it != A.end(); ++it)
1748 else if( expr.length() >= 2 &&
1749 ( expr.substr(0,2) ==
"==" || expr.substr(0,2) ==
">=" ||
1750 expr.substr(0,2) ==
"<=" || expr[0] ==
'>' || expr[0] ==
'<')) {
1753 enum { EQ, GEQ, LEQ, GT, LT };
1754 if ( expr.substr(0, 2) ==
"==" ) op = EQ;
1755 else if ( expr.substr(0, 2) ==
">=" ) op = GEQ;
1756 else if ( expr.substr(0, 2) ==
"<=" ) op = LEQ;
1757 else if ( expr[0] ==
'>' ) op = GT;
1764 std::string x_orig = a[0];
1768 STRING_VECTOR::const_iterator y_orig = a.begin();
1769 for(y_orig++; y_orig != a.end(); y_orig++) {
1773 if ( x == 1e37 || y == 1e37 ) {
1775 if( (op == EQ && x_orig == *y_orig) || (op == GEQ && x_orig >= *y_orig) ||
1776 (op == LEQ && x_orig <= *y_orig) || (op == GT && x_orig > *y_orig) ||
1777 (op == LT && x_orig < *y_orig) )
1782 if( (op == EQ && x == y) || (op == GEQ && x >= y) ||
1783 (op == LEQ && x <= y) || (op == GT && x > y) ||
1784 (op == LT && x < y) )
1794 else if( expr.length() >= 2 && expr.substr(0, 2) ==
"??" ) {
1798 if( x == 1e37 || x < 0 || x >= a.size() - 1 )
return a[a.size()-1];
1801 return a[int(x+0.5)];
1804 else if( expr[0] ==
'?' ) {
1807 else if( a.size() > 2 )
return a[2];
1810 else if( expr[0] ==
'!' ) {
1813 if( Var->
name ==
"" )
return std::string(Var->
original);
1819 else if( expr.length() >= 2 && expr.substr(0,2) ==
"@:" ) {
1824 if( x == 1e37 || x < 0 || x >= A[0].
size() - 1)
1825 return "<<1st index out of range>>";
1827 if( A.size() > 2 ) {
1829 if ( y != 1e37 && y > 0 && y <= A[0].
size() - 1 && y > x )
1830 return A[0].substr(
int(x+0.5),
int(y+1.5) -
int(x+0.5));
1832 return A[0].substr(
int(x+0.5));
1833 return "<<2nd index out of range>>";
1836 char* tmp =
new char[2];
1837 tmp[0] = A[0][int(x+0.5)]; tmp[1] =
'\0';
1838 std::string result(tmp);
1844 else if( expr[0] ==
'@' ) {
1848 if( Var->name ==
"" ) {
1851 return std::string(Var->original);
1857 if (x == 1e37 || x < 0 || x >= Var->value.size() )
1858 return "<<1st index out of range>>";
1860 if ( A.size() > 2) {
1862 int begin = int(x+0.5);
1864 if ( y != 1e37 && y > 0 && y <= Var->value.size() && y > x)
1867 end =
static_cast<unsigned int>(Var->value.size());
1869 return "<<2nd index out of range>>";
1871 std::string result = *(Var->get_element(begin));
1874 result += std::string(
" ") + *(Var->get_element(i));
1878 return *(Var->get_element(
int(x+0.5)));
1901 if( *itk == Str )
return true;
1908 const char* KnownArgument1, ...)
const 1916 va_start(ap, KnownArgument1);
1917 known_arguments.push_back(std::string(KnownArgument1));
1919 for(; i<Number; ++i)
1920 known_arguments.push_back(std::string(va_arg(ap,
char *)));
1934 STRING_VECTOR::const_iterator it =
argv.begin();
1936 for(; it !=
argv.end(); ++it) {
1939 if( arg ==
"" )
continue;
1943 ufos.push_back(*it);
1950 const char* KnownOption1, ...)
const 1958 va_start(ap, KnownOption1);
1959 known_options.push_back(std::string(KnownOption1));
1961 for(; i<Number; ++i)
1962 known_options.push_back(std::string(va_arg(ap,
char *)));
1979 const std::string arg = *it;
1980 if( arg.length() == 0 )
continue;
1981 if( arg[0] ==
'-' ) option_list.push_back(arg);
1990 STRING_VECTOR::const_iterator it =
argv.begin();
1992 for(; it !=
argv.end(); ++it) {
1995 if( arg ==
"" )
continue;
1998 if( arg.length() < 1 || arg[0] !=
'-' )
continue;
2001 ufos.push_back(*it);
2016 std::string KFL(KnownFlagList);
2019 if( ArgumentNumber == -1 ) {
2020 STRING_VECTOR::const_iterator it =
argv.begin();
2022 for(; it !=
argv.end(); ++it) {
2027 if( arg.length() < 2 || arg[0] !=
'-' || arg[1] ==
'-' )
continue;
2030 for(ptrdiff_t i=1; i<(int)arg.length(); ++i) {
2031 if( KFL.find(arg[i]) == std::string::npos ) ufos += arg[i];
2040 for(; i<
argv.size(); ++i) {
2044 if( no_matches == ArgumentNumber) {
2047 for(ptrdiff_t i=1; i<(int)Remain.length(); ++i) {
2048 if( KFL.find(Remain[i]) == std::string::npos ) ufos += Remain[i];
2060 const char* KnownVariable1, ...)
const 2068 va_start(ap, KnownVariable1);
2069 known_variables.push_back(std::string(KnownVariable1));
2071 for(; i<Number; ++i)
2072 known_variables.push_back(std::string(va_arg(ap,
char *)));
2086 if( var_name ==
"" )
continue;
2090 ufos.push_back((*it).name);
2102 const char* KnownSection1, ...)
const 2110 va_start(ap, KnownSection1);
2111 known_sections.push_back(std::string(KnownSection1));
2113 for(; i<Number; ++i) {
2114 std::string tmp = std::string(va_arg(ap,
char *));
2115 if( tmp.length() == 0 )
continue;
2116 if( tmp[tmp.length()-1] !=
'/' ) tmp +=
'/';
2117 known_sections.push_back(tmp);
2136 if( sec_name ==
"" )
continue;
2140 ufos.push_back(*it);
2156 va_start(ap, Known);
2157 known_nominuses.push_back(std::string(Known));
2159 for(; i<Number; ++i) {
2160 std::string tmp = std::string(va_arg(ap,
char *));
2161 if( tmp.length() == 0 )
continue;
2162 known_nominuses.push_back(tmp);
2187 STRING_VECTOR::const_iterator it =
argv.begin();
2189 for(; it !=
argv.end(); ++it) {
2192 if( arg ==
"" )
continue;
2194 if( arg.length() < 1 )
continue;
2196 if( arg[0] ==
'-' )
continue;
2198 if( arg[0] ==
'[' && arg[arg.length()-1] ==
']' )
continue;
2200 bool continue_f =
false;
2202 for(; i<arg.length() ; ++i)
2203 if( arg[i] ==
'=' ) { continue_f =
true;
break; }
2204 if( continue_f )
continue;
2208 ufos.push_back(*it);
2215 bool ThrowExceptionF)
const 2217 std::string ConstraintString = std::string(ConstraintStr);
2218 if( ConstraintStr == (
const char *)
"" )
return true;
2221 if( ThrowExceptionF ) {
2223 msg += std::string(
"\"") +
filename +
"\": \'";
2224 msg += std::string(Value) +
"\' ";
2229 throw std::runtime_error(msg);
2255 bool result =
false;
2258 if (**iterator ==
'|') ++(*iterator);
2259 while( isspace(**iterator) ) ++(*iterator);
2261 while( isspace(**iterator) ) ++(*iterator);
2262 }
while ( **iterator ==
'|' );
2273 while( 1 + 1 == 2 ) {
2274 if( *viterator != **iterator )
break;
2275 ++(*iterator); ++viterator;
2277 if( *viterator ==
'\0' ) {
2278 if ( **iterator !=
'\'' )
break;
2281 else if( **iterator ==
'\'' )
break;
2284 while( **iterator !=
'\'' ) ++(*iterator);
2295 if (**iterator ==
'&') ++(*iterator);
2296 while( isspace(**iterator) ) ++(*iterator);
2298 while( isspace(**iterator) ) ++(*iterator);
2299 }
while ( **iterator ==
'&' );
2306 const char** iterator)
const 2311 GREATER_EQ = EQ | GREATER,
2313 LESS_EQ = EQ | LESS,
2316 DEVISABLE_BY = 0x05,
2320 while( isspace(**iterator) ) ++(*iterator);
2322 switch ( (*iterator)[0] ) {
2324 default: op = EQ; ++(*iterator);
break;
2328 case '>': op = GREATER; ++(*iterator);
break;
2329 case '<': op = LESS; ++(*iterator);
break;
2330 case '%': op = DEVISABLE_BY; ++(*iterator);
break;
2331 case '!': op = NOT; ++(*iterator);
break;
2336 while( isspace(**iterator) ) ++(*iterator);
2338 if( **iterator !=
')' )
2339 throw std::runtime_error(std::string(
"Error while processing the file \"")
2340 +
filename +
"\": a bracket is missing in a constraint.");
2346 if( (*iterator)[0] ==
'=' ) {
2347 if( op == VOID )
throw std::runtime_error(std::string(
"Syntax error found in a constraint")
2348 +
"string while processing the file \"" 2351 op = (Operator) (EQ | op);
2355 else if( op == VOID )
throw std::runtime_error(std::string(
"Syntax error found in a constraint")
2356 +
"string while processing the file \"" 2364 while( isspace(**iterator) ) ++(*iterator);
2367 double value_numeric = -1.0;
2368 double cmp_numeric = -1.0;
2371 result = sscanf(Value.c_str(),
"%lf", &value_numeric);
2372 if( result == 0 || result == EOF )
return false;
2373 result = sscanf(*iterator,
"%lf", &cmp_numeric);
2374 if( result == 0 || result == EOF )
return false;
2377 while( !isspace(**iterator) && (*iterator)[0] !=
')' ) ++(*iterator);
2378 while( isspace(**iterator) ) ++(*iterator);
2381 case GREATER:
return value_numeric > cmp_numeric;
2382 case GREATER_EQ:
return value_numeric >= cmp_numeric;
2383 case LESS:
return value_numeric < cmp_numeric;
2384 case LESS_EQ:
return value_numeric <= cmp_numeric;
2385 case NOT_EQ:
return value_numeric != cmp_numeric;
2386 case EQ:
return value_numeric == cmp_numeric;
2387 case DEVISABLE_BY:
return (value_numeric / cmp_numeric) == double(
int(value_numeric / cmp_numeric));
2388 case NOT:
throw std::runtime_error(std::string(
"Syntax error found in a constraint")
2389 +
"string while processing the file \"" 2391 case VOID:
throw std::runtime_error(std::string(
"Syntax error found in a constraint")
2392 +
"string while processing the file \"" 2395 throw std::runtime_error(std::string(
"Syntax error found in a constraint")
2396 +
"string while processing the file \"" 2423 take(Value, FieldSeparator);
2429 if( Idx <
value.size() )
return &(
value[Idx]);
2431 if( ThrowExceptionF ) {
2435 msg +=
name +
"\' ";
2439 throw std::runtime_error(msg);
2449 using namespace std;
2455 # ifdef GETPOT_STRTOK_3_ARGS 2459 char* copy =
new char[Value.length()+1];
2460 strcpy(copy, Value.c_str());
2461 char* follow_token =
GETPOT_STRTOK(copy, FieldSeparator.c_str(), &spt);
2463 while(follow_token != 0) {
2464 value.push_back(std::string(follow_token));
2465 follow_token =
GETPOT_STRTOK(NULL, FieldSeparator.c_str(), &spt);
2478 if( &That !=
this) {
2493 char* tmp =
new char[128];
2495 std::string result(tmp);
2502 char* tmp =
new char[128];
2504 std::string result(tmp);
2513 for(ptrdiff_t i=0; i<(int)FullPath.length(); ++i) {
2514 if( FullPath[i] ==
'/' ) {
2515 result.push_back(FullPath.substr(0, i));
2524 #ifdef GETPOT_SETTING_NAMESPACE 2530 #endif // __INCLUDE_GUARD_GETPOT_CPP__ const std::string __get_until_closing_bracket(std::istream &istr)
bool __request_recording_f
void set(StringOrCharP VarName, T &Value)
std::vector< unsigned > idx_nominus
static int convert(unsigned int &X)
STRING_VECTOR unidentified_nominuses() const
#define GETPOT_STR_REACHED_END_OF_CONSTRAINT
static const char * name()
static int convert(int &X)
void __split(std::string str, std::vector< std::string > &vect, std::string delimiters=" \")
void __record_variable_request(const std::string &Arg)
T direct_follow(T Default, const char *Option)
std::vector< std::vector< char > *> __internal_string_container
STRING_VECTOR _requested_arguments
std::vector< std::string > STRING_VECTOR
#define GETPOT_STR_DOES_NOT_SATISFY_CONSTRAINT
static double default_value()
const std::string operator[](unsigned Idx) const
bool __constraint_check(const std::string &Value, const char *ConstraintStr, bool ThrowExceptionF) const
variable & operator=(const variable &That)
void __record_argument_request(const std::string &Arg)
void set_false_string_list(unsigned N, const char *StringForFalse,...)
#define GETPOT_STRTOK(a, b, c)
#define victorate(TYPE, VARIABLE, ITERATOR)
std::string unidentified_flags(const char *Known, int ArgumentNumber) const
#define GETPOT_SNPRINTF(STR, SIZE, FORMAT_STR,...)
void __parse_argument_vector(const STRING_VECTOR &ARGV)
T follow(T Default, const char *Option)
#define GETPOT_STR_CANNOT_CONVERT_TO(X, TYPE)
STRING_VECTOR section_list
T operator()(const StringOrCharP VarName, T Default) const
STRING_VECTOR get_section_names() const
T get(unsigned Idx, T Default) const
unsigned vector_variable_size(StringOrCharP VarName) const
const GetPot::variable * __DBE_get(const std::string str)
std::vector< int > int_tails(const char *StartString, const int Default=1)
static const char * convert(std::string &X)
static bool convert(bool &X)
void init_multiple_occurrence()
void __set_variable(const std::string &VarName, const std::string &Value)
static double convert(double &X)
STRING_VECTOR unidentified_variables() const
GetPot & operator=(const GetPot &)
STRING_VECTOR __read_in_file(const std::string &FileName)
#define GETPOT_SETTING_DEFAULT_TRUE_STRING_LIST
STRING_VECTOR false_string_list
STRING_VECTOR nominus_followers(const char *Option)
static const char * default_value()
const char * __get_const_char(const std::string &String) const
static const char * name()
static const char * convert(const char *X)
const variable * __find_variable(const std::string &, const std::string &TypeName, bool ThrowExceptionF=GETPOT_SETTING_THROW_EXCEPTION_ON_DEFAULT) const
STRING_VECTOR _requested_sections
STRING_VECTOR unidentified_sections() const
bool options_contain(const char *FlagList) const
STRING_VECTOR __get_section_tree(const std::string &FullPath)
static std::string default_value()
bool __constraint_check_OR(const std::string &Value, const char **iterator) const
STRING_VECTOR __read_in_stream(std::istream &istr)
const std::string * get_element(unsigned Idx, bool ThrowExceptionF=GETPOT_SETTING_THROW_EXCEPTION_ON_DEFAULT) const
bool __constraint_check_AND(const std::string &Value, const char **iterator) const
#define GETPOT_SETTING_THROW_EXCEPTION_ON_DEFAULT
const char * __match_starting_string(const char *StartString)
bool __constraint_check_PRIMARY(const std::string &Value, const char **iterator) const
std::string __DBE_expand(const std::string str)
static const char * name()
static int convert(unsigned char &X)
std::string __DBE_expand_string(const std::string str)
bool argument_contains(unsigned Idx, const char *FlagList) const
static int default_value()
bool __constrain_check_EQUAL_STRING(const char *viterator, const char **iterator) const
std::string __double2string(const double &Value) const
std::string __process_section_label(const std::string &Section, STRING_VECTOR §ion_stack)
#define GETPOT_STR_IN_SECTION
T get_element(const StringOrCharP VarName, unsigned Idx, const char *Constraint)
void absorb(const GetPot &That)
T __get(const StringOrCharP VarName, const char *Constraint, bool ThrowExceptionF) const
void __basic_initialization()
const std::string __get_next_token(std::istream &istr)
std::string next_nominus()
static double convert(float &X)
std::string __int2string(const int &Value) const
STRING_VECTOR unidentified_arguments() const
#define GETPOT_STR_WITH_TYPE
STRING_VECTOR __DBE_get_expr_list(const std::string str, const unsigned ExpectedNumber)
bool __check_flags(const std::string &Str, const char *FlagList) const
#define GETPOT_STR_FILE_NOT_FOUND(FILE)
STRING_VECTOR true_string_list
const std::string __get_string(std::istream &istr)
STRING_VECTOR unidentified_options() const
static int convert(char &X)
static const char * name()
STRING_VECTOR get_variable_names() const
T __convert_to_type(const std::string &String, T Default, bool ThrowExceptionF=GETPOT_SETTING_THROW_EXCEPTION_ON_DEFAULT) const
void __skip_whitespace(std::istream &istr)
const std::string __get_remaining_string(const std::string &String, const std::string &Start) const
static bool default_value()
bool search(const char *option)
T __get_element(const StringOrCharP VarName, unsigned Idx, const char *Constraint, bool ThrowExceptionF) const
#define GETPOT_STR_VARIABLE
std::vector< std::string > string_tails(const char *StartString)
void __build(const std::string &FileName, const std::string &CommentStart, const std::string &CommentEnd, const std::string &FieldSeparator)
static int convert(unsigned long &X)
static int convert(short &X)
#define GETPOT_STR_TRUE_FALSE_UNDEFINED
std::vector< double > double_tails(const char *StartString, const double Default=1.0)
#define GETPOT_STR_DOES_NOT_CONTAIN_ELEMENT
STRING_VECTOR nominus_vector() const
static int convert(unsigned short &X)
std::string _field_separator
bool __search_string_vector(const STRING_VECTOR &Vec, const std::string &Str) const
static int convert(long &X)
std::vector< variable > variables
void set_true_string_list(unsigned N, const char *StringForTrue,...)
#define GETPOT_STR_MISSING_VARIABLE
#define GETPOT_SETTING_DEFAULT_FALSE_STRING_LIST
std::string _comment_start
STRING_VECTOR _requested_variables
void take(const std::string &Value, const std::string &FieldSeparator)