28 #ifndef QUESO_GETPOT_H
29 #define QUESO_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
60 #include "libmesh/libmesh_common.h"
67 #if !defined(GETPOT_DISABLE_MUTEX)
68 #include "libmesh/threads.h"
69 #define SCOPED_MUTEX libMesh::Threads::spin_mutex::scoped_lock lock(_getpot_mtx)
70 #define GETPOT_MUTEX_DECLARE mutable libMesh::Threads::spin_mutex _getpot_mtx
73 #define GETPOT_MUTEX_DECLARE
76 #define getpot_cerr libMesh::err
77 #define getpot_error() libmesh_error()
78 #define getpot_file_error(filename) libmesh_file_error(filename)
79 #define getpot_cast_int libMesh::cast_int
83 #ifdef LIBMESH_HAVE_CXX11_INVERSE_HYPERBOLIC_SINE
84 #define HAVE_INVERSE_HYPERBOLIC_SINE
87 #ifdef LIBMESH_HAVE_CXX11_INVERSE_HYPERBOLIC_COSINE
88 #define HAVE_INVERSE_HYPERBOLIC_COSINE
91 #ifdef LIBMESH_HAVE_CXX11_INVERSE_HYPERBOLIC_TANGENT
92 #define HAVE_INVERSE_HYPERBOLIC_TANGENT
98 #define GETPOT_DISABLE_MUTEX
100 #define GETPOT_MUTEX_DECLARE
102 #define getpot_cerr std::cerr
103 #define getpot_error() throw std::runtime_error(std::string("GetPot Error"))
104 #define getpot_file_error(filename) getpot_error()
105 #define getpot_cast_int static_cast
109 #ifndef __has_builtin
110 #define __has_builtin(x) 0
116 #if __cplusplus > 199711L && (!defined(__clang__) || __has_builtin(asinh))
117 #define HAVE_INVERSE_HYPERBOLIC_SINE
120 #if __cplusplus > 199711L && (!defined(__clang__) || __has_builtin(acosh))
121 #define HAVE_INVERSE_HYPERBOLIC_COSINE
124 #if __cplusplus > 199711L && (!defined(__clang__) || __has_builtin(atanh))
125 #define HAVE_INVERSE_HYPERBOLIC_TANGENT
128 #endif // #ifdef USE_LIBMESH
133 #define victorate(TYPE, VARIABLE, ITERATOR) \
134 std::vector<TYPE>::const_iterator ITERATOR = (VARIABLE).begin(); \
135 for (; (ITERATOR) != (VARIABLE).end(); ++(ITERATOR))
141 #ifdef GETPOT_NAMESPACE
142 namespace GETPOT_NAMESPACE {
162 inline GetPot(
const int argc_,
const char*
const* argv_,
163 const char* FieldSeparator=0x0);
164 inline GetPot(
const char* FileName,
165 const char* CommentStart=0x0,
const char* CommentEnd=0x0,
166 const char* FieldSeparator=0x0);
167 inline GetPot(
const std::string& FileName,
168 const std::string& CommentStart = std::string(
"#"),
169 const std::string& CommentEnd = std::string(
"\n"),
170 const std::string& FieldSeparator = std::string(
" \t\n"));
176 inline GetPot(std::istream& FileStream,
177 const std::string& CommentStart = std::string(
"#"),
178 const std::string& CommentEnd = std::string(
"\n"),
179 const std::string& FieldSeparator = std::string(
" \t\n"));
187 const char* FieldSeparator =0x0);
189 const std::string& CommentStart=std::string(
"#"),
190 const std::string& CommentEnd=std::string(
"\n"),
191 const std::string& FieldSeparator=std::string(
" \t\n"));
194 const std::string& FileName=std::string(
"ParsedFromStream"),
195 const std::string& CommentStart=std::string(
"#"),
196 const std::string& CommentEnd=std::string(
"\n"),
197 const std::string& FieldSeparator=std::string(
" \t\n"));
214 inline const char*
operator[](
unsigned Idx)
const;
216 template <
typename T>
217 inline T
get(
unsigned Idx,
const T& Default)
const;
219 inline const char*
get(
unsigned Idx,
const char* Default)
const;
220 inline unsigned size()
const;
258 bool have_section(
const std::string& section_name)
const;
264 inline T
operator()(
const char* VarName,
const T& Default)
const;
267 inline T
operator()(
const std::string& VarName,
const T& Default)
const;
269 inline const char*
operator()(
const char* VarName,
const char* Default)
const;
270 inline const char*
operator()(
const std::string& VarName,
const char* Default)
const;
276 inline T
operator()(
const char* VarName,
const T& Default,
unsigned Idx)
const;
279 inline T
operator()(
const std::string& VarName,
const T& Default,
unsigned Idx)
const;
281 inline const char*
operator()(
const char* VarName,
const char* Default,
unsigned Idx)
const;
282 inline const char*
operator()(
const std::string& VarName,
const char* Default,
unsigned Idx)
const;
304 inline T
get_value_no_default(
const std::string& VarName,
const T& Default,
unsigned Idx)
const;
306 inline const char*
get_value_no_default(
const char* VarName,
const char* Default,
unsigned Idx)
const;
307 inline const char*
get_value_no_default(
const std::string& VarName,
const char* Default,
unsigned Idx)
const;
315 inline void set(
const char* VarName,
const T& Value,
const bool Requested =
true);
318 inline void set(
const std::string& VarName,
const T& Value,
const bool Requested =
true);
320 inline void set(
const char* VarName,
const char* Value,
const bool Requested =
true);
321 inline void set(
const std::string& VarName,
const char* Value,
const bool Requested =
true);
350 inline bool search(
const char* option);
351 inline bool search(
const std::string& option);
352 inline bool search(
unsigned No,
const char* P, ...);
358 inline T
next(
const T& Default);
360 inline const char*
next(
const char* Default);
366 inline T
follow(
const T& Default,
const char* Option);
368 inline const char*
follow(
const char* Default,
const char* Option);
374 inline T
follow(
const T& Default,
unsigned No,
const char* Option, ...);
376 inline const char*
follow(
const char* Default,
unsigned No,
const char* Option, ...);
382 inline T
direct_follow(
const T& Default,
const char* Option);
384 inline const char*
direct_follow(
const char* Default,
const char* Option);
439 inline int print(std::ostream &out_stream = std::cout)
const;
446 inline int print(
const char *custom_prefix,
447 std::ostream &out_stream = std::cout,
448 unsigned int skip_count=1)
const;
463 variable(
const char* Name,
const char* Value,
const char* FieldSeparator);
467 void take(
const char* Value,
const char* FieldSeparator);
473 const std::string*
get_element(
unsigned Idx)
const;
526 bool operator()(
const char* s1,
const char* s2)
const {
return strcmp(s1, s2) < 0; }
580 const std::string& Value,
581 const bool Requested);
613 inline bool _check_flags(
const std::string& Str,
const char* FlagList)
const;
619 inline T
_convert_to_type(
const std::string& String,
const T& Default)
const;
621 inline std::string
_convert_to_type(
const std::string& String,
const char* Default)
const;
632 const std::string& Start)
const;
637 const std::string& Str)
const;
651 inline const std::string
_get_string(std::istream& istr);
667 template <
typename T>
670 std::ostringstream out_string;
672 return out_string.str();
682 for (std::size_t pos = 0; pos != FullPath.size(); ++pos)
684 if (FullPath[pos] ==
'/')
685 result.push_back(FullPath.substr(0,pos));
735 #
if !defined(GETPOT_DISABLE_MUTEX)
738 _internal_string_container(),
739 _requested_arguments(),
740 _requested_variables(),
741 _requested_sections(),
742 request_recording_f()
751 const char* FieldSeparator ) :
766 #
if !defined(GETPOT_DISABLE_MUTEX)
769 _internal_string_container(),
770 _requested_arguments(),
771 _requested_variables(),
772 _requested_sections(),
773 request_recording_f()
783 const char* FieldSeparator )
799 _apriori_argv.push_back(std::string(argv_[0]));
800 for (
int i=1; i<argc_; i++)
802 std::string tmp(argv_[i]);
803 _apriori_argv.push_back(tmp);
812 const char* CommentStart ,
const char* CommentEnd ,
813 const char* FieldSeparator) :
827 #
if !defined(GETPOT_DISABLE_MUTEX)
830 _internal_string_container(),
831 _requested_arguments(),
832 _requested_variables(),
833 _requested_sections(),
834 request_recording_f()
836 const std::string& StrCommentStart = CommentStart ? CommentStart : std::string(
"#");
837 const std::string& StrCommentEnd = CommentEnd ? CommentEnd : std::string(
"\n");
838 const std::string& StrFieldSeparator = FieldSeparator ? FieldSeparator : std::string(
" \t\n");
839 this->
parse_input_file(FileName, StrCommentStart, StrCommentEnd, StrFieldSeparator);
846 const std::string& CommentStart,
847 const std::string& CommentEnd,
848 const std::string& FieldSeparator) :
862 #
if !defined(GETPOT_DISABLE_MUTEX)
865 _internal_string_container(),
866 _requested_arguments(),
867 _requested_variables(),
868 _requested_sections(),
869 request_recording_f()
876 const std::string& CommentStart,
877 const std::string& CommentEnd,
878 const std::string& FieldSeparator)
880 std::ifstream input(FileName.c_str());
883 getpot_file_error(FileName);
891 const std::string& CommentStart,
892 const std::string& CommentEnd,
893 const std::string& FieldSeparator) :
907 #
if !defined(GETPOT_DISABLE_MUTEX)
910 _internal_string_container(),
911 _requested_arguments(),
912 _requested_variables(),
913 _requested_sections(),
914 request_recording_f()
917 std::string(
"ParsedFromStream"),
918 CommentStart, CommentEnd, FieldSeparator);
924 const std::string& FileName,
925 const std::string& CommentStart,
926 const std::string& CommentEnd,
927 const std::string& FieldSeparator)
944 _apriori_argv.push_back(FileName);
947 _apriori_argv.insert(_apriori_argv.begin()+1, args.begin(), args.end());
955 prefix(Other.prefix),
956 section(Other.section),
957 section_list(Other.section_list),
959 cursor(Other.cursor),
960 search_loop_f(Other.search_loop_f),
961 search_failed_f(Other.search_failed_f),
963 nominus_cursor(Other.nominus_cursor),
964 idx_nominus(Other.idx_nominus),
965 variables(Other.variables),
966 _comment_start(Other._comment_start),
967 _comment_end(Other._comment_end),
968 _field_separator(Other._field_separator),
972 _internal_string_container(),
973 _requested_arguments(Other._requested_arguments),
974 _requested_variables(Other._requested_variables),
975 _requested_sections(Other._requested_sections),
976 request_recording_f(Other.request_recording_f)
978 std::set<const char*,ltstr>::const_iterator
it =
981 const std::set<const char*,ltstr>::const_iterator end =
984 for (; it != end; ++
it)
986 const char* otherstr = *
it;
987 char* newcopy =
new char[strlen(otherstr)+1];
988 strncpy(newcopy, otherstr, strlen(otherstr)+1);
1001 for (; it != end; ++
it)
1035 std::set<const char*, ltstr>::const_iterator my_it =
1037 const std::set<const char*, ltstr>::const_iterator my_end =
1040 for (; my_it != my_end; ++my_it)
1045 std::set<const char*,ltstr>::const_iterator
it =
1047 const std::set<const char*,ltstr>::const_iterator end =
1050 for (; it != end; ++
it)
1052 const char* otherstr = *
it;
1053 char* newcopy =
new char[strlen(otherstr)+1];
1054 strncpy(newcopy, otherstr, strlen(otherstr)+1);
1117 STRING_VECTOR::const_iterator
it = ARGV.begin();
1127 argv.push_back(*it);
1131 for (; it != ARGV.end(); ++
it)
1133 std::string arg = *
it;
1135 if (arg.length() == 0)
1139 if (arg.length() > 1 && arg[0] ==
'[' && arg[arg.length()-1] ==
']')
1143 std::size_t include_pos = arg.find(
"include ", 1);
1144 if (include_pos != std::string::npos)
1147 const std::string includefile =
1170 argv.push_back(arg);
1176 argv.push_back(arg);
1184 const std::size_t equals_pos = arg.find_first_of(
'=');
1185 if (equals_pos != std::string::npos)
1202 arg.substr(equals_pos+1),
false);
1220 if (Token[0] == EOF)
1222 brute_tokens.push_back(Token);
1235 while (i1 < brute_tokens.size())
1241 if (i2 < brute_tokens.size() && brute_tokens[i2] ==
"=")
1243 if (i3 >= brute_tokens.size())
1244 result = brute_tokens[i1] + brute_tokens[i2];
1246 result = brute_tokens[i1] + brute_tokens[i2] + brute_tokens[i3];
1247 i1 = i3+1; i2 = i3+2; i3 = i3+3;
1249 else if (i2 < brute_tokens.size() &&
1250 brute_tokens[i2].length() > 0 &&
1251 brute_tokens[i2][0] ==
'=')
1255 result = brute_tokens[i1] + brute_tokens[i2];
1256 i1 = i3; i2 = i3+1; i3 = i3+2;
1258 else if (i2 < brute_tokens.size() && brute_tokens[i1][brute_tokens[i1].size()-1] ==
'=')
1260 result = brute_tokens[i1] + brute_tokens[i2];
1261 i1 = i3; i2 = i3+1; i3 = i3+2;
1265 result = brute_tokens[i1];
1271 if (comment_start_loc != std::string::npos)
1272 result = result.substr(0, comment_start_loc);
1274 arglist.push_back(result);
1285 int tmp = istr.get();
1288 while (isspace(tmp))
1312 unsigned match_no=0;
1343 inline const std::string
1352 int last_letter = tmp;
1359 token += getpot_cast_int<char>(tmp);
1363 else if (tmp == EOF || ((tmp ==
' ' || tmp ==
'\t' || tmp ==
'\n') && last_letter !=
'\\'))
1366 else if (tmp ==
'\'' && last_letter !=
'\\')
1373 else if (tmp ==
'{' && last_letter ==
'$')
1379 else if (tmp ==
'[')
1385 else if (tmp ==
'$' && last_letter ==
'\\')
1387 token += getpot_cast_int<char>(tmp); tmp = 0;
1391 else if (tmp ==
'\\' && last_letter !=
'\\')
1394 token += getpot_cast_int<char>(tmp);
1400 inline const std::string
1408 int last_letter = tmp;
1414 else if (tmp ==
'\'' && last_letter !=
'\\')
1417 else if (tmp ==
'\\' && last_letter !=
'\\')
1420 str += getpot_cast_int<char>(tmp);
1426 inline const std::string
1430 std::string str =
"";
1435 int last_letter = tmp;
1440 else if (tmp ==
'{' && last_letter ==
'$')
1443 else if (tmp ==
'}')
1450 else if (tmp ==
'\\' && last_letter !=
'\\')
1453 str += getpot_cast_int<char>(tmp);
1459 inline const std::string
1463 std::string str =
"";
1467 int tmp = istr.get();
1471 else if (tmp ==
'[')
1474 else if (tmp ==
']')
1481 str += getpot_cast_int<char>(tmp);
1493 if (sname.length() >= 2 && sname.substr(0, 2) ==
"./")
1494 sname = sname.substr(2);
1497 else if (sname.length() >= 3 && sname.substr(0, 3) ==
"../")
1501 if (section_stack.end() != section_stack.begin())
1502 section_stack.pop_back();
1503 sname = sname.substr(3);
1504 }
while (sname.substr(0, 3) ==
"../");
1510 section_stack.erase(section_stack.begin(), section_stack.end());
1516 while (i < sname.length())
1518 if (sname[i] ==
'/')
1520 section_stack.push_back(sname.substr(0,i));
1521 if (i+1 < sname.length())
1522 sname = sname.substr(i+1);
1528 section_stack.push_back(sname);
1531 std::string section_label =
"";
1532 if (!section_stack.empty())
1534 victorate(std::string, section_stack,
it)
1535 section_label += *
it +
"/";
1537 return section_label;
1543 template <
typename T>
1547 std::istringstream in_string(String);
1549 in_string >> retval;
1550 if (in_string.fail())
1579 GetPot::_convert_to_type<bool>(
const std::string& String,
const bool & Default)
const
1581 std::string newstring(String);
1583 for (
unsigned int i=0; i<newstring.length(); ++i)
1584 newstring[i] = getpot_cast_int<char>(toupper(newstring[i]));
1587 if (newstring.find(
"TRUE")!=std::string::npos)
1590 if (newstring.find(
"FALSE")!=std::string::npos)
1596 std::istringstream in_string(String);
1597 unsigned int retval;
1598 in_string >> retval;
1599 if (in_string.fail())
1608 template <
typename T>
1612 std::istringstream in_string(String);
1614 in_string >> retval;
1615 if (in_string.fail())
1617 getpot_cerr <<
"ERROR: Input value for variable "<<VarName<<
" is of the wrong type."<<std::endl;
1618 getpot_cerr <<
" value = "<<String<<
" expected type = "<<
typeid(T).name()<<std::endl;
1648 GetPot::_convert_to_type_no_default<bool>(
const char* VarName,
const std::string& String,
const bool &)
const
1650 std::string newstring(String);
1652 for (
unsigned int i=0; i<newstring.length(); ++i)
1654 newstring[i]=getpot_cast_int<char>(toupper(newstring[i]));
1658 if (newstring.find(
"TRUE")!=std::string::npos)
1661 if (newstring.find(
"FALSE")!=std::string::npos)
1667 std::istringstream in_string(String);
1668 unsigned int retval;
1669 in_string >> retval;
1670 if (in_string.fail())
1672 getpot_cerr <<
"ERROR: Input value for variable "<<VarName<<
" is of the wrong type."<<std::endl;
1673 getpot_cerr <<
" value = "<<String<<
" expected type = "<<
typeid(bool).name()<<std::endl;
1685 const char* arg = Arg.c_str();
1691 std::set<const char*,ltstr>::const_iterator
it =
1699 char* newcopy =
new char[strlen(arg)+1];
1700 strncpy(newcopy, arg, strlen(arg)+1);
1713 inline const std::string
1721 if (String.find(Start) == 0)
1722 return String.substr(Start.length());
1734 return search(Option.c_str());
1743 unsigned OldCursor =
cursor;
1744 const std::string SearchTerm =
prefix + Option;
1749 if (OldCursor >=
argv.size())
1750 OldCursor = getpot_cast_int<unsigned>(
argv.size() - 1);
1754 for (
unsigned c =
cursor; c <
argv.size(); c++)
1756 if (
argv[c] == SearchTerm)
1767 for (
unsigned c = 1; c < OldCursor; c++)
1769 if (
argv[c] == SearchTerm)
1800 char* Opt = va_arg(ap,
char *);
1814 char* Opt = va_arg(ap,
char *);
1854 return idx<
argv.size() ?
argv[idx].c_str() : 0;
1859 template <
typename T>
1863 if (Idx >=
argv.size())
1871 GetPot::get(
unsigned int Idx,
const char* Default)
const
1873 if (Idx >=
argv.size())
1875 return argv[Idx].c_str();
1883 return getpot_cast_int<unsigned>(
argv.size());
1889 template <
typename T>
1898 cursor = getpot_cast_int<unsigned>(
argv.size());
1922 template <
typename T>
1927 if (
search(Option) ==
false)
1930 return next(Default);
1945 template <
typename T>
1954 return next(Default);
1958 for (
unsigned i=1; i<No; i++)
1960 char* Opt = va_arg(ap,
char *);
1964 return next(Default);
1981 return next(Default);
1985 for (
unsigned i=1; i<No; i++)
1987 char* Opt = va_arg(ap,
char *);
1991 return next(Default);
2004 template <
typename T>
2017 cursor = getpot_cast_int<unsigned>(
argv.size());
2038 getpot_cast_int<unsigned>(strlen(StartString));
2039 unsigned OldCursor =
cursor;
2041 if (OldCursor >=
argv.size())
2042 OldCursor = getpot_cast_int<unsigned>(
argv.size() - 1);
2046 for (
unsigned c =
cursor; c <
argv.size(); c++)
2048 if (strncmp(StartString,
argv[c].c_str(), N) == 0)
2052 return &(
argv[c].c_str()[N]);
2060 for (
unsigned c = 1; c < OldCursor; c++)
2062 if (strncmp(StartString,
argv[c].c_str(), N) == 0)
2066 return &(
argv[c].c_str()[N]);
2083 STRING_VECTOR::const_iterator
it =
argv.begin();
2084 for (; it !=
argv.end(); ++
it)
2088 if (str.length() >= 2 && str[0] ==
'-' && str[1] !=
'-')
2100 if (Idx >=
argv.size())
2114 unsigned no_matches = 0;
2115 for (
unsigned i=0; i<
argv.size(); i++)
2121 if (no_matches == Idx)
2135 for (
const char* p=FlagList; *p !=
'\0' ; p++)
2136 if (Str.find(*p) != std::string::npos)
2151 std::vector<unsigned>::const_iterator
it =
idx_nominus.begin();
2154 nv.push_back(
argv[*it]);
2235 std::string s = std::string(section_name);
2242 const char slash(
'/');
2244 std::string::const_reverse_iterator
it = section_name.rbegin();
2246 bool found_section =
false;
2250 if( (*it) != slash )
2257 return found_section;
2260 template <
typename T>
2275 template <
typename T>
2300 template <
typename T>
2309 const std::string* element = sv->
get_element(Idx);
2317 template <
typename T>
2321 return operator()(VarName.c_str(), Default, Idx);
2335 GetPot::operator()(
const std::string& VarName,
const char* Default,
unsigned int Idx)
const
2337 return operator()(VarName.c_str(), Default, Idx);
2342 template <
typename T>
2350 getpot_cerr <<
"ERROR: cannot find variable "<<VarName<<std::endl;
2358 template <
typename T>
2383 template <
typename T>
2391 getpot_cerr <<
"ERROR: cannot find variable "<<VarName<<std::endl;
2395 const std::string* element = sv->
get_element(Idx);
2398 getpot_cerr <<
"ERROR: cannot find index "<<Idx<<
" of variable "<<VarName<<std::endl;
2406 template <
typename T>
2445 victorate(std::string, STree,
it)
2467 victorate(std::string, STree,
it)
2479 const std::string& Value,
const bool Requested )
2495 template <
typename T>
2497 GetPot::set(
const char* VarName,
const T& Value,
const bool Requested )
2499 std::ostringstream string_value;
2500 string_value << Value;
2501 _set_variable(VarName, string_value.str().c_str(), Requested);
2506 template <
typename T>
2508 GetPot::set(
const std::string& VarName,
const T& Value,
const bool Requested )
2510 set(VarName.c_str(), Value, Requested);
2516 GetPot::set(
const char* VarName,
const char* Value,
const bool Requested )
2524 GetPot::set(
const std::string& VarName,
const char* Value,
const bool Requested )
2526 set(VarName.c_str(), Value, Requested);
2537 return (
unsigned)(sv->
value.size());
2554 std::vector<GetPot::variable>::const_iterator
it =
variables.begin();
2559 result.push_back(Tmp);
2574 inline std::set<std::string>
2585 const std::string Name =
prefix + VarName;
2587 std::vector<variable>::const_iterator
it =
variables.begin();
2590 if ((*it).name == Name)
2616 out_stream <<
"argc = " <<
argv.size() << std::endl;
2617 STRING_VECTOR::const_iterator
it =
argv.begin();
2618 for (; it !=
argv.end(); ++
it)
2619 out_stream << *it << std::endl;
2620 out_stream << std::endl;
2632 GetPot::print(
const char* custom_prefix, std::ostream &out_stream,
unsigned int skip_count)
const
2634 STRING_VECTOR::const_iterator
it =
argv.begin();
2636 for (; it !=
argv.end(); ++
it)
2638 out_stream << custom_prefix;
2639 out_stream << *it << std::endl;
2641 out_stream << std::endl;
2700 std::string new_string =
"";
2701 unsigned open_brackets = 0;
2703 for (
unsigned i = 0; i<str.size(); i++)
2705 if (i < str.size() - 2 && str.substr(i, 2) ==
"${")
2707 if (open_brackets == 0)
2711 else if (str[i] ==
'}' && open_brackets > 0)
2714 if (open_brackets == 0)
2716 const std::string Replacement =
_DBE_expand(str.substr(first, i - first));
2717 new_string += Replacement;
2720 else if (open_brackets == 0)
2721 new_string += str[i];
2733 std::string str = str_;
2739 for (; i < str.size(); i++)
2740 if (!isspace(str[i]))
2744 unsigned open_brackets = 0;
2745 std::vector<unsigned> start_idx;
2746 unsigned start_new_string = i;
2747 unsigned l = (unsigned)(str.size());
2752 const char letter = str[i];
2754 if (isspace(letter) && open_brackets == 0)
2756 expr_list.push_back(str.substr(start_new_string, i - start_new_string));
2757 bool no_breakout_f =
true;
2758 for (i++; i < l ; i++)
2760 if (!isspace(str[i]))
2762 no_breakout_f =
false;
2763 start_new_string = i;
2771 if (expr_list.size() < ExpectedNumber)
2773 const std::string pre_tmp(
"<< ${ }: missing arguments>>");
2774 STRING_VECTOR tmp(ExpectedNumber - expr_list.size(), pre_tmp);
2775 expr_list.insert(expr_list.end(), tmp.begin(), tmp.end());
2782 if (str.length() >= i+2 && str.substr(i, 2) ==
"${")
2785 start_idx.push_back(i+2);
2788 else if (letter ==
'}' && open_brackets > 0)
2790 int start = start_idx[start_idx.size()-1];
2791 start_idx.pop_back();
2792 const std::string Replacement =
_DBE_expand(str.substr(start, i-start));
2793 if (start - 3 < (
int)0)
2794 str = Replacement + str.substr(i+1);
2796 str = str.substr(0, start-2) + Replacement + str.substr(i+1);
2797 l = (int)(str.size());
2798 i = start + (int)(Replacement.size()) - 3;
2805 expr_list.push_back(str.substr(start_new_string, i-start_new_string));
2807 if (expr_list.size() < ExpectedNumber)
2809 const std::string pre_tmp(
"<< ${ }: missing arguments>>");
2810 STRING_VECTOR tmp(ExpectedNumber - expr_list.size(), pre_tmp);
2811 expr_list.insert(expr_list.end(), tmp.begin(), tmp.end());
2823 std::string secure_Prefix =
prefix;
2847 ev.
original += VarName +
"' undefined>>";
2858 return expr.substr(1);
2861 else if (expr[0] ==
'&')
2865 STRING_VECTOR::const_iterator
it = A.begin();
2866 std::string result = *it++;
2867 for (; it != A.end(); ++
it) result += *it;
2873 else if (expr.length() >= 3 && expr.substr(0, 3) ==
"<->")
2877 const size_t L = A[1].length();
2879 while ((tmp = A[0].find(A[1])) != std::string::npos)
2880 A[0].replace(tmp, L, A[2]);
2886 else if (expr.length() >= 2 &&
2887 expr.substr(0, 1) ==
"=" &&
2888 expr.substr(0, 2) !=
"==")
2890 size_t funcnamestart = expr.find_first_not_of(
" \t", 1);
2891 if (funcnamestart != std::string::npos)
2893 size_t funcnameend = expr.find_first_of(
" \t",funcnamestart);
2894 std::string funcname = expr.substr(funcnamestart,
2895 funcnameend-funcnamestart);
2896 if (funcname ==
"log")
2903 else if (funcname ==
"log10")
2910 else if (funcname ==
"exp")
2917 else if (funcname ==
"sin")
2924 else if (funcname ==
"cos")
2931 else if (funcname ==
"tan")
2938 else if (funcname ==
"asin")
2945 else if (funcname ==
"acos")
2952 else if (funcname ==
"atan")
2959 else if (funcname ==
"atan2")
2967 else if (funcname ==
"sinh")
2974 else if (funcname ==
"cosh")
2981 else if (funcname ==
"tanh")
2988 #ifdef HAVE_INVERSE_HYPERBOLIC_SINE
2989 else if (funcname ==
"asinh")
2997 #ifdef HAVE_INVERSE_HYPERBOLIC_COSINE
2998 else if (funcname ==
"acosh")
3006 #ifdef HAVE_INVERSE_HYPERBOLIC_TANGENT
3007 else if (funcname ==
"atanh")
3015 else if (funcname ==
"sqrt")
3022 else if (funcname ==
"abs")
3029 else if (funcname ==
"max")
3033 STRING_VECTOR::const_iterator
it = A.begin();
3035 for (; it != A.end(); ++
it)
3039 else if (funcname ==
"min")
3043 STRING_VECTOR::const_iterator
it = A.begin();
3045 for (; it != A.end(); ++
it)
3049 else if (funcname ==
"ceil")
3056 else if (funcname ==
"floor")
3063 else if (funcname ==
"fmod")
3071 else if (funcname ==
"srand")
3080 else if (funcname ==
"rand")
3082 if (funcnameend >= expr.length() ||
3083 expr.find_first_not_of(
" \t", funcnameend) == std::string::npos)
3091 const unsigned int x = (RAND_MAX + 1u) / range;
3092 const unsigned int y = x * range;
3093 unsigned int returnval;
3097 }
while (returnval >= y);
3100 else if (funcname ==
"time")
3104 getpot_cerr <<
"ERROR: unrecognized function "
3105 << funcname << std::endl;
3112 else if (expr[0] ==
'+')
3115 STRING_VECTOR::const_iterator
it = A.begin();
3117 for (; it != A.end(); ++
it)
3122 else if (expr[0] ==
'-')
3125 STRING_VECTOR::const_iterator
it = A.begin();
3127 for (; it != A.end(); ++
it)
3132 else if (expr[0] ==
'*')
3135 STRING_VECTOR::const_iterator
it = A.begin();
3137 for (; it != A.end(); ++
it)
3142 else if (expr[0] ==
'/')
3145 STRING_VECTOR::const_iterator
it = A.begin();
3150 for (; it != A.end(); ++
it)
3159 else if (expr[0] ==
'^')
3162 STRING_VECTOR::const_iterator
it = A.begin();
3164 for (; it != A.end(); ++
it)
3170 else if (expr.length() >= 2 &&
3171 (expr.substr(0,2) ==
"==" || expr.substr(0,2) ==
">=" ||
3172 expr.substr(0,2) ==
"<=" || expr[0] ==
'>' || expr[0] ==
'<'))
3176 enum { EQ, GEQ, LEQ, GT, LT };
3178 if (expr.substr(0, 2) ==
"==")
3181 else if (expr.substr(0, 2) ==
">=")
3184 else if (expr.substr(0, 2) ==
"<=")
3187 else if (expr[0] ==
'>')
3194 if (op == GT || op == LT)
3200 std::string x_orig = a[0];
3204 STRING_VECTOR::const_iterator y_orig = a.begin();
3205 for (y_orig++; y_orig != a.end(); ++y_orig)
3210 if (x == 1e37 || y == 1e37)
3213 if ((op == EQ && x_orig == *y_orig) || (op == GEQ && x_orig >= *y_orig) ||
3214 (op == LEQ && x_orig <= *y_orig) || (op == GT && x_orig > *y_orig) ||
3215 (op == LT && x_orig < *y_orig))
3221 if ((op == EQ && x == y) || (op == GEQ && x >= y) ||
3222 (op == LEQ && x <= y) || (op == GT && x > y) ||
3223 (op == LT && x < y))
3234 else if (expr.length() >= 2 && expr.substr(0, 2) ==
"??")
3240 if (x == 1e37 || x < 0 || x >= a.size() - 1)
3241 return a[a.size()-1];
3244 return a[int(x+0.5)];
3248 else if (expr[0] ==
'?')
3255 else if (a.size() > 2)
3259 else if (expr[0] ==
'!')
3263 if (Var->
name ==
"")
3270 else if (expr.length() >= 2 && expr.substr(0,2) ==
"@:")
3276 if (x == 1e37 || x < 0 || x >= A[0].
size() - 1)
3277 return "<<1st index out of range>>";
3282 if (y != 1e37 && y > 0 && y <= A[0].
size() - 1 && y > x)
3283 return A[0].substr(
int(x+0.5),
int(y+1.5) -
int(x+0.5));
3286 return A[0].substr(
int(x+0.5));
3288 return "<<2nd index out of range>>";
3292 char* tmp =
new char[2];
3293 tmp[0] = A[0][int(x+0.5)]; tmp[1] =
'\0';
3294 std::string result(tmp);
3300 else if (expr[0] ==
'@')
3305 if (Var->name ==
"")
3309 return std::string(Var->original);
3315 if (x == 1e37 || x < 0 || x >= Var->value.size())
3316 return "<<1st index out of range>>";
3321 int begin = int(x+0.5);
3323 if (y != 1e37 && y > 0 && y <= Var->value.size() && y > x)
3326 end = int(Var->value.size());
3328 return "<<2nd index out of range>>";
3330 std::string result = *(Var->get_element(begin));
3331 for (
int i = begin+1; i < end; i++)
3332 result += std::string(
" ") + *(Var->get_element(i));
3336 return *(Var->get_element(
int(x+0.5)));
3361 victorate(std::string, VecStr, itk)
3373 const char* KnownArgument1, ...)
const
3375 std::set<std::string> known_arguments;
3382 va_start(ap, KnownArgument1);
3383 known_arguments.insert(std::string(KnownArgument1));
3384 for (
unsigned i=1; i<Number; i++)
3385 known_arguments.insert(std::string(va_arg(ap,
char *)));
3415 STRING_VECTOR::const_iterator
it =
argv.begin();
3417 for (; it !=
argv.end(); ++
it)
3425 if (Knowns.find(arg) == Knowns.end())
3426 ufos.push_back(*it);
3435 const char* KnownOption1, ...)
const
3437 std::set<std::string> known_options;
3444 va_start(ap, KnownOption1);
3445 known_options.insert(std::string(KnownOption1));
3446 for (
unsigned i=1; i<Number; i++)
3447 known_options.insert(std::string(va_arg(ap,
char *)));
3483 STRING_VECTOR::const_iterator
it =
argv.begin();
3485 for (; it !=
argv.end(); ++
it)
3493 if (arg.length() < 1 || arg[0] !=
'-')
3496 if (Knowns.find(arg) == Knowns.end())
3497 ufos.push_back(*it);
3514 std::string KFL(KnownFlagList);
3517 if (ArgumentNumber == -1)
3519 STRING_VECTOR::const_iterator
it =
argv.begin();
3521 for (; it !=
argv.end(); ++
it)
3525 if (arg ==
"")
continue;
3528 if (arg.length() < 2)
3531 else if (arg[0] !=
'-')
3534 else if (arg[1] ==
'-')
3538 const char* p=arg.c_str();
3540 for (; *p !=
'\0' ; p++)
3541 if (KFL.find(*p) == std::string::npos) ufos += *p;
3549 for (
unsigned i=1; i<
argv.size(); i++)
3555 if (no_matches == ArgumentNumber)
3559 const char* p = Remain.c_str();
3561 for (; *p !=
'\0' ; p++)
3562 if (KFL.find(*p) == std::string::npos) ufos += *p;
3575 const char* KnownVariable1, ...)
const
3577 std::set<std::string> known_variables;
3584 va_start(ap, KnownVariable1);
3585 known_variables.insert(std::string(KnownVariable1));
3586 for (
unsigned i=1; i<Number; i++)
3587 known_variables.insert(std::string(va_arg(ap,
char *)));
3618 if (Knowns.find(var_name) == Knowns.end())
3619 ufos.push_back((*it).name);
3636 const char* KnownSection1, ...)
const
3638 std::set<std::string> known_sections;
3645 va_start(ap, KnownSection1);
3646 known_sections.insert(std::string(KnownSection1));
3647 for (
unsigned i=1; i<Number; i++)
3649 std::string tmp = std::string(va_arg(ap,
char *));
3651 if (tmp.length() == 0)
3654 if (tmp[tmp.length()-1] !=
'/')
3657 known_sections.insert(tmp);
3697 if (Knowns.find(sec_name) == Knowns.end())
3698 ufos.push_back(*
it);
3709 std::set<std::string> known_nominuses;
3716 va_start(ap, Known);
3717 known_nominuses.insert(std::string(Known));
3718 for (
unsigned i=1; i<Number; i++)
3720 std::string tmp = std::string(va_arg(ap,
char *));
3721 if (tmp.length() == 0)
3723 known_nominuses.insert(tmp);
3763 STRING_VECTOR::const_iterator
it =
argv.begin();
3765 for (; it !=
argv.end(); ++
it)
3772 if (arg.length() < 1)
3780 if (arg[0] ==
'[' && arg[arg.length()-1] ==
']')
3784 bool continue_f =
false;
3785 for (
unsigned i=0; i<arg.length() ; i++)
3796 if (Knowns.find(arg) == Knowns.end())
3797 ufos.push_back(*it);
3808 std::set<std::string>
3817 std::set<std::string>
3826 std::set<std::string>
3864 take(Value, FieldSeparator);
3869 inline const std::string*
3872 if (Idx >= value.size())
3875 return &(value[Idx]);
3883 original = std::string(Value);
3908 std::string Value_str = std::string(Value);
3909 std::string delimiters = std::string(FieldSeparator);
3912 std::string::size_type lastPos = Value_str.find_first_not_of(delimiters, 0);
3915 std::string::size_type pos = Value_str.find_first_of(delimiters, lastPos);
3919 while (std::string::npos != pos || std::string::npos != lastPos)
3922 value.push_back(Value_str.substr(lastPos, pos - lastPos));
3925 lastPos = Value_str.find_first_not_of(delimiters, pos);
3928 pos = Value_str.find_first_of(delimiters, lastPos);
3946 value = Other.
value;
3952 #ifdef GETPOT_NAMESPACE
3958 #endif // QUESO_GETPOT_H
STRING_VECTOR _read_in_stream(std::istream &istr)
const GetPot::variable * _DBE_get_variable(const std::string &str)
void _record_variable_request(const std::string &Arg) const
void disable_request_recording()
void _set_variable(const std::string &VarName, const std::string &Value, const bool Requested)
const char * _internal_managed_copy(const std::string &Arg) const
const char * next_nominus()
std::set< std::string > get_requested_sections() const
std::set< std::string > overridden_vars
variable & operator=(const variable &Other)
T get(unsigned Idx, const T &Default) const
const variable * _find_variable(const char *) const
bool operator()(const char *s1, const char *s2) const
bool options_contain(const char *FlagList) const
std::string unidentified_flags(const char *Known, int ArgumentNumber) const
std::string next_nominus_string()
bool search(const char *option)
const char * operator[](unsigned Idx) const
unsigned nominus_size() const
std::string _process_section_label(const std::string &Section, STRING_VECTOR §ion_stack)
T direct_follow(const T &Default, const char *Option)
T follow(const T &Default, const char *Option)
std::set< const char *, ltstr > _internal_string_container
const std::string _get_until_closing_square_bracket(std::istream &istr)
std::string _field_separator
void init_multiple_occurrence()
bool have_section(const char *section_name) const
void absorb(const GetPot &Other)
std::set< std::string > get_requested_arguments() const
const char * _match_starting_string(const char *StartString)
bool _search_string_vector(const STRING_VECTOR &Vec, const std::string &Str) const
std::set< std::string > _requested_arguments
const variable * _request_variable(const char *) const
the intent is to exercise the right to control the distribution of derivative or collective works based on the Library In mere aggregation of another work not based on the Library with the you must alter all the notices that refer to this so that they refer to the ordinary GNU General Public instead of to this it is irreversible for that so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy This option is useful when you wish to copy part of the code of the Library into a program that is not a library You may copy and distribute the which must be distributed under the terms of Sections and above on a medium customarily used for software interchange If distribution of object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source even though third parties are not compelled to copy the source along with the object code A program that contains no derivative of any portion of the but is designed to work with the Library by being compiled or linked with is called a work that uses the Library Such a in is not a derivative work of the and therefore falls outside the scope of this License linking a work that uses the Library with the Library creates an executable that is a derivative of the rather than a work that uses the library The executable is therefore covered by this License Section states terms for distribution of such executables When a work that uses the Library uses material from a header file that is part of the the object code for the work may be a derivative work of the Library even though the source code is not Whether this is true is especially significant if the work can be linked without the or if the work is itself a library The threshold for this to be true is not precisely defined by law If such an object file uses only numerical data structure layouts and and small macros and small then the use of the object file is regardless of whether it is legally a derivative if the work is a derivative of the you may distribute the object code for the work under the terms of Section Any executables containing that work also fall under Section
GetPot & operator=(const GetPot &)
std::vector< variable > variables
std::string _comment_start
void _parse_argument_vector(const STRING_VECTOR &ARGV)
T _convert_to_type_no_default(const char *VarName, const std::string &String, const T &Default) const
void reset_nominus_cursor()
std::vector< unsigned > idx_nominus
void enable_request_recording()
T operator()(const char *VarName, const T &Default) const
STRING_VECTOR get_section_names() const
bool argument_contains(unsigned Idx, const char *FlagList) const
const std::string _get_next_token(std::istream &istr)
STRING_VECTOR unidentified_options() const
STRING_VECTOR section_list
void _record_argument_request(const std::string &Arg) const
STRING_VECTOR unidentified_nominuses() const
void _skip_whitespace(std::istream &istr)
std::set< std::string > _requested_variables
T get_value_no_default(const char *VarName, const T &Default) const
void _basic_initialization()
static std::string _convert_from_type(const T &Value)
STRING_VECTOR nominus_vector() const
void set(const char *VarName, const T &Value, const bool Requested=true)
STRING_VECTOR _DBE_get_expr_list(const std::string &str, const unsigned ExpectedNumber)
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
int print(std::ostream &out_stream=std::cout) const
T _convert_to_type(const std::string &String, const T &Default) const
const std::string _get_string(std::istream &istr)
void take(const char *Value, const char *FieldSeparator)
STRING_VECTOR unidentified_sections() const
std::vector< std::string > STRING_VECTOR
STRING_VECTOR get_variable_names() const
unsigned vector_variable_size(const char *VarName) const
STRING_VECTOR unidentified_variables() const
void parse_input_file(const std::string &FileName, const std::string &CommentStart=std::string("#"), const std::string &CommentEnd=std::string("\n"), const std::string &FieldSeparator=std::string(" \t\n"))
that you receive source code or can get it if you want it
std::set< std::string > _requested_sections
std::set< std::string > get_overridden_variables() const
bool search_failed() const
McOptionsValues::McOptionsValues(#ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS const SsOptionsValues *alternativePSsOptionsValues, const SsOptionsValues *alternativeQSsOptionsValues#endif if)(m_alternativeQSsOptionsValues=*alternativeQSsOptionsValues)
static STRING_VECTOR _get_section_tree(const std::string &FullPath)
void parse_command_line(const int argc_, const char *const *argv_, const char *FieldSeparator=0x0)
void set_prefix(const char *Prefix)
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("\n"), const std::string &FieldSeparator=std::string(" \t\n"))
const std::string * get_element(unsigned Idx) const
const std::string _get_until_closing_bracket(std::istream &istr)
bool have_variable(const char *VarName) const
bool _check_flags(const std::string &Str, const char *FlagList) const
std::set< std::string > get_requested_variables() const
std::string _DBE_expand(const std::string &str)
STRING_VECTOR unidentified_arguments() const
std::string _DBE_expand_string(const std::string &str)