28 #ifndef LIBMESH_GETPOT_H 29 #define LIBMESH_GETPOT_H 31 #if defined(WIN32) || defined(SOLARIS_RAW) || (__GNUC__ == 2) || defined(__HP_aCC) 32 #define strtok_r(a, b, c) strtok(a, b) 33 #endif // WINDOWS or SOLARIS or gcc 2.* or HP aCC 68 #if !defined(GETPOT_DISABLE_MUTEX) 70 #define SCOPED_MUTEX libMesh::Threads::spin_mutex::scoped_lock lock(_getpot_mtx) 71 #define GETPOT_MUTEX_DECLARE mutable libMesh::Threads::spin_mutex _getpot_mtx 74 #define GETPOT_MUTEX_DECLARE 77 #define getpot_cerr libMesh::err 78 #define getpot_error() libmesh_error() 79 #define getpot_file_error(filename) libmesh_file_error(filename) 80 #define getpot_cast_int libMesh::cast_int 84 #ifdef LIBMESH_HAVE_CXX11_INVERSE_HYPERBOLIC_SINE 85 #define HAVE_INVERSE_HYPERBOLIC_SINE 88 #ifdef LIBMESH_HAVE_CXX11_INVERSE_HYPERBOLIC_COSINE 89 #define HAVE_INVERSE_HYPERBOLIC_COSINE 92 #ifdef LIBMESH_HAVE_CXX11_INVERSE_HYPERBOLIC_TANGENT 93 #define HAVE_INVERSE_HYPERBOLIC_TANGENT 99 #define GETPOT_DISABLE_MUTEX 101 #define GETPOT_MUTEX_DECLARE 103 #define getpot_cerr std::cerr 104 #define getpot_error() throw std::runtime_error(std::string("GetPot Error")) 105 #define getpot_file_error(filename) getpot_error() 106 #define getpot_cast_int static_cast 110 #ifndef __has_builtin 111 #define __has_builtin(x) 0 117 #if __cplusplus > 199711L && (!defined(__clang__) || __has_builtin(asinh)) 118 #define HAVE_INVERSE_HYPERBOLIC_SINE 121 #if __cplusplus > 199711L && (!defined(__clang__) || __has_builtin(acosh)) 122 #define HAVE_INVERSE_HYPERBOLIC_COSINE 125 #if __cplusplus > 199711L && (!defined(__clang__) || __has_builtin(atanh)) 126 #define HAVE_INVERSE_HYPERBOLIC_TANGENT 129 #endif // #ifdef USE_LIBMESH 134 #define victorate(TYPE, VARIABLE, ITERATOR) \ 135 std::vector<TYPE>::const_iterator ITERATOR = (VARIABLE).begin(); \ 136 for (; (ITERATOR) != (VARIABLE).end(); ++(ITERATOR)) 142 #ifdef GETPOT_NAMESPACE 163 inline GetPot(
const int argc_,
const char*
const* argv_,
164 const char* FieldSeparator=0x0);
165 inline GetPot(
const char* FileName,
166 const char* CommentStart=0x0,
const char* CommentEnd=0x0,
167 const char* FieldSeparator=0x0);
168 inline GetPot(
const std::string& FileName,
169 const std::string& CommentStart = std::string(
"#"),
170 const std::string& CommentEnd = std::string(
"\n"),
171 const std::string& FieldSeparator = std::string(
" \t\n"));
177 inline GetPot(std::istream& FileStream,
178 const std::string& CommentStart = std::string(
"#"),
179 const std::string& CommentEnd = std::string(
"\n"),
180 const std::string& FieldSeparator = std::string(
" \t\n"));
188 const char* FieldSeparator =0x0);
190 const std::string& CommentStart=std::string(
"#"),
191 const std::string& CommentEnd=std::string(
"\n"),
192 const std::string& FieldSeparator=std::string(
" \t\n"));
195 const std::string& FileName=std::string(
"ParsedFromStream"),
196 const std::string& CommentStart=std::string(
"#"),
197 const std::string& CommentEnd=std::string(
"\n"),
198 const std::string& FieldSeparator=std::string(
" \t\n"));
215 inline const char*
operator[](
unsigned Idx)
const;
217 template <
typename T>
218 inline T
get(
unsigned Idx,
const T& Default)
const;
220 inline const char*
get(
unsigned Idx,
const char* Default)
const;
221 inline unsigned size()
const;
259 bool have_section(
const std::string& section_name)
const;
265 inline T
operator()(
const char* VarName,
const T& Default)
const;
268 inline T
operator()(
const std::string& VarName,
const T& Default)
const;
270 inline const char*
operator()(
const char* VarName,
const char* Default)
const;
271 inline const char*
operator()(
const std::string& VarName,
const char* Default)
const;
277 inline T
operator()(
const char* VarName,
const T& Default,
unsigned Idx)
const;
280 inline T
operator()(
const std::string& VarName,
const T& Default,
unsigned Idx)
const;
282 inline const char*
operator()(
const char* VarName,
const char* Default,
unsigned Idx)
const;
283 inline const char*
operator()(
const std::string& VarName,
const char* Default,
unsigned Idx)
const;
305 inline T
get_value_no_default(
const std::string& VarName,
const T& Default,
unsigned Idx)
const;
307 inline const char*
get_value_no_default(
const char* VarName,
const char* Default,
unsigned Idx)
const;
308 inline const char*
get_value_no_default(
const std::string& VarName,
const char* Default,
unsigned Idx)
const;
316 inline void set(
const char* VarName,
const T& Value,
const bool Requested =
true);
319 inline void set(
const std::string& VarName,
const T& Value,
const bool Requested =
true);
321 inline void set(
const char* VarName,
const char* Value,
const bool Requested =
true);
322 inline void set(
const std::string& VarName,
const char* Value,
const bool Requested =
true);
372 inline bool search(
const char* option);
373 inline bool search(
const std::string& option);
374 inline bool search(
unsigned No,
const char* P, ...);
380 inline T
next(
const T& Default);
382 inline const char*
next(
const char* Default);
388 inline T
follow(
const T& Default,
const char* Option);
390 inline const char*
follow(
const char* Default,
const char* Option);
396 inline T
follow(
const T& Default,
unsigned No,
const char* Option, ...);
398 inline const char*
follow(
const char* Default,
unsigned No,
const char* Option, ...);
404 inline T
direct_follow(
const T& Default,
const char* Option);
406 inline const char*
direct_follow(
const char* Default,
const char* Option);
461 inline int print(std::ostream &out_stream = std::cout)
const;
468 inline int print(
const char *custom_prefix,
469 std::ostream &out_stream = std::cout,
470 unsigned int skip_count=1)
const;
485 variable(
const char* Name,
const char* Value,
const char* FieldSeparator);
489 void take(
const char* Value,
const char* FieldSeparator);
495 const std::string*
get_element(
unsigned Idx)
const;
548 bool operator()(
const char* s1,
const char* s2)
const {
return strcmp(s1, s2) < 0; }
602 const std::string& Value,
603 const bool Requested);
635 inline bool _check_flags(
const std::string& Str,
const char* FlagList)
const;
641 inline T
_convert_to_type(
const std::string& String,
const T& Default)
const;
643 inline std::string
_convert_to_type(
const std::string& String,
const char* Default)
const;
654 const std::string& Start)
const;
659 const std::string& Str)
const;
673 inline const std::string
_get_string(std::istream& istr);
689 template <
typename T>
692 std::ostringstream out_string;
694 return out_string.str();
704 for (std::size_t pos = 0; pos != FullPath.size(); ++pos)
706 if (FullPath[pos] ==
'/')
707 result.push_back(FullPath.substr(0,pos));
757 #
if !defined(GETPOT_DISABLE_MUTEX)
760 _internal_string_container(),
761 _requested_arguments(),
762 _requested_variables(),
763 _requested_sections(),
764 request_recording_f()
773 const char* FieldSeparator ) :
788 #
if !defined(GETPOT_DISABLE_MUTEX)
791 _internal_string_container(),
792 _requested_arguments(),
793 _requested_variables(),
794 _requested_sections(),
795 request_recording_f()
805 const char* FieldSeparator )
821 _apriori_argv.push_back(std::string(argv_[0]));
822 for (
int i=1; i<argc_; i++)
824 std::string tmp(argv_[i]);
825 _apriori_argv.push_back(tmp);
834 const char* CommentStart ,
const char* CommentEnd ,
835 const char* FieldSeparator) :
849 #
if !defined(GETPOT_DISABLE_MUTEX)
852 _internal_string_container(),
853 _requested_arguments(),
854 _requested_variables(),
855 _requested_sections(),
856 request_recording_f()
858 const std::string& StrCommentStart = CommentStart ? CommentStart : std::string(
"#");
859 const std::string& StrCommentEnd = CommentEnd ? CommentEnd : std::string(
"\n");
860 const std::string& StrFieldSeparator = FieldSeparator ? FieldSeparator : std::string(
" \t\n");
861 this->
parse_input_file(FileName, StrCommentStart, StrCommentEnd, StrFieldSeparator);
868 const std::string& CommentStart,
869 const std::string& CommentEnd,
870 const std::string& FieldSeparator) :
884 #
if !defined(GETPOT_DISABLE_MUTEX)
887 _internal_string_container(),
888 _requested_arguments(),
889 _requested_variables(),
890 _requested_sections(),
891 request_recording_f()
898 const std::string& CommentStart,
899 const std::string& CommentEnd,
900 const std::string& FieldSeparator)
902 std::ifstream input(FileName.c_str());
905 getpot_file_error(FileName);
913 const std::string& CommentStart,
914 const std::string& CommentEnd,
915 const std::string& FieldSeparator) :
929 #
if !defined(GETPOT_DISABLE_MUTEX)
932 _internal_string_container(),
933 _requested_arguments(),
934 _requested_variables(),
935 _requested_sections(),
936 request_recording_f()
939 std::string(
"ParsedFromStream"),
940 CommentStart, CommentEnd, FieldSeparator);
946 const std::string& FileName,
947 const std::string& CommentStart,
948 const std::string& CommentEnd,
949 const std::string& FieldSeparator)
966 _apriori_argv.push_back(FileName);
969 _apriori_argv.insert(_apriori_argv.begin()+1, args.begin(), args.end());
977 prefix(Other.prefix),
978 section(Other.section),
979 section_list(Other.section_list),
981 cursor(Other.cursor),
982 search_loop_f(Other.search_loop_f),
983 search_failed_f(Other.search_failed_f),
985 nominus_cursor(Other.nominus_cursor),
986 idx_nominus(Other.idx_nominus),
987 variables(Other.variables),
988 _comment_start(Other._comment_start),
989 _comment_end(Other._comment_end),
990 _field_separator(Other._field_separator),
994 _internal_string_container(),
995 _requested_arguments(Other._requested_arguments),
996 _requested_variables(Other._requested_variables),
997 _requested_sections(Other._requested_sections),
998 request_recording_f(Other.request_recording_f)
1000 std::set<const char*,ltstr>::const_iterator it =
1003 const std::set<const char*,ltstr>::const_iterator
end =
1006 for (; it !=
end; ++it)
1008 const char* otherstr = *it;
1009 char* newcopy =
new char[strlen(otherstr)+1];
1010 strncpy(newcopy, otherstr, strlen(otherstr)+1);
1023 for (; it !=
end; ++it)
1057 std::set<const char*, ltstr>::const_iterator my_it =
1059 const std::set<const char*, ltstr>::const_iterator my_end =
1062 for (; my_it != my_end; ++my_it)
1067 std::set<const char*,ltstr>::const_iterator it =
1069 const std::set<const char*,ltstr>::const_iterator
end =
1072 for (; it !=
end; ++it)
1074 const char* otherstr = *it;
1075 const std::size_t bufsize = strlen(otherstr)+1;
1076 char* newcopy =
new char[bufsize];
1077 strncpy(newcopy, otherstr, bufsize);
1140 STRING_VECTOR::const_iterator it = ARGV.begin();
1150 argv.push_back(*it);
1154 for (; it != ARGV.end(); ++it)
1156 std::string arg = *it;
1158 if (arg.length() == 0)
1162 if (arg.length() > 1 && arg[0] ==
'[' && arg[arg.length()-1] ==
']')
1166 std::size_t include_pos = arg.find(
"include ", 1);
1167 if (include_pos != std::string::npos)
1170 const std::string includefile =
1193 argv.push_back(arg);
1199 argv.push_back(arg);
1207 const std::size_t equals_pos = arg.find_first_of(
'=');
1208 if (equals_pos != std::string::npos)
1225 arg.substr(equals_pos+1),
false);
1243 if (Token[0] == EOF)
1245 brute_tokens.push_back(Token);
1258 while (i1 < brute_tokens.size())
1264 if (i2 < brute_tokens.size() && brute_tokens[i2] ==
"=")
1266 if (i3 >= brute_tokens.size())
1267 result = brute_tokens[i1] + brute_tokens[i2];
1269 result = brute_tokens[i1] + brute_tokens[i2] + brute_tokens[i3];
1270 i1 = i3+1; i2 = i3+2; i3 = i3+3;
1272 else if (i2 < brute_tokens.size() &&
1273 brute_tokens[i2].length() > 0 &&
1274 brute_tokens[i2][0] ==
'=')
1278 result = brute_tokens[i1] + brute_tokens[i2];
1279 i1 = i3; i2 = i3+1; i3 = i3+2;
1281 else if (i2 < brute_tokens.size() && brute_tokens[i1][brute_tokens[i1].size()-1] ==
'=')
1283 result = brute_tokens[i1] + brute_tokens[i2];
1284 i1 = i3; i2 = i3+1; i3 = i3+2;
1288 result = brute_tokens[i1];
1294 if (comment_start_loc != std::string::npos)
1295 result = result.substr(0, comment_start_loc);
1297 arglist.push_back(result);
1308 int tmp = istr.get();
1311 while (isspace(tmp))
1335 unsigned match_no=0;
1366 inline const std::string
1375 int last_letter = tmp;
1382 token += getpot_cast_int<char>(tmp);
1386 else if (tmp == EOF || ((tmp ==
' ' || tmp ==
'\t' || tmp ==
'\n') && last_letter !=
'\\'))
1389 else if (tmp ==
'\'' && last_letter !=
'\\')
1396 else if (tmp ==
'{' && last_letter ==
'$')
1402 else if (tmp ==
'[')
1408 else if (tmp ==
'$' && last_letter ==
'\\')
1410 token += getpot_cast_int<char>(tmp); tmp = 0;
1414 else if (tmp ==
'\\' && last_letter !=
'\\')
1417 token += getpot_cast_int<char>(tmp);
1423 inline const std::string
1431 int last_letter = tmp;
1437 else if (tmp ==
'\'' && last_letter !=
'\\')
1440 else if (tmp ==
'\\' && last_letter !=
'\\')
1443 str += getpot_cast_int<char>(tmp);
1449 inline const std::string
1453 std::string str =
"";
1458 int last_letter = tmp;
1463 else if (tmp ==
'{' && last_letter ==
'$')
1466 else if (tmp ==
'}')
1473 else if (tmp ==
'\\' && last_letter !=
'\\')
1476 str += getpot_cast_int<char>(tmp);
1482 inline const std::string
1486 std::string str =
"";
1490 int tmp = istr.get();
1494 else if (tmp ==
'[')
1497 else if (tmp ==
']')
1504 str += getpot_cast_int<char>(tmp);
1514 std::string sname = Section;
1516 if (sname.length() >= 2 && sname.substr(0, 2) ==
"./")
1517 sname = sname.substr(2);
1520 else if (sname.length() >= 3 && sname.substr(0, 3) ==
"../")
1524 if (section_stack.end() != section_stack.begin())
1525 section_stack.pop_back();
1526 sname = sname.substr(3);
1527 }
while (sname.substr(0, 3) ==
"../");
1533 section_stack.erase(section_stack.begin(), section_stack.end());
1539 while (i < sname.length())
1541 if (sname[i] ==
'/')
1543 section_stack.push_back(sname.substr(0,i));
1544 if (i+1 < sname.length())
1545 sname = sname.substr(i+1);
1551 section_stack.push_back(sname);
1554 std::string section_label =
"";
1555 if (!section_stack.empty())
1557 victorate(std::string, section_stack, it)
1558 section_label += *it +
"/";
1560 return section_label;
1566 template <
typename T>
1570 std::istringstream in_string(String);
1572 in_string >> retval;
1573 if (in_string.fail())
1602 GetPot::_convert_to_type<bool>(
const std::string& String,
const bool & Default)
const 1604 std::string newstring(String);
1606 for (
unsigned int i=0; i<newstring.length(); ++i)
1607 newstring[i] = getpot_cast_int<char>(toupper(newstring[i]));
1610 if (newstring.find(
"TRUE")!=std::string::npos)
1613 if (newstring.find(
"FALSE")!=std::string::npos)
1619 std::istringstream in_string(String);
1620 unsigned int retval;
1621 in_string >> retval;
1622 if (in_string.fail())
1631 template <
typename T>
1635 std::istringstream in_string(String);
1637 in_string >> retval;
1638 if (in_string.fail())
1640 getpot_cerr <<
"ERROR: Input value for variable "<<VarName<<
" is of the wrong type."<<std::endl;
1641 getpot_cerr <<
" value = "<<String<<
" expected type = "<<
typeid(T).
name()<<std::endl;
1671 GetPot::_convert_to_type_no_default<bool>(
const char* VarName,
const std::string& String,
const bool &)
const 1673 std::string newstring(String);
1675 for (
unsigned int i=0; i<newstring.length(); ++i)
1677 newstring[i]=getpot_cast_int<char>(toupper(newstring[i]));
1681 if (newstring.find(
"TRUE")!=std::string::npos)
1684 if (newstring.find(
"FALSE")!=std::string::npos)
1690 std::istringstream in_string(String);
1691 unsigned int retval;
1692 in_string >> retval;
1693 if (in_string.fail())
1695 getpot_cerr <<
"ERROR: Input value for variable "<<VarName<<
" is of the wrong type."<<std::endl;
1696 getpot_cerr <<
" value = "<<String<<
" expected type = "<<
typeid(bool).
name()<<std::endl;
1708 const char* arg = Arg.c_str();
1714 std::set<const char*,ltstr>::const_iterator it =
1722 const std::size_t bufsize = strlen(arg)+1;
1723 char* newcopy =
new char[bufsize];
1724 strncpy(newcopy, arg, bufsize);
1737 inline const std::string
1745 if (String.find(Start) == 0)
1746 return String.substr(Start.length());
1758 return search(Option.c_str());
1767 unsigned OldCursor =
cursor;
1768 const std::string SearchTerm =
prefix + Option;
1773 if (OldCursor >=
argv.size())
1774 OldCursor = getpot_cast_int<unsigned>(
argv.size() - 1);
1778 for (
unsigned c =
cursor; c <
argv.size(); c++)
1780 if (
argv[c] == SearchTerm)
1791 for (
unsigned c = 1; c <= OldCursor; c++)
1793 if (
argv[c] == SearchTerm)
1824 char* Opt = va_arg(ap,
char *);
1838 char* Opt = va_arg(ap,
char *);
1883 template <
typename T>
1887 if (Idx >=
argv.size())
1895 GetPot::get(
unsigned int Idx,
const char* Default)
const 1897 if (Idx >=
argv.size())
1899 return argv[Idx].c_str();
1907 return getpot_cast_int<unsigned>(
argv.size());
1913 template <
typename T>
1922 cursor = getpot_cast_int<unsigned>(
argv.size());
1946 template <
typename T>
1951 if (
search(Option) ==
false)
1954 return next(Default);
1969 template <
typename T>
1978 return next(Default);
1982 for (
unsigned i=1; i<No; i++)
1984 char* Opt = va_arg(ap,
char *);
1988 return next(Default);
2005 return next(Default);
2009 for (
unsigned i=1; i<No; i++)
2011 char* Opt = va_arg(ap,
char *);
2015 return next(Default);
2028 template <
typename T>
2041 cursor = getpot_cast_int<unsigned>(
argv.size());
2062 getpot_cast_int<unsigned>(strlen(StartString));
2063 unsigned OldCursor =
cursor;
2065 if (OldCursor >=
argv.size())
2066 OldCursor = getpot_cast_int<unsigned>(
argv.size() - 1);
2070 for (
unsigned c =
cursor; c <
argv.size(); c++)
2072 if (strncmp(StartString,
argv[c].c_str(), N) == 0)
2076 return &(
argv[c].c_str()[N]);
2084 for (
unsigned c = 1; c < OldCursor; c++)
2086 if (strncmp(StartString,
argv[c].c_str(), N) == 0)
2090 return &(
argv[c].c_str()[N]);
2107 STRING_VECTOR::const_iterator it =
argv.begin();
2108 for (; it !=
argv.end(); ++it)
2112 if (str.length() >= 2 && str[0] ==
'-' && str[1] !=
'-')
2124 if (Idx >=
argv.size())
2138 unsigned no_matches = 0;
2139 for (
unsigned i=0; i<
argv.size(); i++)
2145 if (no_matches == Idx)
2159 for (
const char* p=FlagList; *p !=
'\0' ; p++)
2160 if (Str.find(*p) != std::string::npos)
2175 std::vector<unsigned>::const_iterator it =
idx_nominus.begin();
2178 nv.push_back(
argv[*it]);
2259 std::string s = std::string(section_name);
2266 const char slash(
'/');
2268 std::string::const_reverse_iterator it = section_name.rbegin();
2270 bool found_section =
false;
2274 if( (*it) != slash )
2281 return found_section;
2284 template <
typename T>
2299 template <
typename T>
2324 template <
typename T>
2333 const std::string* element = sv->
get_element(Idx);
2341 template <
typename T>
2345 return operator()(VarName.c_str(), Default, Idx);
2359 GetPot::operator()(
const std::string& VarName,
const char* Default,
unsigned int Idx)
const 2361 return operator()(VarName.c_str(), Default, Idx);
2366 template <
typename T>
2374 getpot_cerr <<
"ERROR: cannot find variable "<<VarName<<std::endl;
2382 template <
typename T>
2407 template <
typename T>
2415 getpot_cerr <<
"ERROR: cannot find variable "<<VarName<<std::endl;
2419 const std::string* element = sv->
get_element(Idx);
2422 getpot_cerr <<
"ERROR: cannot find index "<<Idx<<
" of variable "<<VarName<<std::endl;
2430 template <
typename T>
2469 victorate(std::string, STree, it)
2491 victorate(std::string, STree, it)
2503 const std::string& Value,
const bool Requested )
2519 template <
typename T>
2521 GetPot::set(
const char* VarName,
const T& Value,
const bool Requested )
2523 std::ostringstream string_value;
2524 string_value << Value;
2525 _set_variable(VarName, string_value.str().c_str(), Requested);
2530 template <
typename T>
2532 GetPot::set(
const std::string& VarName,
const T& Value,
const bool Requested )
2534 set(VarName.c_str(), Value, Requested);
2540 GetPot::set(
const char* VarName,
const char* Value,
const bool Requested )
2548 GetPot::set(
const std::string& VarName,
const char* Value,
const bool Requested )
2550 set(VarName.c_str(), Value, Requested);
2561 return (
unsigned)(sv->
value.size());
2578 std::vector<GetPot::variable>::const_iterator it =
variables.begin();
2583 result.push_back(Tmp);
2603 const std::string full_prefix =
2604 *sec_prefix.rbegin() ==
'/' ? sec_prefix : sec_prefix +
'/';
2606 const std::size_t full_prefix_len = full_prefix.size();
2612 std::set<std::string> subsections;
2616 for (STRING_VECTOR::const_iterator it =
section_list.begin();
2619 const std::string & section_name = *it;
2622 if (section_name.compare(0, full_prefix_len, full_prefix) == 0)
2624 const std::size_t next_slash_len =
2625 section_name.find(
'/', full_prefix_len);
2627 const std::string subsection_name =
2628 section_name.substr(full_prefix_len,
2629 next_slash_len - full_prefix_len);
2634 if (!subsection_name.empty() &&
2635 !subsections.count(subsection_name))
2637 returnval.push_back(subsection_name);
2638 subsections.insert(subsection_name);
2648 inline std::set<std::string>
2659 const std::string Name =
prefix + VarName;
2661 std::vector<variable>::const_iterator it =
variables.begin();
2664 if ((*it).name == Name)
2690 out_stream <<
"argc = " <<
argv.size() << std::endl;
2691 STRING_VECTOR::const_iterator it =
argv.begin();
2692 for (; it !=
argv.end(); ++it)
2693 out_stream << *it << std::endl;
2694 out_stream << std::endl;
2706 GetPot::print(
const char* custom_prefix, std::ostream &out_stream,
unsigned int skip_count)
const 2708 STRING_VECTOR::const_iterator it =
argv.begin();
2710 for (; it !=
argv.end(); ++it)
2712 out_stream << custom_prefix;
2713 out_stream << *it << std::endl;
2715 out_stream << std::endl;
2774 std::string new_string =
"";
2775 unsigned open_brackets = 0;
2777 for (
unsigned i = 0; i<str.size(); i++)
2779 if (i < str.size() - 2 && str.substr(i, 2) ==
"${")
2781 if (open_brackets == 0)
2785 else if (str[i] ==
'}' && open_brackets > 0)
2788 if (open_brackets == 0)
2790 const std::string Replacement =
_DBE_expand(str.substr(first, i - first));
2791 new_string += Replacement;
2794 else if (open_brackets == 0)
2795 new_string += str[i];
2807 std::string str = str_;
2813 for (; i < str.size(); i++)
2814 if (!isspace(str[i]))
2818 unsigned open_brackets = 0;
2819 std::vector<unsigned> start_idx;
2820 unsigned start_new_string = i;
2821 unsigned l = (unsigned)(str.size());
2826 const char letter = str[i];
2828 if (isspace(letter) && open_brackets == 0)
2830 expr_list.push_back(str.substr(start_new_string, i - start_new_string));
2831 bool no_breakout_f =
true;
2832 for (i++; i < l ; i++)
2834 if (!isspace(str[i]))
2836 no_breakout_f =
false;
2837 start_new_string = i;
2845 if (expr_list.size() < ExpectedNumber)
2847 const std::string pre_tmp(
"<< ${ }: missing arguments>>");
2848 STRING_VECTOR tmp(ExpectedNumber - expr_list.size(), pre_tmp);
2849 expr_list.insert(expr_list.end(), tmp.begin(), tmp.end());
2856 if (str.length() >= i+2 && str.substr(i, 2) ==
"${")
2859 start_idx.push_back(i+2);
2862 else if (letter ==
'}' && open_brackets > 0)
2864 int start = start_idx[start_idx.size()-1];
2865 start_idx.pop_back();
2866 const std::string Replacement =
_DBE_expand(str.substr(start, i-start));
2867 if (start - 3 < (
int)0)
2868 str = Replacement + str.substr(i+1);
2870 str = str.substr(0, start-2) + Replacement + str.substr(i+1);
2871 l = (int)(str.size());
2872 i = start + (int)(Replacement.size()) - 3;
2879 expr_list.push_back(str.substr(start_new_string, i-start_new_string));
2881 if (expr_list.size() < ExpectedNumber)
2883 const std::string pre_tmp(
"<< ${ }: missing arguments>>");
2884 STRING_VECTOR tmp(ExpectedNumber - expr_list.size(), pre_tmp);
2885 expr_list.insert(expr_list.end(), tmp.begin(), tmp.end());
2897 std::string secure_Prefix =
prefix;
2921 ev.
original += VarName +
"' undefined>>";
2932 return expr.substr(1);
2935 else if (expr[0] ==
'&')
2939 STRING_VECTOR::const_iterator it =
A.begin();
2940 std::string result = *it++;
2941 for (; it !=
A.end(); ++it) result += *it;
2947 else if (expr.length() >= 3 && expr.substr(0, 3) ==
"<->")
2951 const size_t L =
A[1].length();
2953 while ((tmp =
A[0].find(
A[1])) != std::string::npos)
2954 A[0].replace(tmp, L,
A[2]);
2960 else if (expr.length() >= 2 &&
2961 expr.substr(0, 1) ==
"=" &&
2962 expr.substr(0, 2) !=
"==")
2964 size_t funcnamestart = expr.find_first_not_of(
" \t", 1);
2965 if (funcnamestart != std::string::npos)
2967 size_t funcnameend = expr.find_first_of(
" \t",funcnamestart);
2968 std::string funcname = expr.substr(funcnamestart,
2969 funcnameend-funcnamestart);
2970 if (funcname ==
"log")
2977 else if (funcname ==
"log10")
2984 else if (funcname ==
"exp")
2991 else if (funcname ==
"sin")
2998 else if (funcname ==
"cos")
3005 else if (funcname ==
"tan")
3012 else if (funcname ==
"asin")
3019 else if (funcname ==
"acos")
3026 else if (funcname ==
"atan")
3033 else if (funcname ==
"atan2")
3041 else if (funcname ==
"sinh")
3048 else if (funcname ==
"cosh")
3055 else if (funcname ==
"tanh")
3062 #ifdef HAVE_INVERSE_HYPERBOLIC_SINE 3063 else if (funcname ==
"asinh")
3071 #ifdef HAVE_INVERSE_HYPERBOLIC_COSINE 3072 else if (funcname ==
"acosh")
3080 #ifdef HAVE_INVERSE_HYPERBOLIC_TANGENT 3081 else if (funcname ==
"atanh")
3089 else if (funcname ==
"sqrt")
3096 else if (funcname ==
"abs")
3103 else if (funcname ==
"max")
3107 STRING_VECTOR::const_iterator it =
A.begin();
3109 for (; it !=
A.end(); ++it)
3113 else if (funcname ==
"min")
3117 STRING_VECTOR::const_iterator it =
A.begin();
3119 for (; it !=
A.end(); ++it)
3123 else if (funcname ==
"ceil")
3130 else if (funcname ==
"floor")
3137 else if (funcname ==
"fmod")
3145 else if (funcname ==
"srand")
3154 else if (funcname ==
"rand")
3156 if (funcnameend >= expr.length() ||
3157 expr.find_first_not_of(
" \t", funcnameend) == std::string::npos)
3165 const unsigned int x = (RAND_MAX + 1u) / range;
3166 const unsigned int y = x * range;
3167 unsigned int returnval;
3171 }
while (returnval >= y);
3174 else if (funcname ==
"time")
3178 getpot_cerr <<
"ERROR: unrecognized function " 3179 << funcname << std::endl;
3186 else if (expr[0] ==
'+')
3189 STRING_VECTOR::const_iterator it =
A.begin();
3191 for (; it !=
A.end(); ++it)
3196 else if (expr[0] ==
'-')
3199 STRING_VECTOR::const_iterator it =
A.begin();
3201 for (; it !=
A.end(); ++it)
3206 else if (expr[0] ==
'*')
3209 STRING_VECTOR::const_iterator it =
A.begin();
3211 for (; it !=
A.end(); ++it)
3216 else if (expr[0] ==
'/')
3219 STRING_VECTOR::const_iterator it =
A.begin();
3224 for (; it !=
A.end(); ++it)
3233 else if (expr[0] ==
'^')
3236 STRING_VECTOR::const_iterator it =
A.begin();
3238 for (; it !=
A.end(); ++it)
3244 else if (expr.length() >= 2 &&
3245 (expr.substr(0,2) ==
"==" || expr.substr(0,2) ==
">=" ||
3246 expr.substr(0,2) ==
"<=" || expr[0] ==
'>' || expr[0] ==
'<'))
3250 enum { EQ, GEQ, LEQ, GT, LT };
3252 if (expr.substr(0, 2) ==
"==")
3255 else if (expr.substr(0, 2) ==
">=")
3258 else if (expr.substr(0, 2) ==
"<=")
3261 else if (expr[0] ==
'>')
3268 if (op == GT || op == LT)
3274 std::string x_orig = a[0];
3278 STRING_VECTOR::const_iterator y_orig = a.begin();
3279 for (y_orig++; y_orig != a.end(); ++y_orig)
3284 if (x == 1e37 || y == 1e37)
3287 if ((op == EQ && x_orig == *y_orig) || (op == GEQ && x_orig >= *y_orig) ||
3288 (op == LEQ && x_orig <= *y_orig) || (op == GT && x_orig > *y_orig) ||
3289 (op == LT && x_orig < *y_orig))
3295 if ((op == EQ && x == y) || (op == GEQ && x >= y) ||
3296 (op == LEQ && x <= y) || (op == GT && x > y) ||
3297 (op == LT && x < y))
3308 else if (expr.length() >= 2 && expr.substr(0, 2) ==
"??")
3314 if (x == 1e37 || x < 0 || x >=
double(a.size() - 1))
3315 return a[a.size()-1];
3318 return a[int(x+0.5)];
3322 else if (expr[0] ==
'?')
3329 else if (a.size() > 2)
3333 else if (expr[0] ==
'!')
3337 if (Var->
name ==
"")
3344 else if (expr.length() >= 2 && expr.substr(0,2) ==
"@:")
3350 if (x == 1e37 || x < 0 || x >=
double(
A[0].
size() - 1))
3351 return "<<1st index out of range>>";
3356 if (y != 1e37 && y > 0 && y <=
double(
A[0].
size() - 1) && y > x)
3357 return A[0].substr(
int(x+0.5),
int(y+1.5) -
int(x+0.5));
3360 return A[0].substr(
int(x+0.5));
3362 return "<<2nd index out of range>>";
3366 char* tmp =
new char[2];
3367 tmp[0] =
A[0][int(x+0.5)]; tmp[1] =
'\0';
3368 std::string result(tmp);
3374 else if (expr[0] ==
'@')
3379 if (Var->name ==
"")
3383 return std::string(Var->original);
3389 if (x == 1e37 || x < 0 || x >=
double(Var->value.size()))
3390 return "<<1st index out of range>>";
3395 int begin = int(x+0.5);
3397 if (y != 1e37 && y > 0 && y <=
double(Var->value.size()) && y > x)
3400 end = int(Var->value.size());
3402 return "<<2nd index out of range>>";
3404 std::string result = *(Var->get_element(begin));
3405 for (
int i = begin+1; i <
end; i++)
3406 result += std::string(
" ") + *(Var->get_element(i));
3410 return *(Var->get_element(
int(x+0.5)));
3435 victorate(std::string, VecStr, itk)
3447 const char* KnownArgument1, ...)
const 3449 std::set<std::string> known_arguments;
3456 va_start(ap, KnownArgument1);
3457 known_arguments.insert(std::string(KnownArgument1));
3458 for (
unsigned i=1; i<
Number; i++)
3459 known_arguments.insert(std::string(va_arg(ap,
char *)));
3489 STRING_VECTOR::const_iterator it =
argv.begin();
3491 for (; it !=
argv.end(); ++it)
3499 if (Knowns.find(arg) == Knowns.end())
3500 ufos.push_back(*it);
3509 const char* KnownOption1, ...)
const 3511 std::set<std::string> known_options;
3518 va_start(ap, KnownOption1);
3519 known_options.insert(std::string(KnownOption1));
3520 for (
unsigned i=1; i<
Number; i++)
3521 known_options.insert(std::string(va_arg(ap,
char *)));
3557 STRING_VECTOR::const_iterator it =
argv.begin();
3559 for (; it !=
argv.end(); ++it)
3567 if (arg.length() < 1 || arg[0] !=
'-')
3570 if (Knowns.find(arg) == Knowns.end())
3571 ufos.push_back(*it);
3588 std::string KFL(KnownFlagList);
3591 if (ArgumentNumber == -1)
3593 STRING_VECTOR::const_iterator it =
argv.begin();
3595 for (; it !=
argv.end(); ++it)
3599 if (arg ==
"")
continue;
3602 if (arg.length() < 2)
3605 else if (arg[0] !=
'-')
3608 else if (arg[1] ==
'-')
3612 const char* p=arg.c_str();
3614 for (; *p !=
'\0' ; p++)
3615 if (KFL.find(*p) == std::string::npos) ufos += *p;
3623 for (
unsigned i=1; i<
argv.size(); i++)
3629 if (no_matches == ArgumentNumber)
3633 const char* p = Remain.c_str();
3635 for (; *p !=
'\0' ; p++)
3636 if (KFL.find(*p) == std::string::npos) ufos += *p;
3649 const char* KnownVariable1, ...)
const 3651 std::set<std::string> known_variables;
3658 va_start(ap, KnownVariable1);
3659 known_variables.insert(std::string(KnownVariable1));
3660 for (
unsigned i=1; i<
Number; i++)
3661 known_variables.insert(std::string(va_arg(ap,
char *)));
3692 if (Knowns.find(var_name) == Knowns.end())
3693 ufos.push_back((*it).name);
3710 const char* KnownSection1, ...)
const 3712 std::set<std::string> known_sections;
3719 va_start(ap, KnownSection1);
3720 known_sections.insert(std::string(KnownSection1));
3721 for (
unsigned i=1; i<
Number; i++)
3723 std::string tmp = std::string(va_arg(ap,
char *));
3725 if (tmp.length() == 0)
3728 if (tmp[tmp.length()-1] !=
'/')
3731 known_sections.insert(tmp);
3771 if (Knowns.find(sec_name) == Knowns.end())
3772 ufos.push_back(*it);
3783 std::set<std::string> known_nominuses;
3790 va_start(ap, Known);
3791 known_nominuses.insert(std::string(Known));
3792 for (
unsigned i=1; i<
Number; i++)
3794 std::string tmp = std::string(va_arg(ap,
char *));
3795 if (tmp.length() == 0)
3797 known_nominuses.insert(tmp);
3837 STRING_VECTOR::const_iterator it =
argv.begin();
3839 for (; it !=
argv.end(); ++it)
3846 if (arg.length() < 1)
3854 if (arg[0] ==
'[' && arg[arg.length()-1] ==
']')
3858 bool continue_f =
false;
3859 for (
unsigned i=0; i<arg.length() ; i++)
3870 if (Knowns.find(arg) == Knowns.end())
3871 ufos.push_back(*it);
3882 std::set<std::string>
3891 std::set<std::string>
3900 std::set<std::string>
3938 take(Value, FieldSeparator);
3943 inline const std::string*
3946 if (Idx >=
value.size())
3949 return &(
value[Idx]);
3957 original = std::string(Value);
3982 std::string Value_str = std::string(Value);
3983 std::string delimiters = std::string(FieldSeparator);
3986 std::string::size_type lastPos = Value_str.find_first_not_of(delimiters, 0);
3989 std::string::size_type pos = Value_str.find_first_of(delimiters, lastPos);
3993 while (std::string::npos != pos || std::string::npos != lastPos)
3996 value.push_back(Value_str.substr(lastPos, pos - lastPos));
3999 lastPos = Value_str.find_first_not_of(delimiters, pos);
4002 pos = Value_str.find_first_of(delimiters, lastPos);
4026 #ifdef GETPOT_NAMESPACE 4032 #endif // LIBMESH_GETPOT_H std::string name(const ElemQuality q)
bool search_failed() const
bool argument_contains(unsigned Idx, const char *FlagList) const
STRING_VECTOR unidentified_variables() const
static STRING_VECTOR _get_section_tree(const std::string &FullPath)
T get_value_no_default(const char *VarName, const T &Default) const
const std::string _get_string(std::istream &istr)
bool _search_string_vector(const STRING_VECTOR &Vec, const std::string &Str) const
std::string _DBE_expand(const std::string &str)
std::set< std::string > get_requested_variables() const
bool have_section(const char *section_name) const
STRING_VECTOR _read_in_stream(std::istream &istr)
STRING_VECTOR get_variable_names() const
T _convert_to_type_no_default(const char *VarName, const std::string &String, const T &Default) const
void parse_input_file(const std::string &FileName, const std::string &CommentStart=std::string("#"), const std::string &CommentEnd=std::string("\), const std::string &FieldSeparator=std::string(" \\"))
STRING_VECTOR unidentified_nominuses() const
if(!eq) SETERRQ2(((PetscObject) dm) -> comm, PETSC_ERR_ARG_WRONG, "DM of type %s, not of type %s",((PetscObject) dm) ->type, DMLIBMESH)
const std::string _get_until_closing_bracket(std::istream &istr)
bool search(const char *option)
const variable * _find_variable(const char *) const
STRING_VECTOR unidentified_sections() const
static std::string _convert_from_type(const T &Value)
const std::string _get_until_closing_square_bracket(std::istream &istr)
bool operator()(const char *s1, const char *s2) const
STRING_VECTOR unidentified_arguments() const
unsigned nominus_size() const
variable & operator=(const variable &Other)
int print(std::ostream &out_stream=std::cout) const
const std::string * get_element(unsigned Idx) const
void _parse_argument_vector(const STRING_VECTOR &ARGV)
void set(const char *VarName, const T &Value, const bool Requested=true)
T follow(const T &Default, const char *Option)
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
long double max(long double a, double b)
void disable_request_recording()
const std::string _get_next_token(std::istream &istr)
std::vector< unsigned > idx_nominus
bool _check_flags(const std::string &Str, const char *FlagList) const
STRING_VECTOR get_subsection_names(const std::string §ion_name) const
STRING_VECTOR _DBE_get_expr_list(const std::string &str, const unsigned ExpectedNumber)
std::vector< variable > variables
T operator()(const char *VarName, const T &Default) const
GetPot & operator=(const GetPot &)
const char * _match_starting_string(const char *StartString)
T direct_follow(const T &Default, const char *Option)
unsigned vector_variable_size(const char *VarName) const
void absorb(const GetPot &Other)
void _basic_initialization()
std::set< std::string > get_overridden_variables() const
T _convert_to_type(const std::string &String, const T &Default) const
const char * _internal_managed_copy(const std::string &Arg) const
void parse_input_stream(std::istream &FileStream, const std::string &FileName=std::string("ParsedFromStream"), const std::string &CommentStart=std::string("#"), const std::string &CommentEnd=std::string("\), const std::string &FieldSeparator=std::string(" \\"))
std::set< std::string > _requested_sections
void _skip_whitespace(std::istream &istr)
double pow(double a, int b)
void enable_request_recording()
STRING_VECTOR nominus_vector() const
std::set< std::string > get_requested_sections() const
bool have_variable(const char *VarName) const
const char * next_nominus()
const GetPot::variable * _DBE_get_variable(const std::string &str)
void set_prefix(const char *Prefix)
STRING_VECTOR unidentified_options() const
void reset_nominus_cursor()
const variable * _request_variable(const char *) const
std::string next_nominus_string()
static PetscErrorCode Mat * A
void init_multiple_occurrence()
void _set_variable(const std::string &VarName, const std::string &Value, const bool Requested)
std::set< std::string > _requested_variables
std::string _process_section_label(const std::string &Section, STRING_VECTOR §ion_stack)
std::string _field_separator
void take(const char *Value, const char *FieldSeparator)
T get(unsigned Idx, const T &Default) const
void parse_command_line(const int argc_, const char *const *argv_, const char *FieldSeparator=0x0)
bool options_contain(const char *FlagList) const
STRING_VECTOR section_list
std::vector< std::string > STRING_VECTOR
const char * operator[](unsigned Idx) const
std::set< std::string > get_requested_arguments() const
std::string _comment_start
STRING_VECTOR get_section_names() const
long double min(long double a, double b)
std::string unidentified_flags(const char *Known, int ArgumentNumber) const
std::set< std::string > overridden_vars
std::set< std::string > _requested_arguments
void _record_argument_request(const std::string &Arg) const
void _record_variable_request(const std::string &Arg) const
std::string _DBE_expand_string(const std::string &str)
std::set< const char *, ltstr > _internal_string_container