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 63 #include "libmesh/libmesh_common.h" 70 #if !defined(GETPOT_DISABLE_MUTEX) 71 #include "libmesh/threads.h" 72 #define SCOPED_MUTEX libMesh::Threads::spin_mutex::scoped_lock lock(_getpot_mtx) 73 #define GETPOT_MUTEX_DECLARE mutable libMesh::Threads::spin_mutex _getpot_mtx 76 #define GETPOT_MUTEX_DECLARE 79 #define getpot_cerr libMesh::err 80 #define getpot_error() libmesh_error() 81 #define getpot_file_error(filename) libmesh_file_error(filename) 82 #define getpot_cast_int libMesh::cast_int 86 #ifdef LIBMESH_HAVE_CXX11_INVERSE_HYPERBOLIC_SINE 87 #define HAVE_INVERSE_HYPERBOLIC_SINE 90 #ifdef LIBMESH_HAVE_CXX11_INVERSE_HYPERBOLIC_COSINE 91 #define HAVE_INVERSE_HYPERBOLIC_COSINE 94 #ifdef LIBMESH_HAVE_CXX11_INVERSE_HYPERBOLIC_TANGENT 95 #define HAVE_INVERSE_HYPERBOLIC_TANGENT 101 #define GETPOT_DISABLE_MUTEX 103 #define GETPOT_MUTEX_DECLARE 105 #define getpot_cerr std::cerr 106 #define getpot_error() throw std::runtime_error(std::string("GetPot Error")) 107 #define getpot_file_error(filename) getpot_error() 108 #define getpot_cast_int static_cast 112 #ifndef __has_builtin 113 #define __has_builtin(x) 0 119 #if __cplusplus > 199711L && (!defined(__clang__) || __has_builtin(asinh)) 120 #define HAVE_INVERSE_HYPERBOLIC_SINE 123 #if __cplusplus > 199711L && (!defined(__clang__) || __has_builtin(acosh)) 124 #define HAVE_INVERSE_HYPERBOLIC_COSINE 127 #if __cplusplus > 199711L && (!defined(__clang__) || __has_builtin(atanh)) 128 #define HAVE_INVERSE_HYPERBOLIC_TANGENT 131 #endif // #ifdef USE_LIBMESH 136 #define victorate(TYPE, VARIABLE, ITERATOR) \ 137 std::vector<TYPE>::const_iterator ITERATOR = (VARIABLE).begin(); \ 138 for (; (ITERATOR) != (VARIABLE).end(); ++(ITERATOR)) 144 #ifdef GETPOT_NAMESPACE 165 inline GetPot(
const int argc_,
const char*
const* argv_,
166 const char* FieldSeparator=0x0);
167 inline GetPot(
const char* FileName,
168 const char* CommentStart=0x0,
const char* CommentEnd=0x0,
169 const char* FieldSeparator=0x0);
170 inline GetPot(
const std::string& FileName,
171 const std::string& CommentStart = std::string(
"#"),
172 const std::string& CommentEnd = std::string(
"\n"),
173 const std::string& FieldSeparator = std::string(
" \t\n"));
179 inline GetPot(std::istream& FileStream,
180 const std::string& CommentStart = std::string(
"#"),
181 const std::string& CommentEnd = std::string(
"\n"),
182 const std::string& FieldSeparator = std::string(
" \t\n"));
190 const char* FieldSeparator =0x0);
192 const std::string& CommentStart=std::string(
"#"),
193 const std::string& CommentEnd=std::string(
"\n"),
194 const std::string& FieldSeparator=std::string(
" \t\n"));
197 const std::string& FileName=std::string(
"ParsedFromStream"),
198 const std::string& CommentStart=std::string(
"#"),
199 const std::string& CommentEnd=std::string(
"\n"),
200 const std::string& FieldSeparator=std::string(
" \t\n"));
217 inline const char*
operator[](
unsigned Idx)
const;
219 template <
typename T>
220 inline T
get(
unsigned Idx,
const T& Default)
const;
222 inline const char*
get(
unsigned Idx,
const char* Default)
const;
223 inline unsigned size()
const;
261 bool have_section(
const std::string& section_name)
const;
267 inline T
operator()(
const char* VarName,
const T& Default)
const;
270 inline T
operator()(
const std::string& VarName,
const T& Default)
const;
272 inline const char*
operator()(
const char* VarName,
const char* Default)
const;
273 inline const char*
operator()(
const std::string& VarName,
const char* Default)
const;
279 inline T
operator()(
const char* VarName,
const T& Default,
unsigned Idx)
const;
282 inline T
operator()(
const std::string& VarName,
const T& Default,
unsigned Idx)
const;
284 inline const char*
operator()(
const char* VarName,
const char* Default,
unsigned Idx)
const;
285 inline const char*
operator()(
const std::string& VarName,
const char* Default,
unsigned Idx)
const;
307 inline T
get_value_no_default(
const std::string& VarName,
const T& Default,
unsigned Idx)
const;
309 inline const char*
get_value_no_default(
const char* VarName,
const char* Default,
unsigned Idx)
const;
310 inline const char*
get_value_no_default(
const std::string& VarName,
const char* Default,
unsigned Idx)
const;
318 inline void set(
const char* VarName,
const T& Value,
const bool Requested =
true);
321 inline void set(
const std::string& VarName,
const T& Value,
const bool Requested =
true);
323 inline void set(
const char* VarName,
const char* Value,
const bool Requested =
true);
324 inline void set(
const std::string& VarName,
const char* Value,
const bool Requested =
true);
374 inline bool search(
const char* option);
375 inline bool search(
const std::string& option);
376 inline bool search(
unsigned No,
const char* P, ...);
382 inline T
next(
const T& Default);
384 inline const char*
next(
const char* Default);
390 inline T
follow(
const T& Default,
const char* Option);
392 inline const char*
follow(
const char* Default,
const char* Option);
398 inline T
follow(
const T& Default,
unsigned No,
const char* Option, ...);
400 inline const char*
follow(
const char* Default,
unsigned No,
const char* Option, ...);
406 inline T
direct_follow(
const T& Default,
const char* Option);
408 inline const char*
direct_follow(
const char* Default,
const char* Option);
463 inline int print(std::ostream &out_stream = std::cout)
const;
470 inline int print(
const char *custom_prefix,
471 std::ostream &out_stream = std::cout,
472 unsigned int skip_count=1)
const;
487 variable(
const char* Name,
const char* Value,
const char* FieldSeparator);
491 void take(
const char* Value,
const char* FieldSeparator);
497 const std::string*
get_element(
unsigned Idx)
const;
568 const std::unique_ptr<
const char[]> & s2)
const 569 {
return strcmp(s1.get(), s2.get()) < 0; }
572 const char *
const & s2)
const 573 {
return strcmp(s1.get(), s2) < 0; }
576 const std::unique_ptr<
const char[]> & s2)
const 577 {
return strcmp(s1, s2.get()) < 0; }
623 const std::string& Value,
624 const bool Requested);
656 inline bool _check_flags(
const std::string& Str,
const char* FlagList)
const;
662 inline T
_convert_to_type(
const std::string& String,
const T& Default)
const;
664 inline std::string
_convert_to_type(
const std::string& String,
const char* Default)
const;
675 const std::string& Start)
const;
680 const std::string& Str)
const;
694 inline const std::string
_get_string(std::istream& istr);
710 template <
typename T>
713 std::ostringstream out_string;
715 return out_string.str();
725 for (std::size_t pos = 0; pos != FullPath.size(); ++pos)
727 if (FullPath[pos] ==
'/')
728 result.push_back(FullPath.substr(0,pos));
778 #
if !defined(GETPOT_DISABLE_MUTEX)
781 _internal_string_container(),
782 _requested_arguments(),
783 _requested_variables(),
784 _requested_sections(),
785 request_recording_f()
794 const char* FieldSeparator ) :
809 #
if !defined(GETPOT_DISABLE_MUTEX)
812 _internal_string_container(),
813 _requested_arguments(),
814 _requested_variables(),
815 _requested_sections(),
816 request_recording_f()
826 const char* FieldSeparator )
842 _apriori_argv.push_back(std::string(argv_[0]));
843 for (
int i=1; i<argc_; i++)
845 std::string tmp(argv_[i]);
846 _apriori_argv.push_back(tmp);
855 const char* CommentStart ,
const char* CommentEnd ,
856 const char* FieldSeparator) :
870 #
if !defined(GETPOT_DISABLE_MUTEX)
873 _internal_string_container(),
874 _requested_arguments(),
875 _requested_variables(),
876 _requested_sections(),
877 request_recording_f()
879 const std::string& StrCommentStart = CommentStart ? CommentStart : std::string(
"#");
880 const std::string& StrCommentEnd = CommentEnd ? CommentEnd : std::string(
"\n");
881 const std::string& StrFieldSeparator = FieldSeparator ? FieldSeparator : std::string(
" \t\n");
882 this->
parse_input_file(FileName, StrCommentStart, StrCommentEnd, StrFieldSeparator);
889 const std::string& CommentStart,
890 const std::string& CommentEnd,
891 const std::string& FieldSeparator) :
905 #
if !defined(GETPOT_DISABLE_MUTEX)
908 _internal_string_container(),
909 _requested_arguments(),
910 _requested_variables(),
911 _requested_sections(),
912 request_recording_f()
919 const std::string& CommentStart,
920 const std::string& CommentEnd,
921 const std::string& FieldSeparator)
923 std::ifstream input(FileName.c_str());
926 getpot_file_error(FileName);
934 const std::string& CommentStart,
935 const std::string& CommentEnd,
936 const std::string& FieldSeparator) :
950 #
if !defined(GETPOT_DISABLE_MUTEX)
953 _internal_string_container(),
954 _requested_arguments(),
955 _requested_variables(),
956 _requested_sections(),
957 request_recording_f()
960 std::string(
"ParsedFromStream"),
961 CommentStart, CommentEnd, FieldSeparator);
967 const std::string& FileName,
968 const std::string& CommentStart,
969 const std::string& CommentEnd,
970 const std::string& FieldSeparator)
987 _apriori_argv.push_back(FileName);
990 _apriori_argv.insert(_apriori_argv.begin()+1, args.begin(), args.end());
998 prefix(Other.prefix),
999 section(Other.section),
1000 section_list(Other.section_list),
1002 cursor(Other.cursor),
1003 search_loop_f(Other.search_loop_f),
1004 search_failed_f(Other.search_failed_f),
1006 nominus_cursor(Other.nominus_cursor),
1007 idx_nominus(Other.idx_nominus),
1008 variables(Other.variables),
1009 _comment_start(Other._comment_start),
1010 _comment_end(Other._comment_end),
1011 _field_separator(Other._field_separator),
1015 _internal_string_container(),
1016 _requested_arguments(Other._requested_arguments),
1017 _requested_variables(Other._requested_variables),
1018 _requested_sections(Other._requested_sections),
1019 request_recording_f(Other.request_recording_f)
1023 auto newlen = strlen(otherstr.get()) + 1;
1024 auto newcopy = std::make_unique<char[]>(newlen);
1025 strncpy(newcopy.get(), otherstr.get(), newlen);
1070 auto newlen = strlen(otherstr.get()) + 1;
1071 auto newcopy = std::make_unique<char[]>(newlen);
1072 strncpy(newcopy.get(), otherstr.get(), newlen);
1135 STRING_VECTOR::const_iterator it = ARGV.begin();
1145 argv.push_back(*it);
1149 for (; it != ARGV.end(); ++it)
1151 std::string arg = *it;
1153 if (arg.length() == 0)
1157 if (arg.length() > 1 && arg[0] ==
'[' && arg[arg.length()-1] ==
']')
1161 std::size_t include_pos = arg.find(
"include ", 1);
1162 if (include_pos != std::string::npos)
1165 const std::string includefile =
1188 argv.push_back(arg);
1194 argv.push_back(arg);
1202 const std::size_t equals_pos = arg.find_first_of(
'=');
1203 if (equals_pos != std::string::npos)
1220 arg.substr(equals_pos+1),
false);
1238 if (Token[0] == EOF)
1240 brute_tokens.push_back(Token);
1253 while (i1 < brute_tokens.size())
1259 if (i2 < brute_tokens.size() && brute_tokens[i2] ==
"=")
1261 if (i3 >= brute_tokens.size())
1262 result = brute_tokens[i1] + brute_tokens[i2];
1264 result = brute_tokens[i1] + brute_tokens[i2] + brute_tokens[i3];
1265 i1 = i3+1; i2 = i3+2; i3 = i3+3;
1267 else if (i2 < brute_tokens.size() &&
1268 brute_tokens[i2].length() > 0 &&
1269 brute_tokens[i2][0] ==
'=')
1273 result = brute_tokens[i1] + brute_tokens[i2];
1274 i1 = i3; i2 = i3+1; i3 = i3+2;
1276 else if (i2 < brute_tokens.size() && brute_tokens[i1][brute_tokens[i1].size()-1] ==
'=')
1278 result = brute_tokens[i1] + brute_tokens[i2];
1279 i1 = i3; i2 = i3+1; i3 = i3+2;
1283 result = brute_tokens[i1];
1289 if (comment_start_loc != std::string::npos)
1290 result = result.substr(0, comment_start_loc);
1292 arglist.push_back(result);
1303 int tmp = istr.get();
1306 while (std::isspace(tmp))
1330 unsigned match_no=0;
1361 inline const std::string
1370 int last_letter = tmp;
1377 token += getpot_cast_int<char>(tmp);
1381 else if (tmp == EOF || ((tmp ==
' ' || tmp ==
'\t' || tmp ==
'\n') && last_letter !=
'\\'))
1384 else if (tmp ==
'\'' && last_letter !=
'\\')
1391 else if (tmp ==
'{' && last_letter ==
'$')
1397 else if (tmp ==
'[')
1403 else if (tmp ==
'$' && last_letter ==
'\\')
1405 token += getpot_cast_int<char>(tmp); tmp = 0;
1409 else if (tmp ==
'\\' && last_letter !=
'\\')
1412 token += getpot_cast_int<char>(tmp);
1418 inline const std::string
1426 int last_letter = tmp;
1432 else if (tmp ==
'\'' && last_letter !=
'\\')
1435 else if (tmp ==
'\\' && last_letter !=
'\\')
1438 str += getpot_cast_int<char>(tmp);
1444 inline const std::string
1448 std::string str =
"";
1453 int last_letter = tmp;
1458 else if (tmp ==
'{' && last_letter ==
'$')
1461 else if (tmp ==
'}')
1468 else if (tmp ==
'\\' && last_letter !=
'\\')
1471 str += getpot_cast_int<char>(tmp);
1477 inline const std::string
1481 std::string str =
"";
1485 int tmp = istr.get();
1489 else if (tmp ==
'[')
1492 else if (tmp ==
']')
1499 str += getpot_cast_int<char>(tmp);
1509 std::string sname = Section;
1511 if (sname.length() >= 2 && sname.substr(0, 2) ==
"./")
1512 sname = sname.substr(2);
1515 else if (sname.length() >= 3 && sname.substr(0, 3) ==
"../")
1519 if (section_stack.end() != section_stack.begin())
1520 section_stack.pop_back();
1521 sname = sname.substr(3);
1522 }
while (sname.substr(0, 3) ==
"../");
1528 section_stack.erase(section_stack.begin(), section_stack.end());
1534 while (i < sname.length())
1536 if (sname[i] ==
'/')
1538 section_stack.push_back(sname.substr(0,i));
1539 if (i+1 < sname.length())
1540 sname = sname.substr(i+1);
1546 section_stack.push_back(sname);
1549 std::string section_label =
"";
1550 if (!section_stack.empty())
1552 victorate(std::string, section_stack, it)
1553 section_label += *it +
"/";
1555 return section_label;
1561 template <
typename T>
1565 std::istringstream in_string(String);
1567 in_string >> retval;
1568 if (in_string.fail())
1597 GetPot::_convert_to_type<bool>(
const std::string& String,
const bool & Default)
const 1599 std::string newstring(String);
1601 for (
unsigned int i=0; i<newstring.length(); ++i)
1602 newstring[i] = getpot_cast_int<char>(toupper(newstring[i]));
1605 if (newstring.find(
"TRUE")!=std::string::npos)
1608 if (newstring.find(
"FALSE")!=std::string::npos)
1614 std::istringstream in_string(String);
1615 unsigned int retval;
1616 in_string >> retval;
1617 if (in_string.fail())
1626 template <
typename T>
1630 std::istringstream in_string(String);
1632 in_string >> retval;
1633 if (in_string.fail())
1635 getpot_cerr <<
"ERROR: Input value for variable "<<VarName<<
" is of the wrong type."<<std::endl;
1636 getpot_cerr <<
" value = "<<String<<
" expected type = "<<
typeid(T).
name()<<std::endl;
1666 GetPot::_convert_to_type_no_default<bool>(
const char* VarName,
const std::string& String,
const bool &)
const 1668 std::string newstring(String);
1670 for (
unsigned int i=0; i<newstring.length(); ++i)
1672 newstring[i]=getpot_cast_int<char>(toupper(newstring[i]));
1676 if (newstring.find(
"TRUE")!=std::string::npos)
1679 if (newstring.find(
"FALSE")!=std::string::npos)
1685 std::istringstream in_string(String);
1686 unsigned int retval;
1687 in_string >> retval;
1688 if (in_string.fail())
1690 getpot_cerr <<
"ERROR: Input value for variable "<<VarName<<
" is of the wrong type."<<std::endl;
1691 getpot_cerr <<
" value = "<<String<<
" expected type = "<<
typeid(bool).
name()<<std::endl;
1703 const char* arg = Arg.c_str();
1715 const std::size_t bufsize = strlen(arg)+1;
1716 auto newcopy = std::make_unique<char[]>(bufsize);
1717 strncpy(newcopy.get(), arg, bufsize);
1719 return pr.first->get();
1730 inline const std::string
1738 if (String.find(Start) == 0)
1739 return String.substr(Start.length());
1751 return search(Option.c_str());
1760 unsigned OldCursor =
cursor;
1761 const std::string SearchTerm =
prefix + Option;
1766 if (OldCursor >=
argv.size())
1767 OldCursor = getpot_cast_int<unsigned>(
argv.size() - 1);
1771 for (
unsigned c =
cursor; c <
argv.size(); c++)
1773 if (
argv[c] == SearchTerm)
1784 for (
unsigned c = 1; c <= OldCursor; c++)
1786 if (
argv[c] == SearchTerm)
1817 char* Opt = va_arg(ap,
char *);
1831 char* Opt = va_arg(ap,
char *);
1876 template <
typename T>
1880 if (Idx >=
argv.size())
1888 GetPot::get(
unsigned int Idx,
const char* Default)
const 1890 if (Idx >=
argv.size())
1892 return argv[Idx].c_str();
1900 return getpot_cast_int<unsigned>(
argv.size());
1906 template <
typename T>
1915 cursor = getpot_cast_int<unsigned>(
argv.size());
1939 template <
typename T>
1944 if (
search(Option) ==
false)
1947 return next(Default);
1962 template <
typename T>
1971 return next(Default);
1975 for (
unsigned i=1; i<No; i++)
1977 char* Opt = va_arg(ap,
char *);
1981 return next(Default);
1998 return next(Default);
2002 for (
unsigned i=1; i<No; i++)
2004 char* Opt = va_arg(ap,
char *);
2008 return next(Default);
2021 template <
typename T>
2034 cursor = getpot_cast_int<unsigned>(
argv.size());
2055 getpot_cast_int<unsigned>(strlen(StartString));
2056 unsigned OldCursor =
cursor;
2058 if (OldCursor >=
argv.size())
2059 OldCursor = getpot_cast_int<unsigned>(
argv.size() - 1);
2063 for (
unsigned c =
cursor; c <
argv.size(); c++)
2065 if (strncmp(StartString,
argv[c].c_str(), N) == 0)
2069 return &(
argv[c].c_str()[N]);
2077 for (
unsigned c = 1; c < OldCursor; c++)
2079 if (strncmp(StartString,
argv[c].c_str(), N) == 0)
2083 return &(
argv[c].c_str()[N]);
2100 STRING_VECTOR::const_iterator it =
argv.begin();
2101 for (; it !=
argv.end(); ++it)
2105 if (str.length() >= 2 && str[0] ==
'-' && str[1] !=
'-')
2117 if (Idx >=
argv.size())
2131 unsigned no_matches = 0;
2132 for (
unsigned i=0; i<
argv.size(); i++)
2138 if (no_matches == Idx)
2152 for (
const char* p=FlagList; *p !=
'\0' ; p++)
2153 if (Str.find(*p) != std::string::npos)
2168 std::vector<unsigned>::const_iterator it =
idx_nominus.begin();
2171 nv.push_back(
argv[*it]);
2252 std::string s = std::string(section_name);
2259 const char slash(
'/');
2261 std::string::const_reverse_iterator it = section_name.rbegin();
2263 bool found_section =
false;
2267 if( (*it) != slash )
2274 return found_section;
2277 template <
typename T>
2292 template <
typename T>
2317 template <
typename T>
2326 const std::string* element = sv->
get_element(Idx);
2334 template <
typename T>
2338 return operator()(VarName.c_str(), Default, Idx);
2352 GetPot::operator()(
const std::string& VarName,
const char* Default,
unsigned int Idx)
const 2354 return operator()(VarName.c_str(), Default, Idx);
2359 template <
typename T>
2367 getpot_cerr <<
"ERROR: cannot find variable "<<VarName<<std::endl;
2375 template <
typename T>
2400 template <
typename T>
2408 getpot_cerr <<
"ERROR: cannot find variable "<<VarName<<std::endl;
2412 const std::string* element = sv->
get_element(Idx);
2415 getpot_cerr <<
"ERROR: cannot find index "<<Idx<<
" of variable "<<VarName<<std::endl;
2423 template <
typename T>
2462 victorate(std::string, STree, it)
2484 victorate(std::string, STree, it)
2496 const std::string& Value,
const bool Requested )
2512 template <
typename T>
2514 GetPot::set(
const char* VarName,
const T& Value,
const bool Requested )
2516 std::ostringstream string_value;
2517 string_value << Value;
2518 _set_variable(VarName, string_value.str().c_str(), Requested);
2523 template <
typename T>
2525 GetPot::set(
const std::string& VarName,
const T& Value,
const bool Requested )
2527 set(VarName.c_str(), Value, Requested);
2533 GetPot::set(
const char* VarName,
const char* Value,
const bool Requested )
2541 GetPot::set(
const std::string& VarName,
const char* Value,
const bool Requested )
2543 set(VarName.c_str(), Value, Requested);
2554 return (
unsigned)(sv->
value.size());
2571 std::vector<GetPot::variable>::const_iterator it =
variables.begin();
2576 result.push_back(Tmp);
2596 const std::string full_prefix =
2597 *sec_prefix.rbegin() ==
'/' ? sec_prefix : sec_prefix +
'/';
2599 const std::size_t full_prefix_len = full_prefix.size();
2605 std::set<std::string> subsections;
2609 for (STRING_VECTOR::const_iterator it =
section_list.begin();
2612 const std::string & section_name = *it;
2615 if (section_name.compare(0, full_prefix_len, full_prefix) == 0)
2617 const std::size_t next_slash_len =
2618 section_name.find(
'/', full_prefix_len);
2620 const std::string subsection_name =
2621 section_name.substr(full_prefix_len,
2622 next_slash_len - full_prefix_len);
2627 if (!subsection_name.empty() &&
2628 !subsections.count(subsection_name))
2630 returnval.push_back(subsection_name);
2631 subsections.insert(subsection_name);
2641 inline std::set<std::string>
2652 const std::string Name =
prefix + VarName;
2654 std::vector<variable>::const_iterator it =
variables.begin();
2657 if ((*it).name == Name)
2683 out_stream <<
"argc = " <<
argv.size() << std::endl;
2684 STRING_VECTOR::const_iterator it =
argv.begin();
2685 for (; it !=
argv.end(); ++it)
2686 out_stream << *it << std::endl;
2687 out_stream << std::endl;
2699 GetPot::print(
const char* custom_prefix, std::ostream &out_stream,
unsigned int skip_count)
const 2701 STRING_VECTOR::const_iterator it =
argv.begin();
2703 for (; it !=
argv.end(); ++it)
2705 out_stream << custom_prefix;
2706 out_stream << *it << std::endl;
2708 out_stream << std::endl;
2767 std::string new_string =
"";
2768 unsigned open_brackets = 0;
2770 for (
unsigned i = 0; i<str.size(); i++)
2772 if (i + 2 < str.size() && str.substr(i, 2) ==
"${")
2774 if (open_brackets == 0)
2778 else if (str[i] ==
'}' && open_brackets > 0)
2781 if (open_brackets == 0)
2783 const std::string Replacement =
_DBE_expand(str.substr(first, i - first));
2784 new_string += Replacement;
2787 else if (open_brackets == 0)
2788 new_string += str[i];
2800 std::string str = str_;
2806 for (; i < str.size(); i++)
2807 if (!std::isspace(str[i]))
2811 unsigned open_brackets = 0;
2812 std::vector<unsigned> start_idx;
2813 unsigned start_new_string = i;
2814 unsigned l = (unsigned)(str.size());
2819 const char letter = str[i];
2821 if (std::isspace(letter) && open_brackets == 0)
2823 expr_list.push_back(str.substr(start_new_string, i - start_new_string));
2824 bool no_breakout_f =
true;
2825 for (i++; i < l ; i++)
2827 if (!std::isspace(str[i]))
2829 no_breakout_f =
false;
2830 start_new_string = i;
2838 if (expr_list.size() < ExpectedNumber)
2840 const std::string pre_tmp(
"<< ${ }: missing arguments>>");
2841 STRING_VECTOR tmp(ExpectedNumber - expr_list.size(), pre_tmp);
2842 expr_list.insert(expr_list.end(), tmp.begin(), tmp.end());
2849 if (str.length() >= i+2 && str.substr(i, 2) ==
"${")
2852 start_idx.push_back(i+2);
2855 else if (letter ==
'}' && open_brackets > 0)
2857 int start = start_idx[start_idx.size()-1];
2858 start_idx.pop_back();
2859 const std::string Replacement =
_DBE_expand(str.substr(start, i-start));
2860 if (start - 3 < (
int)0)
2861 str = Replacement + str.substr(i+1);
2863 str = str.substr(0, start-2) + Replacement + str.substr(i+1);
2864 l = (
int)(str.size());
2865 i = start + (
int)(Replacement.size()) - 3;
2872 expr_list.push_back(str.substr(start_new_string, i-start_new_string));
2874 if (expr_list.size() < ExpectedNumber)
2876 const std::string pre_tmp(
"<< ${ }: missing arguments>>");
2877 STRING_VECTOR tmp(ExpectedNumber - expr_list.size(), pre_tmp);
2878 expr_list.insert(expr_list.end(), tmp.begin(), tmp.end());
2890 std::string secure_Prefix =
prefix;
2914 ev.
original += VarName +
"' undefined>>";
2925 return expr.substr(1);
2928 else if (expr[0] ==
'&')
2932 STRING_VECTOR::const_iterator it = A.begin();
2933 std::string result = *it++;
2934 for (; it != A.end(); ++it) result += *it;
2940 else if (expr.length() >= 3 && expr.substr(0, 3) ==
"<->")
2944 const size_t L = A[1].length();
2946 while ((tmp = A[0].find(A[1])) != std::string::npos)
2947 A[0].replace(tmp, L, A[2]);
2953 else if (expr.length() >= 2 &&
2954 expr.substr(0, 1) ==
"=" &&
2955 expr.substr(0, 2) !=
"==")
2957 size_t funcnamestart = expr.find_first_not_of(
" \t", 1);
2958 if (funcnamestart != std::string::npos)
2960 size_t funcnameend = expr.find_first_of(
" \t",funcnamestart);
2961 std::string funcname = expr.substr(funcnamestart,
2962 funcnameend-funcnamestart);
2963 if (funcname ==
"log")
2970 else if (funcname ==
"log10")
2977 else if (funcname ==
"exp")
2984 else if (funcname ==
"sin")
2991 else if (funcname ==
"cos")
2998 else if (funcname ==
"tan")
3005 else if (funcname ==
"asin")
3012 else if (funcname ==
"acos")
3019 else if (funcname ==
"atan")
3026 else if (funcname ==
"atan2")
3034 else if (funcname ==
"sinh")
3041 else if (funcname ==
"cosh")
3048 else if (funcname ==
"tanh")
3055 #ifdef HAVE_INVERSE_HYPERBOLIC_SINE 3056 else if (funcname ==
"asinh")
3064 #ifdef HAVE_INVERSE_HYPERBOLIC_COSINE 3065 else if (funcname ==
"acosh")
3073 #ifdef HAVE_INVERSE_HYPERBOLIC_TANGENT 3074 else if (funcname ==
"atanh")
3082 else if (funcname ==
"sqrt")
3089 else if (funcname ==
"abs")
3096 else if (funcname ==
"max")
3100 STRING_VECTOR::const_iterator it = A.begin();
3102 for (; it != A.end(); ++it)
3106 else if (funcname ==
"min")
3110 STRING_VECTOR::const_iterator it = A.begin();
3112 for (; it != A.end(); ++it)
3116 else if (funcname ==
"ceil")
3123 else if (funcname ==
"floor")
3130 else if (funcname ==
"fmod")
3138 else if (funcname ==
"srand")
3147 else if (funcname ==
"rand")
3149 if (funcnameend >= expr.length() ||
3150 expr.find_first_not_of(
" \t", funcnameend) == std::string::npos)
3158 const unsigned int x = (RAND_MAX + 1u) / range;
3159 const unsigned int y = x * range;
3160 unsigned int returnval;
3164 }
while (returnval >= y);
3167 else if (funcname ==
"time")
3171 getpot_cerr <<
"ERROR: unrecognized function " 3172 << funcname << std::endl;
3179 else if (expr[0] ==
'+')
3182 STRING_VECTOR::const_iterator it = A.begin();
3184 for (; it != A.end(); ++it)
3189 else if (expr[0] ==
'-')
3192 STRING_VECTOR::const_iterator it = A.begin();
3194 for (; it != A.end(); ++it)
3199 else if (expr[0] ==
'*')
3202 STRING_VECTOR::const_iterator it = A.begin();
3204 for (; it != A.end(); ++it)
3209 else if (expr[0] ==
'/')
3212 STRING_VECTOR::const_iterator it = A.begin();
3217 for (; it != A.end(); ++it)
3226 else if (expr[0] ==
'^')
3229 STRING_VECTOR::const_iterator it = A.begin();
3231 for (; it != A.end(); ++it)
3237 else if (expr.length() >= 2 &&
3238 (expr.substr(0,2) ==
"==" || expr.substr(0,2) ==
">=" ||
3239 expr.substr(0,2) ==
"<=" || expr[0] ==
'>' || expr[0] ==
'<'))
3243 enum { EQ, GEQ, LEQ, GT, LT };
3245 if (expr.substr(0, 2) ==
"==")
3248 else if (expr.substr(0, 2) ==
">=")
3251 else if (expr.substr(0, 2) ==
"<=")
3254 else if (expr[0] ==
'>')
3261 if (op == GT || op == LT)
3267 std::string x_orig = a[0];
3271 STRING_VECTOR::const_iterator y_orig = a.begin();
3272 for (y_orig++; y_orig != a.end(); ++y_orig)
3277 if (x == 1e37 || y == 1e37)
3280 if ((op == EQ && x_orig == *y_orig) || (op == GEQ && x_orig >= *y_orig) ||
3281 (op == LEQ && x_orig <= *y_orig) || (op == GT && x_orig > *y_orig) ||
3282 (op == LT && x_orig < *y_orig))
3288 if ((op == EQ && x == y) || (op == GEQ && x >= y) ||
3289 (op == LEQ && x <= y) || (op == GT && x > y) ||
3290 (op == LT && x < y))
3301 else if (expr.length() >= 2 && expr.substr(0, 2) ==
"??")
3307 if (x == 1e37 || x < 0 || x >=
double(a.size() - 1))
3308 return a[a.size()-1];
3311 return a[
int(x+0.5)];
3315 else if (expr[0] ==
'?')
3322 else if (a.size() > 2)
3326 else if (expr[0] ==
'!')
3330 if (Var->
name ==
"")
3337 else if (expr.length() >= 2 && expr.substr(0,2) ==
"@:")
3343 if (x == 1e37 || x < 0 || x >=
double(A[0].
size() - 1))
3344 return "<<1st index out of range>>";
3349 if (y != 1e37 && y > 0 && y <=
double(A[0].
size() - 1) && y > x)
3350 return A[0].substr(
int(x+0.5),
int(y+1.5) -
int(x+0.5));
3353 return A[0].substr(
int(x+0.5));
3355 return "<<2nd index out of range>>";
3359 char* tmp =
new char[2];
3360 tmp[0] = A[0][
int(x+0.5)]; tmp[1] =
'\0';
3361 std::string result(tmp);
3367 else if (expr[0] ==
'@')
3372 if (Var->name ==
"")
3376 return std::string(Var->original);
3382 if (x == 1e37 || x < 0 || x >=
double(Var->value.size()))
3383 return "<<1st index out of range>>";
3388 int begin =
int(x+0.5);
3390 if (y != 1e37 && y > 0 && y <=
double(Var->value.size()) && y > x)
3393 end =
int(Var->value.size());
3395 return "<<2nd index out of range>>";
3397 std::string result = *(Var->get_element(begin));
3398 for (
int i = begin+1; i < end; i++)
3399 result += std::string(
" ") + *(Var->get_element(i));
3403 return *(Var->get_element(
int(x+0.5)));
3412 return std::string(
B->original);
3428 victorate(std::string, VecStr, itk)
3440 const char* KnownArgument1, ...)
const 3442 std::set<std::string> known_arguments;
3449 va_start(ap, KnownArgument1);
3450 known_arguments.insert(std::string(KnownArgument1));
3451 for (
unsigned i=1; i<
Number; i++)
3452 known_arguments.insert(std::string(va_arg(ap,
char *)));
3482 STRING_VECTOR::const_iterator it =
argv.begin();
3484 for (; it !=
argv.end(); ++it)
3492 if (Knowns.find(arg) == Knowns.end())
3493 ufos.push_back(*it);
3502 const char* KnownOption1, ...)
const 3504 std::set<std::string> known_options;
3511 va_start(ap, KnownOption1);
3512 known_options.insert(std::string(KnownOption1));
3513 for (
unsigned i=1; i<
Number; i++)
3514 known_options.insert(std::string(va_arg(ap,
char *)));
3550 STRING_VECTOR::const_iterator it =
argv.begin();
3552 for (; it !=
argv.end(); ++it)
3560 if (arg.length() < 1 || arg[0] !=
'-')
3563 if (Knowns.find(arg) == Knowns.end())
3564 ufos.push_back(*it);
3581 std::string KFL(KnownFlagList);
3584 if (ArgumentNumber == -1)
3586 STRING_VECTOR::const_iterator it =
argv.begin();
3588 for (; it !=
argv.end(); ++it)
3592 if (arg ==
"")
continue;
3595 if (arg.length() < 2)
3598 else if (arg[0] !=
'-')
3601 else if (arg[1] ==
'-')
3605 const char* p=arg.c_str();
3607 for (; *p !=
'\0' ; p++)
3608 if (KFL.find(*p) == std::string::npos) ufos += *p;
3616 for (
unsigned i=1; i<
argv.size(); i++)
3622 if (no_matches == ArgumentNumber)
3626 const char* p = Remain.c_str();
3628 for (; *p !=
'\0' ; p++)
3629 if (KFL.find(*p) == std::string::npos) ufos += *p;
3642 const char* KnownVariable1, ...)
const 3644 std::set<std::string> known_variables;
3651 va_start(ap, KnownVariable1);
3652 known_variables.insert(std::string(KnownVariable1));
3653 for (
unsigned i=1; i<
Number; i++)
3654 known_variables.insert(std::string(va_arg(ap,
char *)));
3685 if (Knowns.find(var_name) == Knowns.end())
3686 ufos.push_back((*it).name);
3703 const char* KnownSection1, ...)
const 3705 std::set<std::string> known_sections;
3712 va_start(ap, KnownSection1);
3713 known_sections.insert(std::string(KnownSection1));
3714 for (
unsigned i=1; i<
Number; i++)
3716 std::string tmp = std::string(va_arg(ap,
char *));
3718 if (tmp.length() == 0)
3721 if (tmp[tmp.length()-1] !=
'/')
3724 known_sections.insert(tmp);
3764 if (Knowns.find(sec_name) == Knowns.end())
3765 ufos.push_back(*it);
3776 std::set<std::string> known_nominuses;
3783 va_start(ap, Known);
3784 known_nominuses.insert(std::string(Known));
3785 for (
unsigned i=1; i<
Number; i++)
3787 std::string tmp = std::string(va_arg(ap,
char *));
3788 if (tmp.length() == 0)
3790 known_nominuses.insert(tmp);
3830 STRING_VECTOR::const_iterator it =
argv.begin();
3832 for (; it !=
argv.end(); ++it)
3839 if (arg.length() < 1)
3847 if (arg[0] ==
'[' && arg[arg.length()-1] ==
']')
3851 bool continue_f =
false;
3852 for (
unsigned i=0; i<arg.length() ; i++)
3863 if (Knowns.find(arg) == Knowns.end())
3864 ufos.push_back(*it);
3875 std::set<std::string>
3884 std::set<std::string>
3893 std::set<std::string>
3931 take(Value, FieldSeparator);
3936 inline const std::string*
3939 if (Idx >=
value.size())
3942 return &(
value[Idx]);
3950 original = std::string(Value);
3975 std::string Value_str = std::string(Value);
3976 std::string delimiters = std::string(FieldSeparator);
3979 std::string::size_type lastPos = Value_str.find_first_not_of(delimiters, 0);
3982 std::string::size_type pos = Value_str.find_first_of(delimiters, lastPos);
3986 while (std::string::npos != pos || std::string::npos != lastPos)
3989 value.push_back(Value_str.substr(lastPos, pos - lastPos));
3992 lastPos = Value_str.find_first_not_of(delimiters, pos);
3995 pos = Value_str.find_first_of(delimiters, lastPos);
4019 #ifdef GETPOT_NAMESPACE 4025 #endif // LIBMESH_GETPOT_H std::string name(const ElemQuality q)
This function returns a string containing some name for q.
bool search_failed() const
GETPOT_MUTEX_DECLARE
we have some mutable non-thread-safe members, but we want to be able to call const member functions f...
bool argument_contains(unsigned Idx, const char *FlagList) const
STRING_VECTOR unidentified_variables() const
static STRING_VECTOR _get_section_tree(const std::string &FullPath)
cuts a variable name into a tree of sub-sections.
int nominus_cursor
nominus vector
T get_value_no_default(const char *VarName, const T &Default) const
access variables, but error out if not present scalar values
const std::string _get_string(std::istream &istr)
void is_transparent
As of C++14, std::set::find() can be a templated overload.
bool _search_string_vector(const STRING_VECTOR &Vec, const std::string &Str) const
search for a specific string
std::string _DBE_expand(const std::string &str)
std::set< std::string > get_requested_variables() const
void disable_loop()
enable/disable search for an option in loop
void reset_cursor()
reset cursor to position '1'
bool have_section(const char *section_name) const
Check for a section name.
STRING_VECTOR _read_in_stream(std::istream &istr)
Variable to be specified on the command line or in input files.
STRING_VECTOR get_variable_names() const
variable()
constructors, destructors, assignment operator
std::string name
data members
T _convert_to_type_no_default(const char *VarName, const std::string &String, const T &Default) const
Transparent comparator object used for making std::sets that contain unique_ptrs. ...
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
const std::string _get_until_closing_bracket(std::istream &istr)
bool search(const char *option)
search for a certain option and set cursor to position
const variable * _find_variable(const char *) const
helpers for argument list processing
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)
STRING_VECTOR unidentified_arguments() const
unsigned nominus_size() const
variable & operator=(const variable &Other)
int print(std::ostream &out_stream=std::cout) const
output
const std::string * get_element(unsigned Idx) const
get a specific element in the string vector (return 0 if not present)
void _parse_argument_vector(const STRING_VECTOR &ARGV)
produce three basic data vectors:
void set(const char *VarName, const T &Value, const bool Requested=true)
setting variables i) from outside of GetPot (considering prefix etc.) ii) from inside, use '_set_variable()' below
T follow(const T &Default, const char *Option)
search for option and get argument at cursor++
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
prefix extraction
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
support search for flags in a specific argument
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::string prefix
member variables
std::vector< variable > variables
variables (arguments of the form "variable=value")
T operator()(const char *VarName, const T &Default) const
scalar values
bool operator()(const std::unique_ptr< const char[]> &s1, const std::unique_ptr< const char[]> &s2) const
GetPot & operator=(const GetPot &)
const char * _match_starting_string(const char *StartString)
support finding directly followed arguments
T direct_follow(const T &Default, const char *Option)
directly followed arguments
unsigned vector_variable_size(const char *VarName) const
GetPot - A class for parsing command line arguments and configuration files.
GetPot()
constructors, destructor, assignment operator
void absorb(const GetPot &Other)
absorbing contents of another GetPot object
void _basic_initialization()
std::set< std::unique_ptr< const char[]>, ltstr > _internal_string_container
some functions return a char pointer to a string created on the fly.
std::set< std::string > get_overridden_variables() const
T _convert_to_type(const std::string &String, const T &Default) const
type conversion if possible
const char * _internal_managed_copy(const std::string &Arg) const
some functions return a char pointer to a temporarily existing string this function adds them to our ...
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)
helpers to parse input file create an argument vector based on data found in an input file...
STRING_VECTOR argv
argument vector
void enable_request_recording()
STRING_VECTOR nominus_vector() const
std::set< std::string > get_requested_sections() const
bool have_variable(const char *VarName) const
variables
const char * next_nominus()
const GetPot::variable * _DBE_get_variable(const std::string &str)
void set_prefix(const char *Prefix)
cursor oriented functions
STRING_VECTOR unidentified_options() const
void reset_nominus_cursor()
nominus arguments
const variable * _request_variable(const char *) const
search (and record request) for a variable in 'variables' array
void clear_requests()
for ufo detection: recording requested arguments, options etc.
std::string next_nominus_string()
void init_multiple_occurrence()
void _set_variable(const std::string &VarName, const std::string &Value, const bool Requested)
helper functions
std::set< std::string > _requested_variables
std::string _process_section_label(const std::string &Section, STRING_VECTOR §ion_stack)
bool operator()(const char *const &s1, const std::unique_ptr< const char[]> &s2) const
std::string _field_separator
field separator (separating elements of a vector)
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)
Re-initialization methods.
bool options_contain(const char *FlagList) const
flags
STRING_VECTOR section_list
std::vector< std::string > STRING_VECTOR
const char * operator[](unsigned Idx) const
direct access to command line arguments
std::set< std::string > get_requested_arguments() const
Accessors for requested variables.
T next(const T &Default)
get argument at cursor++
std::string _comment_start
comment delimiters
STRING_VECTOR get_section_names() const
std::string unidentified_flags(const char *Known, int ArgumentNumber) const
void ErrorVector unsigned int
std::set< std::string > overridden_vars
std::set< std::string > _requested_arguments
keeping track about arguments that are requested, so that the UFO detection can be simplified ...
void _record_argument_request(const std::string &Arg) const
if an argument is requested record it and the 'tag' the section branch to which it belongs...
void _record_variable_request(const std::string &Arg) const
bool operator()(const std::unique_ptr< const char[]> &s1, const char *const &s2) const
std::string _DBE_expand_string(const std::string &str)
dollar bracket expressions