getpot.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 // GetPot Version libMeshHPCT_fork-1.2 Apr/14/2010
3 // Based on "getpot-1.1.1.tgz" version from SourceForge
4 //
5 // New code (C) 2009-2013 Roy Stogner, Karl Schulz
6 //
7 // GetPot Version 1.0 Sept/13/2002
8 //
9 // WEBSITE: http://getpot.sourceforge.net
10 //
11 // This library is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Lesser General Public License as
13 // published by the Free Software Foundation; either version 2.1 of the
14 // License, or (at your option) any later version.
15 //
16 // This library is distributed in the hope that it will be useful, but
17 // WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 // USA
25 //
26 // (C) 2001-2002 Frank R. Schaefer
27 //==========================================================================
28 #ifndef LIBMESH_GETPOT_H
29 #define LIBMESH_GETPOT_H
30 
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
34 
35 #include <algorithm>
36 #include <cstddef>
37 #include <fstream>
38 #include <iostream> // not every compiler distribution includes <iostream> with <fstream>
39 #include <set>
40 #include <sstream>
41 #include <stdexcept>
42 #include <string>
43 #include <typeinfo>
44 #include <vector>
45 
46 #include <cmath>
47 #include <cstdlib>
48 #include <ctime>
49 
50 extern "C" {
51 #include <stdarg.h> // --> va_list and friends
52 #include <string.h> // --> strcmp, strncmp, strlen, strncpy
53 }
54 
55 // Undefine USE_LIBMESH to avoid libMesh-specific code
56 
57 #define USE_LIBMESH 1
58 
59 #ifdef USE_LIBMESH
60 
61 #include "libmesh/libmesh_common.h"
62 
63 // We need a mutex to keep const operations thread-safe in the
64 // presence of mutable containers. Right now GetPot supports a
65 // Threads::scoped_mutex wrapper around TBB, and we're assuming that
66 // users aren't doing any threaded GetPot usage when TBB threads are
67 // disabled.
68 #if !defined(GETPOT_DISABLE_MUTEX)
69 #include "libmesh/threads.h"
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
72 #else
73 #define SCOPED_MUTEX
74 #define GETPOT_MUTEX_DECLARE
75 #endif
76 
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
81 
82 // If libmesh detected the inverse hyperbolic trig functions, set
83 // special #defines for getpot.h
84 #ifdef LIBMESH_HAVE_CXX11_INVERSE_HYPERBOLIC_SINE
85 #define HAVE_INVERSE_HYPERBOLIC_SINE
86 #endif
87 
88 #ifdef LIBMESH_HAVE_CXX11_INVERSE_HYPERBOLIC_COSINE
89 #define HAVE_INVERSE_HYPERBOLIC_COSINE
90 #endif
91 
92 #ifdef LIBMESH_HAVE_CXX11_INVERSE_HYPERBOLIC_TANGENT
93 #define HAVE_INVERSE_HYPERBOLIC_TANGENT
94 #endif
95 
96 #else // !USE_LIBMESH
97 
98 // Currently threaded GetPot use is only supported via libMesh Threads
99 #define GETPOT_DISABLE_MUTEX
100 #define SCOPED_MUTEX
101 #define GETPOT_MUTEX_DECLARE
102 
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
107 
108 // Clang provides the __has_builtin macro, we define it for compilers
109 // that don't...
110 #ifndef __has_builtin
111 #define __has_builtin(x) 0
112 #endif
113 
114 // Fine-grained ifdefs for all three inverse hyperbolic trig
115 // functions. This works for the two clang compilers I tried it
116 // on... a hand-built one and one from Apple.
117 #if __cplusplus > 199711L && (!defined(__clang__) || __has_builtin(asinh))
118 #define HAVE_INVERSE_HYPERBOLIC_SINE
119 #endif
120 
121 #if __cplusplus > 199711L && (!defined(__clang__) || __has_builtin(acosh))
122 #define HAVE_INVERSE_HYPERBOLIC_COSINE
123 #endif
124 
125 #if __cplusplus > 199711L && (!defined(__clang__) || __has_builtin(atanh))
126 #define HAVE_INVERSE_HYPERBOLIC_TANGENT
127 #endif
128 
129 #endif // #ifdef USE_LIBMESH
130 
131 
132 typedef std::vector<std::string> STRING_VECTOR;
133 
134 #define victorate(TYPE, VARIABLE, ITERATOR) \
135  std::vector<TYPE>::const_iterator ITERATOR = (VARIABLE).begin(); \
136  for (; (ITERATOR) != (VARIABLE).end(); ++(ITERATOR))
137 
138 // We allow GETPOT_NAMESPACE to be defined before this file is
139 // included; if libraries using two different versions of GetPot might
140 // be linked together, the result may be unsafe unless they're put in
141 // different namespaces.
142 #ifdef GETPOT_NAMESPACE
143 namespace GETPOT_NAMESPACE {
144 #endif
145 
153 class GetPot
154 {
155  inline void _basic_initialization();
156 
157 public:
161  inline GetPot();
162  inline GetPot(const GetPot&);
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"));
172 
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"));
181  inline ~GetPot();
182  inline GetPot& operator=(const GetPot&);
183 
187  inline void parse_command_line(const int argc_, const char * const* argv_,
188  const char* FieldSeparator =0x0);
189  inline void parse_input_file(const std::string& FileName,
190  const std::string& CommentStart=std::string("#"),
191  const std::string& CommentEnd=std::string("\n"),
192  const std::string& FieldSeparator=std::string(" \t\n"));
193 
194  inline void parse_input_stream(std::istream& FileStream,
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"));
199 
203  inline void absorb(const GetPot& Other);
204 
208  inline void clear_requests();
211 
215  inline const char* operator[](unsigned Idx) const;
216 
217  template <typename T>
218  inline T get(unsigned Idx, const T& Default) const;
219 
220  inline const char* get(unsigned Idx, const char* Default) const;
221  inline unsigned size() const;
222 
226  inline bool options_contain(const char* FlagList) const;
227  inline bool argument_contains(unsigned Idx, const char* FlagList) const;
228 
236  inline bool have_variable(const char* VarName) const;
237  inline bool have_variable(const std::string& VarName) const;
238 
248  bool have_section(const char* section_name) const;
249 
259  bool have_section(const std::string& section_name) const;
260 
264  template<typename T>
265  inline T operator()(const char* VarName, const T& Default) const;
266 
267  template<typename T>
268  inline T operator()(const std::string& VarName, const T& Default) const;
269 
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;
272 
276  template<typename T>
277  inline T operator()(const char* VarName, const T& Default, unsigned Idx) const;
278 
279  template<typename T>
280  inline T operator()(const std::string& VarName, const T& Default, unsigned Idx) const;
281 
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;
284 
289  template<typename T>
290  inline T get_value_no_default(const char* VarName, const T& Default) const;
291 
292  template<typename T>
293  inline T get_value_no_default(const std::string& VarName, const T& Default) const;
294 
295  inline const char* get_value_no_default(const char* VarName, const char* Default) const;
296  inline const char* get_value_no_default(const std::string& VarName, const char* Default) const;
297 
301  template<typename T>
302  inline T get_value_no_default(const char* VarName, const T& Default, unsigned Idx) const;
303 
304  template<typename T>
305  inline T get_value_no_default(const std::string& VarName, const T& Default, unsigned Idx) const;
306 
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;
309 
315  template<typename T>
316  inline void set(const char* VarName, const T& Value, const bool Requested = true);
317 
318  template<typename T>
319  inline void set(const std::string& VarName, const T& Value, const bool Requested = true);
320 
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);
323 
324  inline unsigned vector_variable_size(const char* VarName) const;
325  inline unsigned vector_variable_size(const std::string& VarName) const;
326 
327  /*
328  * Return a list of all variables set by the current input
329  */
330  inline STRING_VECTOR get_variable_names() const;
331 
332  /*
333  * Return a list of all sections present in the current input
334  */
335  inline STRING_VECTOR get_section_names() const;
336 
337  /*
338  * Return a list of all subsections of the given section name in the
339  * current input.
340  *
341  * Subsections will be returned in the order they appear in the
342  * input.
343  *
344  * Subsections which exist multiple times in the input file will
345  * only be returned once, in the position of their first appearance.
346  */
347  inline STRING_VECTOR get_subsection_names(const std::string & section_name) const;
348 
349  inline std::set<std::string> get_overridden_variables() const;
350 
354  inline void set_prefix(const char* Prefix) { prefix = std::string(Prefix); }
355  inline bool search_failed() const { return search_failed_f; }
356 
360  inline void disable_loop() { search_loop_f = false; }
361  inline void enable_loop() { search_loop_f = true; }
362 
366  inline void reset_cursor();
367  inline void init_multiple_occurrence();
368 
372  inline bool search(const char* option);
373  inline bool search(const std::string& option);
374  inline bool search(unsigned No, const char* P, ...);
375 
379  template<typename T>
380  inline T next(const T& Default);
381 
382  inline const char* next(const char* Default);
383 
387  template<typename T>
388  inline T follow(const T& Default, const char* Option);
389 
390  inline const char* follow(const char* Default, const char* Option);
391 
395  template<typename T>
396  inline T follow(const T& Default, unsigned No, const char* Option, ...);
397 
398  inline const char* follow(const char* Default, unsigned No, const char* Option, ...);
399 
403  template<typename T>
404  inline T direct_follow(const T& Default, const char* Option);
405 
406  inline const char* direct_follow(const char* Default, const char* Option);
407 
411  inline void reset_nominus_cursor();
412  inline STRING_VECTOR nominus_vector() const;
413  inline unsigned nominus_size() const { return getpot_cast_int<unsigned>(idx_nominus.size()); }
414  inline const char* next_nominus();
415  inline std::string next_nominus_string();
416 
420  inline STRING_VECTOR unidentified_arguments(unsigned Number, const char* Known, ...) const;
421  inline STRING_VECTOR unidentified_arguments(const std::set<std::string>& Knowns) const;
422  inline STRING_VECTOR unidentified_arguments(const std::vector<std::string>& Knowns) const;
423  inline STRING_VECTOR unidentified_arguments() const;
424 
425  inline STRING_VECTOR unidentified_options(unsigned Number, const char* Known, ...) const;
426  inline STRING_VECTOR unidentified_options(const std::set<std::string>& Knowns) const;
427  inline STRING_VECTOR unidentified_options(const std::vector<std::string>& Knowns) const;
428  inline STRING_VECTOR unidentified_options() const;
429 
430  inline std::string unidentified_flags(const char* Known, int ArgumentNumber /* =-1 */) const;
431 
432  inline STRING_VECTOR unidentified_variables(unsigned Number, const char* Known, ...) const;
433  inline STRING_VECTOR unidentified_variables(const std::set<std::string>& Knowns) const;
434  inline STRING_VECTOR unidentified_variables(const std::vector<std::string>& Knowns) const;
435  inline STRING_VECTOR unidentified_variables() const;
436 
437  inline STRING_VECTOR unidentified_sections(unsigned Number, const char* Known, ...) const;
438  inline STRING_VECTOR unidentified_sections(const std::set<std::string>& Knowns) const;
439  inline STRING_VECTOR unidentified_sections(const std::vector<std::string>& Knowns) const;
440  inline STRING_VECTOR unidentified_sections() const;
441 
442  inline STRING_VECTOR unidentified_nominuses(unsigned Number, const char* Known, ...) const;
443  inline STRING_VECTOR unidentified_nominuses(const std::set<std::string>& Knowns) const;
444  inline STRING_VECTOR unidentified_nominuses(const std::vector<std::string>& Knowns) const;
445  inline STRING_VECTOR unidentified_nominuses() const;
446 
450  std::set<std::string> get_requested_arguments() const;
451  std::set<std::string> get_requested_variables() const;
452  std::set<std::string> get_requested_sections() const;
453 
461  inline int print(std::ostream &out_stream = std::cout) const;
462 
468  inline int print(const char *custom_prefix,
469  std::ostream &out_stream = std::cout,
470  unsigned int skip_count=1) const;
471 
472 private:
473 
478  struct variable
479  {
483  variable();
484  variable(const variable&);
485  variable(const char* Name, const char* Value, const char* FieldSeparator);
486  ~variable();
487  variable& operator=(const variable& Other);
488 
489  void take(const char* Value, const char* FieldSeparator);
490 
495  const std::string* get_element(unsigned Idx) const;
496 
500  std::string name; // identifier of variable
501  STRING_VECTOR value; // value of variable stored in vector
502  std::string original; // value of variable as given on command line
503  };
504 
508  std::string prefix; // prefix automatically added in queries
509  std::string section; // (for dollar bracket parsing)
510  STRING_VECTOR section_list; // list of all parsed sections
511 
515  STRING_VECTOR argv; // vector of command line arguments stored as strings
516  unsigned cursor; // cursor for argv
517  bool search_loop_f; // shall search start at beginning after reaching end of arg array ?
518  bool search_failed_f; // flag indicating a failed search() operation (e.g. next() functions react with 'missed')
519  std::set<std::string> overridden_vars; // vector of variables that were supplied more than once during parsing
520 
524  int nominus_cursor; // cursor for nominus_pointers
525  std::vector<unsigned> idx_nominus; // indices of 'no minus' arguments
526 
530  std::vector<variable> variables;
531 
535  std::string _comment_start;
536  std::string _comment_end;
537 
541  std::string _field_separator;
542 
546  struct ltstr
547  {
548  bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) < 0; }
549  };
550 
558 
567  mutable std::set<const char*, ltstr> _internal_string_container;
568 
573  const char* _internal_managed_copy(const std::string& Arg) const;
574 
579  mutable std::set<std::string> _requested_arguments;
580  mutable std::set<std::string> _requested_variables;
581  mutable std::set<std::string> _requested_sections;
582 
583  bool request_recording_f; // speed: request recording can be turned off
584 
591  void _record_argument_request(const std::string& Arg) const;
592  void _record_variable_request(const std::string& Arg) const;
593 
601  inline void _set_variable(const std::string& VarName,
602  const std::string& Value,
603  const bool Requested);
604 
611  inline void _parse_argument_vector(const STRING_VECTOR& ARGV);
612 
620  inline const variable* _find_variable(const char*) const;
621 
625  inline const variable* _request_variable(const char*) const;
626 
630  inline const char* _match_starting_string(const char* StartString);
631 
635  inline bool _check_flags(const std::string& Str, const char* FlagList) const;
636 
640  template<typename T>
641  inline T _convert_to_type(const std::string& String, const T& Default) const;
642 
643  inline std::string _convert_to_type(const std::string& String, const char* Default) const;
644 
645  template<typename T>
646  inline T _convert_to_type_no_default(const char* VarName, const std::string& String, const T& Default) const;
647 
648  inline std::string _convert_to_type_no_default(const char* VarName, const std::string& String, const char* Default) const;
649 
653  const std::string _get_remaining_string(const std::string& String,
654  const std::string& Start) const;
658  inline bool _search_string_vector(const STRING_VECTOR& Vec,
659  const std::string& Str) const;
660 
671  inline void _skip_whitespace(std::istream& istr);
672  inline const std::string _get_next_token(std::istream& istr);
673  inline const std::string _get_string(std::istream& istr);
674  inline const std::string _get_until_closing_bracket(std::istream& istr);
675  inline const std::string _get_until_closing_square_bracket(std::istream& istr);
676 
677  inline STRING_VECTOR _read_in_stream(std::istream& istr);
678  inline std::string _process_section_label(const std::string& Section,
679  STRING_VECTOR& section_stack);
680 
684  std::string _DBE_expand_string(const std::string& str);
685  std::string _DBE_expand(const std::string& str);
686  const GetPot::variable* _DBE_get_variable(const std::string& str);
687  STRING_VECTOR _DBE_get_expr_list(const std::string& str, const unsigned ExpectedNumber);
688 
689  template <typename T>
690  static std::string _convert_from_type(const T& Value)
691  {
692  std::ostringstream out_string;
693  out_string << Value;
694  return out_string.str();
695  }
696 
701  static STRING_VECTOR _get_section_tree(const std::string& FullPath)
702  {
703  STRING_VECTOR result;
704  for (std::size_t pos = 0; pos != FullPath.size(); ++pos)
705  {
706  if (FullPath[pos] == '/')
707  result.push_back(FullPath.substr(0,pos));
708  }
709 
710  return result;
711  }
712 };
713 
714 
716 // (*) constructors, destructor, assignment operator
717 //.............................................................................
718 //
719 inline void
721 {
722  cursor = 0;
723  nominus_cursor = -1;
724  search_failed_f = true;
725  search_loop_f = true;
726  prefix = "";
727  section = "";
728 
729  // automatic request recording for later ufo detection
730  request_recording_f = true;
731 
732  // comment start and end strings
733  _comment_start = std::string("#");
734  _comment_end = std::string("\n");
735 
736  // default: separate vector elements by whitespaces
737  _field_separator = " \t\n";
738 }
739 
740 
741 
742 inline
744  prefix(),
745  section(),
746  section_list(),
747  argv(),
748  cursor(),
749  search_loop_f(),
750  search_failed_f(),
751  nominus_cursor(),
752  idx_nominus(),
753  variables(),
754  _comment_start(),
755  _comment_end(),
756  _field_separator(),
757 #if !defined(GETPOT_DISABLE_MUTEX)
758  _getpot_mtx(),
759 #endif
760  _internal_string_container(),
761  _requested_arguments(),
762  _requested_variables(),
763  _requested_sections(),
764  request_recording_f()
765 {
767 }
768 
769 
770 
771 inline
772 GetPot::GetPot(const int argc_, const char * const * argv_,
773  const char* FieldSeparator /* =0x0 */) :
774  // leave 'char**' non-const to honor less capable compilers ...
775  prefix(),
776  section(),
777  section_list(),
778  argv(),
779  cursor(),
780  search_loop_f(),
781  search_failed_f(),
782  nominus_cursor(),
783  idx_nominus(),
784  variables(),
785  _comment_start(),
786  _comment_end(),
787  _field_separator(),
788 #if !defined(GETPOT_DISABLE_MUTEX)
789  _getpot_mtx(),
790 #endif
791  _internal_string_container(),
792  _requested_arguments(),
793  _requested_variables(),
794  _requested_sections(),
795  request_recording_f()
796 {
797  this->parse_command_line(argc_, argv_, FieldSeparator);
798 }
799 
800 
801 
802 // leave 'char**' non-const to honor less capable compilers ...
803 inline void
804 GetPot::parse_command_line(const int argc_, const char * const * argv_,
805  const char* FieldSeparator /* =0x0 */)
806 {
808 
809  // if specified -> overwrite default string
810  if (FieldSeparator)
811  _field_separator = std::string(FieldSeparator);
812 
813  // -- make an internal copy of the argument list:
814  STRING_VECTOR _apriori_argv;
815  // -- for the sake of clarity: we do want to include the first
816  // argument of the first parsing source in the argument vector!
817  // it will not be a nominus argument, though. This gives us a
818  // minimum vector size of one which facilitates error checking
819  // in many functions. Also the user will be able to retrieve
820  // the name of his application or input file by "get[0]"
821  _apriori_argv.push_back(std::string(argv_[0]));
822  for (int i=1; i<argc_; i++)
823  {
824  std::string tmp(argv_[i]); // recall the problem with temporaries,
825  _apriori_argv.push_back(tmp); // reference counting in argument lists ...
826  }
827  _parse_argument_vector(_apriori_argv);
828 }
829 
830 
831 
832 inline
833 GetPot::GetPot(const char* FileName,
834  const char* CommentStart /* = 0x0 */, const char* CommentEnd /* = 0x0 */,
835  const char* FieldSeparator/* = 0x0 */) :
836  prefix(),
837  section(),
838  section_list(),
839  argv(),
840  cursor(),
841  search_loop_f(),
842  search_failed_f(),
843  nominus_cursor(),
844  idx_nominus(),
845  variables(),
846  _comment_start(),
847  _comment_end(),
848  _field_separator(),
849 #if !defined(GETPOT_DISABLE_MUTEX)
850  _getpot_mtx(),
851 #endif
852  _internal_string_container(),
853  _requested_arguments(),
854  _requested_variables(),
855  _requested_sections(),
856  request_recording_f()
857 {
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);
862 }
863 
864 
865 
866 inline
867 GetPot::GetPot(const std::string& FileName,
868  const std::string& CommentStart,
869  const std::string& CommentEnd,
870  const std::string& FieldSeparator) :
871  prefix(),
872  section(),
873  section_list(),
874  argv(),
875  cursor(),
876  search_loop_f(),
877  search_failed_f(),
878  nominus_cursor(),
879  idx_nominus(),
880  variables(),
881  _comment_start(),
882  _comment_end(),
883  _field_separator(),
884 #if !defined(GETPOT_DISABLE_MUTEX)
885  _getpot_mtx(),
886 #endif
887  _internal_string_container(),
888  _requested_arguments(),
889  _requested_variables(),
890  _requested_sections(),
891  request_recording_f()
892 {
893  this->parse_input_file(FileName, CommentStart, CommentEnd, FieldSeparator);
894 }
895 
896 inline void
897 GetPot::parse_input_file(const std::string& FileName,
898  const std::string& CommentStart,
899  const std::string& CommentEnd,
900  const std::string& FieldSeparator)
901 {
902  std::ifstream input(FileName.c_str());
903 
904  if (!input)
905  getpot_file_error(FileName);
906 
907  this->parse_input_stream(input,FileName,CommentStart,CommentEnd,FieldSeparator);
908 }
909 
910 
911 inline
912 GetPot::GetPot(std::istream& FileStream,
913  const std::string& CommentStart,
914  const std::string& CommentEnd,
915  const std::string& FieldSeparator) :
916  prefix(),
917  section(),
918  section_list(),
919  argv(),
920  cursor(),
921  search_loop_f(),
922  search_failed_f(),
923  nominus_cursor(),
924  idx_nominus(),
925  variables(),
926  _comment_start(),
927  _comment_end(),
928  _field_separator(),
929 #if !defined(GETPOT_DISABLE_MUTEX)
930  _getpot_mtx(),
931 #endif
932  _internal_string_container(),
933  _requested_arguments(),
934  _requested_variables(),
935  _requested_sections(),
936  request_recording_f()
937 {
938  this->parse_input_stream(FileStream,
939  std::string("ParsedFromStream"),// We don't have a filename here
940  CommentStart, CommentEnd, FieldSeparator);
941 }
942 
943 
944 inline void
945 GetPot::parse_input_stream(std::istream& FileStream,
946  const std::string& FileName,
947  const std::string& CommentStart,
948  const std::string& CommentEnd,
949  const std::string& FieldSeparator)
950 {
952 
953  // overwrite default strings
954  _comment_start = std::string(CommentStart);
955  _comment_end = std::string(CommentEnd);
956  _field_separator = FieldSeparator;
957 
958  STRING_VECTOR _apriori_argv;
959  // -- the first element of the argument vector stores the name of
960  // the first parsing source; however, this element is not
961  // parsed for variable assignments or nominuses.
962  //
963  // Regardless, we don't add more than one name to the argument
964  // vector. In this case, we're parsing from a stream, so we'll
965  // hardcode the "filename" to "ParsedFromStream"
966  _apriori_argv.push_back(FileName);
967 
968  STRING_VECTOR args = _read_in_stream(FileStream);
969  _apriori_argv.insert(_apriori_argv.begin()+1, args.begin(), args.end());
970  _parse_argument_vector(_apriori_argv);
971 }
972 
973 
974 
975 inline
976 GetPot::GetPot(const GetPot& Other) :
977  prefix(Other.prefix),
978  section(Other.section),
979  section_list(Other.section_list),
980  argv(Other.argv),
981  cursor(Other.cursor),
982  search_loop_f(Other.search_loop_f),
983  search_failed_f(Other.search_failed_f),
984  overridden_vars(),
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),
991  // #if !defined(GETPOT_DISABLE_MUTEX)
992  // _getpot_mtx(Other._getpot_mtx),
993  // #endif
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)
999 {
1000  std::set<const char*,ltstr>::const_iterator it =
1001  Other._internal_string_container.begin();
1002 
1003  const std::set<const char*,ltstr>::const_iterator end =
1004  Other._internal_string_container.end();
1005 
1006  for (; it != end; ++it)
1007  {
1008  const char* otherstr = *it;
1009  char* newcopy = new char[strlen(otherstr)+1];
1010  strncpy(newcopy, otherstr, strlen(otherstr)+1);
1011  this->_internal_string_container.insert(newcopy);
1012  }
1013 }
1014 
1015 
1016 
1017 inline
1019 {
1020  // may be some return strings had to be created, delete now !
1021  std::set<const char*, ltstr>::const_iterator it = _internal_string_container.begin();
1022  const std::set<const char*, ltstr>::const_iterator end = _internal_string_container.end();
1023  for (; it != end; ++it)
1024  delete [] *it;
1025 }
1026 
1027 
1028 
1029 inline GetPot&
1031 {
1032  if (&Other == this)
1033  return *this;
1034 
1035  prefix = Other.prefix;
1036  section = Other.section;
1037  section_list = Other.section_list;
1038  argv = Other.argv;
1039  cursor = Other.cursor;
1040  search_loop_f = Other.search_loop_f;
1044  idx_nominus = Other.idx_nominus;
1045  variables = Other.variables;
1047  _comment_end = Other._comment_end;
1049  // #if !defined(GETPOT_DISABLE_MUTEX)
1050  // _getpot_mtx = Other._getpot_mtx;
1051  // #endif
1056 
1057  std::set<const char*, ltstr>::const_iterator my_it =
1059  const std::set<const char*, ltstr>::const_iterator my_end =
1061 
1062  for (; my_it != my_end; ++my_it)
1063  delete [] *my_it;
1064 
1066 
1067  std::set<const char*,ltstr>::const_iterator it =
1068  Other._internal_string_container.begin();
1069  const std::set<const char*,ltstr>::const_iterator end =
1070  Other._internal_string_container.end();
1071 
1072  for (; it != end; ++it)
1073  {
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);
1078  this->_internal_string_container.insert(newcopy);
1079  }
1080 
1081  return *this;
1082 }
1083 
1084 
1085 
1086 inline void
1087 GetPot::absorb(const GetPot& Other)
1088 {
1089  if (&Other == this)
1090  return;
1091 
1092  // variables that are not influenced by absorption:
1093  // _comment_start
1094  // _comment_end
1095  // cursor
1096  // nominus_cursor
1097  // search_failed
1098  // idx_nominus
1099  // search_loop_f
1100  argv = Other.argv;
1101  variables = Other.variables;
1102 
1103  if (request_recording_f)
1104  {
1105  // Get a lock before touching anything mutable
1106  SCOPED_MUTEX;
1107 
1108  _requested_arguments.insert(Other._requested_arguments.begin(), Other._requested_arguments.end());
1109  _requested_variables.insert(Other._requested_variables.begin(), Other._requested_variables.end());
1110  _requested_sections.insert(Other._requested_sections.begin(), Other._requested_sections.end());
1111  }
1112 }
1113 
1114 
1115 
1116 inline void
1118 {
1119  // Get a lock before touching anything mutable
1120  SCOPED_MUTEX;
1121 
1122  _requested_arguments.clear();
1123  _requested_variables.clear();
1124  _requested_sections.clear();
1125 }
1126 
1127 
1128 
1129 inline void
1131 {
1132  if (ARGV.empty())
1133  return;
1134 
1135  // build internal databases:
1136  // 1) array with no-minus arguments (usually used as filenames)
1137  // 2) variable assignments:
1138  // 'variable name' '=' number | string
1139  STRING_VECTOR section_stack;
1140  STRING_VECTOR::const_iterator it = ARGV.begin();
1141 
1142 
1143  section = "";
1144 
1145  // -- do not parse the first argument, so that this parsing source
1146  // name is not interpreted a s a nominus or so. If we already
1147  // have parsed arguments, don't bother adding another parsing
1148  // source name
1149  if (argv.empty())
1150  argv.push_back(*it);
1151  ++it;
1152 
1153  // -- loop over remaining arguments
1154  for (; it != ARGV.end(); ++it)
1155  {
1156  std::string arg = *it;
1157 
1158  if (arg.length() == 0)
1159  continue;
1160 
1161  // -- [section] labels and [include file] directives
1162  if (arg.length() > 1 && arg[0] == '[' && arg[arg.length()-1] == ']')
1163  {
1164 
1165  // Is this an include file directive?
1166  std::size_t include_pos = arg.find("include ", 1);
1167  if (include_pos != std::string::npos)
1168  {
1169 
1170  const std::string includefile =
1171  _DBE_expand_string(arg.substr(9, arg.length()-9-include_pos));
1172 
1173  this->parse_input_file
1174  (includefile, _comment_start, _comment_end, _field_separator);
1175  }
1176 
1177  else
1178  {
1179  // (*) sections are considered 'requested arguments'
1180  if (request_recording_f)
1181  {
1182  // Get a lock before touching anything mutable
1183  SCOPED_MUTEX;
1184 
1185  _requested_arguments.insert(arg);
1186  }
1187 
1188  const std::string Name = _DBE_expand_string(arg.substr(1, arg.length()-2));
1189  section = _process_section_label(Name, section_stack);
1190  // new section --> append to list of sections
1191  if (find(section_list.begin(), section_list.end(), section) == section_list.end())
1192  if (section.length() != 0) section_list.push_back(section);
1193  argv.push_back(arg);
1194  }
1195  }
1196  else
1197  {
1198  arg = section + _DBE_expand_string(arg);
1199  argv.push_back(arg);
1200  }
1201 
1202  // -- separate array for nominus arguments
1203  if (arg[0] != '-')
1204  idx_nominus.push_back(getpot_cast_int<unsigned>(argv.size()-1));
1205 
1206  // -- variables: does arg contain a '=' operator ?
1207  const std::size_t equals_pos = arg.find_first_of('=');
1208  if (equals_pos != std::string::npos)
1209  {
1210  // (*) record for later ufo detection
1211  // arguments carrying variables are always treated as 'requested' arguments.
1212  // unrequested variables have to be detected with the ufo-variable
1213  // detection routine.
1214  if (request_recording_f)
1215  {
1216  // Get a lock before touching anything mutable
1217  SCOPED_MUTEX;
1218 
1219  _requested_arguments.insert(arg);
1220  }
1221 
1222  // => arg (from start to '=') = Name of variable
1223  // (from '=' to end) = value of variable
1224  _set_variable(arg.substr(0,equals_pos),
1225  arg.substr(equals_pos+1), false);
1226  }
1227  }
1228 }
1229 
1230 
1231 
1232 inline STRING_VECTOR
1233 GetPot::_read_in_stream(std::istream& istr)
1234 {
1235  STRING_VECTOR brute_tokens;
1236  while (istr)
1237  {
1238  _skip_whitespace(istr);
1239  const std::string Token = _get_next_token(istr);
1240  // Allow 'keyword =' to parse with an empty string as value.
1241  // Only break at EOF.
1242  // if (Token.length() == 0 || Token[0] == EOF) break;
1243  if (Token[0] == EOF)
1244  break;
1245  brute_tokens.push_back(Token);
1246  }
1247 
1248  // -- reduce expressions of token1'='token2 to a single
1249  // string 'token1=token2'
1250  // -- copy everything into 'argv'
1251  // -- arguments preceded by something like '[' name ']' (section)
1252  // produce a second copy of each argument with a prefix '[name]argument'
1253  unsigned i1 = 0;
1254  unsigned i2 = 1;
1255  unsigned i3 = 2;
1256 
1257  STRING_VECTOR arglist;
1258  while (i1 < brute_tokens.size())
1259  {
1260  // 1) concatenate 'abcdef' '=' 'efgasdef' to 'abcdef=efgasdef'
1261  // note: java.lang.String: substring(a,b) = from a to b-1
1262  // C++ string: substr(a,b) = from a to a + b
1263  std::string result;
1264  if (i2 < brute_tokens.size() && brute_tokens[i2] == "=")
1265  {
1266  if (i3 >= brute_tokens.size())
1267  result = brute_tokens[i1] + brute_tokens[i2];
1268  else
1269  result = brute_tokens[i1] + brute_tokens[i2] + brute_tokens[i3];
1270  i1 = i3+1; i2 = i3+2; i3 = i3+3;
1271  }
1272  else if (i2 < brute_tokens.size() &&
1273  brute_tokens[i2].length() > 0 &&
1274  brute_tokens[i2][0] == '=')
1275  {
1276  // This case should not be hit if '=' at the beginning of a word
1277  // is always separated into its own word
1278  result = brute_tokens[i1] + brute_tokens[i2];
1279  i1 = i3; i2 = i3+1; i3 = i3+2;
1280  }
1281  else if (i2 < brute_tokens.size() && brute_tokens[i1][brute_tokens[i1].size()-1] == '=')
1282  {
1283  result = brute_tokens[i1] + brute_tokens[i2];
1284  i1 = i3; i2 = i3+1; i3 = i3+2;
1285  }
1286  else
1287  {
1288  result = brute_tokens[i1];
1289  i1=i2; i2=i3; i3++;
1290  }
1291 
1292  // Now strip out any comment
1293  size_t comment_start_loc = result.find(_comment_start, 0);
1294  if (comment_start_loc != std::string::npos)
1295  result = result.substr(0, comment_start_loc);
1296 
1297  arglist.push_back(result);
1298  }
1299  return arglist;
1300 }
1301 
1302 
1303 
1304 inline void
1305 GetPot::_skip_whitespace(std::istream& istr)
1306 {
1307  // find next non-whitespace while deleting comments
1308  int tmp = istr.get();
1309  do {
1310  // -- search a non whitespace
1311  while (isspace(tmp))
1312  {
1313  tmp = istr.get();
1314  if (!istr)
1315  return;
1316  }
1317 
1318  // -- look if characters match the comment starter string
1319  for (unsigned i=0; i<_comment_start.length() ; i++)
1320  {
1321  if (tmp != _comment_start[i])
1322  {
1323  // -- one step more backwards, since 'tmp' already at non-whitespace
1324  istr.unget();
1325  return;
1326  }
1327 
1328  // RHS: Why is this here? It breaks on empty comments
1329  // tmp = istr.get();
1330  // if (!istr) { istr.unget(); return; }
1331  }
1332  // 'tmp' contains last character of _comment_starter
1333 
1334  // -- comment starter found -> search for comment ender
1335  unsigned match_no=0;
1336  while (true)
1337  {
1338  tmp = istr.get();
1339  if (!istr)
1340  {
1341  istr.unget();
1342  return;
1343  }
1344 
1345  if (tmp == _comment_end[match_no])
1346  {
1347  match_no++;
1348  if (match_no == _comment_end.length())
1349  {
1350  istr.unget();
1351  break; // shuffle more whitespace, end of comment found
1352  }
1353  }
1354  else
1355  match_no = 0;
1356  }
1357 
1358  tmp = istr.get();
1359 
1360  } while (istr);
1361  istr.unget();
1362 }
1363 
1364 
1365 
1366 inline const std::string
1367 GetPot::_get_next_token(std::istream& istr)
1368 {
1369  // get next concatenates string token. consider quotes that embrace
1370  // whitespaces
1371  std::string token;
1372  int tmp = 0;
1373  while (true)
1374  {
1375  int last_letter = tmp;
1376  tmp = istr.get();
1377 
1378  if (tmp == '=')
1379  {
1380  // Always break at '='.
1381  // This separates '=' at the beginning of a word into its own word.
1382  token += getpot_cast_int<char>(tmp);
1383  return token;
1384  }
1385 
1386  else if (tmp == EOF || ((tmp == ' ' || tmp == '\t' || tmp == '\n') && last_letter != '\\'))
1387  return token;
1388 
1389  else if (tmp == '\'' && last_letter != '\\')
1390  {
1391  // QUOTES: un-backslashed quotes => it's a string
1392  token += _get_string(istr);
1393  continue;
1394  }
1395 
1396  else if (tmp == '{' && last_letter == '$')
1397  {
1398  token += '{' + _get_until_closing_bracket(istr);
1399  continue;
1400  }
1401 
1402  else if (tmp == '[')
1403  {
1405  continue;
1406  }
1407 
1408  else if (tmp == '$' && last_letter == '\\')
1409  {
1410  token += getpot_cast_int<char>(tmp); tmp = 0; // so that last_letter will become = 0, not '$';
1411  continue;
1412  }
1413 
1414  else if (tmp == '\\' && last_letter != '\\')
1415  continue; // don't append un-backslashed backslashes
1416 
1417  token += getpot_cast_int<char>(tmp);
1418  }
1419 }
1420 
1421 
1422 
1423 inline const std::string
1424 GetPot::_get_string(std::istream& istr)
1425 {
1426  // parse input until next matching '
1427  std::string str;
1428  int tmp = 0;
1429  while (true)
1430  {
1431  int last_letter = tmp;
1432  tmp = istr.get();
1433  if (tmp == EOF)
1434  return str;
1435 
1436  // un-backslashed quotes => it's the end of the string
1437  else if (tmp == '\'' && last_letter != '\\')
1438  return str;
1439 
1440  else if (tmp == '\\' && last_letter != '\\')
1441  continue; // don't append
1442 
1443  str += getpot_cast_int<char>(tmp);
1444  }
1445 }
1446 
1447 
1448 
1449 inline const std::string
1451 {
1452  // parse input until next matching }
1453  std::string str = "";
1454  int tmp = 0;
1455  int brackets = 1;
1456  while (true)
1457  {
1458  int last_letter = tmp;
1459  tmp = istr.get();
1460  if (tmp == EOF)
1461  return str;
1462 
1463  else if (tmp == '{' && last_letter == '$')
1464  brackets += 1;
1465 
1466  else if (tmp == '}')
1467  {
1468  brackets -= 1;
1469  // un-backslashed brackets => it's the end of the string
1470  if (brackets == 0)
1471  return str + '}';
1472 
1473  else if (tmp == '\\' && last_letter != '\\')
1474  continue; // do not append an unbackslashed backslash
1475  }
1476  str += getpot_cast_int<char>(tmp);
1477  }
1478 }
1479 
1480 
1481 
1482 inline const std::string
1484 {
1485  // parse input until next matching ]
1486  std::string str = "";
1487  int brackets = 1;
1488  while (true)
1489  {
1490  int tmp = istr.get();
1491  if (tmp == EOF)
1492  return str;
1493 
1494  else if (tmp == '[')
1495  brackets += 1;
1496 
1497  else if (tmp == ']')
1498  {
1499  brackets -= 1;
1500  if (brackets == 0)
1501  return str + ']';
1502  }
1503 
1504  str += getpot_cast_int<char>(tmp);
1505  }
1506 }
1507 
1508 
1509 
1510 inline std::string
1511 GetPot::_process_section_label(const std::string& Section,
1512  STRING_VECTOR& section_stack)
1513 {
1514  std::string sname = Section;
1515  // 1) subsection of actual section ('./' prefix)
1516  if (sname.length() >= 2 && sname.substr(0, 2) == "./")
1517  sname = sname.substr(2);
1518 
1519  // 2) subsection of parent section ('../' prefix)
1520  else if (sname.length() >= 3 && sname.substr(0, 3) == "../")
1521  {
1522  do
1523  {
1524  if (section_stack.end() != section_stack.begin())
1525  section_stack.pop_back();
1526  sname = sname.substr(3);
1527  } while (sname.substr(0, 3) == "../");
1528  }
1529 
1530  // 3) subsection of the root-section
1531  else
1532  // [] => back to root section
1533  section_stack.erase(section_stack.begin(), section_stack.end());
1534 
1535  if (sname != "")
1536  {
1537  // parse section name for 'slashes'
1538  unsigned i=0;
1539  while (i < sname.length())
1540  {
1541  if (sname[i] == '/')
1542  {
1543  section_stack.push_back(sname.substr(0,i));
1544  if (i+1 < sname.length())
1545  sname = sname.substr(i+1);
1546  i = 0;
1547  }
1548  else
1549  i++;
1550  }
1551  section_stack.push_back(sname);
1552  }
1553 
1554  std::string section_label = "";
1555  if (!section_stack.empty())
1556  {
1557  victorate(std::string, section_stack, it)
1558  section_label += *it + "/";
1559  }
1560  return section_label;
1561 }
1562 
1563 
1564 
1565 // Use C++ istream/ostream to handle most type conversions.
1566 template <typename T>
1567 inline T
1568 GetPot::_convert_to_type(const std::string& String, const T& Default) const
1569 {
1570  std::istringstream in_string(String);
1571  T retval;
1572  in_string >> retval;
1573  if (in_string.fail())
1574  retval = Default;
1575  return retval;
1576 }
1577 
1578 
1579 
1580 // copy string - operator>> would have stopped upon seeing whitespace!
1581 template <>
1582 inline std::string
1583 GetPot::_convert_to_type(const std::string& String, const std::string&) const
1584 {
1585  return String;
1586 }
1587 
1588 
1589 
1590 // copy string
1591 inline std::string
1592 GetPot::_convert_to_type(const std::string& String, const char*) const
1593 {
1594  return String;
1595 }
1596 
1597 
1598 
1599 // be more liberal than std C++ in what we interpret as a boolean
1600 template<>
1601 inline bool
1602 GetPot::_convert_to_type<bool>(const std::string& String, const bool & Default) const
1603 {
1604  std::string newstring(String);
1605  //std::transform(newstring.begin(), newstring.end(), newstring.begin(), std::toupper);
1606  for (unsigned int i=0; i<newstring.length(); ++i)
1607  newstring[i] = getpot_cast_int<char>(toupper(newstring[i]));
1608 
1609  // "true"/"True"/"TRUE" should work
1610  if (newstring.find("TRUE")!=std::string::npos)
1611  return true;
1612 
1613  if (newstring.find("FALSE")!=std::string::npos)
1614  return false;
1615 
1616  // And if we don't find that, let's search for an integer and use C unsigned
1617  // int->bool conversion before giving up; i.e. a user could specify "0" for
1618  // false or "1" for true
1619  std::istringstream in_string(String);
1620  unsigned int retval;
1621  in_string >> retval;
1622  if (in_string.fail())
1623  return Default;
1624 
1625  return retval;
1626 }
1627 
1628 
1629 
1630 // Use C++ istream/ostream to handle most type conversions.
1631 template <typename T>
1632 inline T
1633 GetPot::_convert_to_type_no_default(const char* VarName, const std::string& String, const T&) const
1634 {
1635  std::istringstream in_string(String);
1636  T retval;
1637  in_string >> retval;
1638  if (in_string.fail())
1639  {
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;
1642  getpot_error();
1643  }
1644  return retval;
1645 }
1646 
1647 
1648 
1649 // copy string - operator>> would have stopped upon seeing whitespace!
1650 template <>
1651 inline std::string
1652 GetPot::_convert_to_type_no_default(const char*, const std::string& String, const std::string&) const
1653 {
1654  return String;
1655 }
1656 
1657 
1658 
1659 // copy string
1660 inline std::string
1661 GetPot::_convert_to_type_no_default(const char*, const std::string& String, const char*) const
1662 {
1663  return String;
1664 }
1665 
1666 
1667 
1668 // be more liberal than std C++ in what we interpret as a boolean
1669 template<>
1670 inline bool
1671 GetPot::_convert_to_type_no_default<bool>(const char* VarName, const std::string& String, const bool &) const
1672 {
1673  std::string newstring(String);
1674  //std::transform(newstring.begin(), newstring.end(), newstring.begin(), std::toupper);
1675  for (unsigned int i=0; i<newstring.length(); ++i)
1676  {
1677  newstring[i]=getpot_cast_int<char>(toupper(newstring[i]));
1678  }
1679 
1680  // "true"/"True"/"TRUE" should work
1681  if (newstring.find("TRUE")!=std::string::npos)
1682  return true;
1683 
1684  if (newstring.find("FALSE")!=std::string::npos)
1685  return false;
1686 
1687  // And if we don't find that, let's search for an integer and use C unsigned
1688  // int->bool conversion before giving up; i.e. a user could specify "0" for
1689  // false or "1" for true
1690  std::istringstream in_string(String);
1691  unsigned int retval;
1692  in_string >> retval;
1693  if (in_string.fail())
1694  {
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;
1697  getpot_error();
1698  }
1699 
1700  return retval;
1701 }
1702 
1703 
1704 
1705 inline const char*
1706 GetPot::_internal_managed_copy(const std::string& Arg) const
1707 {
1708  const char* arg = Arg.c_str();
1709 
1710  // Get a lock before touching anything mutable
1711  SCOPED_MUTEX;
1712 
1713  // See if there's already an identical string saved
1714  std::set<const char*,ltstr>::const_iterator it =
1715  _internal_string_container.find(arg);
1716 
1717  // If so, return it
1718  if (it != _internal_string_container.end())
1719  return *it;
1720 
1721  // Otherwise, create a new one
1722  const std::size_t bufsize = strlen(arg)+1;
1723  char* newcopy = new char[bufsize];
1724  strncpy(newcopy, arg, bufsize);
1725  _internal_string_container.insert(newcopy);
1726  return newcopy;
1727 }
1728 
1729 
1730 
1732 // (*) cursor oriented functions
1733 //.............................................................................
1734 
1735 // Checks if 'String' begins with 'Start' and returns the remaining String.
1736 // Returns None if String does not begin with Start.
1737 inline const std::string
1738 GetPot::_get_remaining_string(const std::string& String, const std::string& Start) const
1739 {
1740  if (Start == "")
1741  return String;
1742 
1743  // note: java.lang.String: substring(a,b) = from a to b-1
1744  // C++ string: substr(a,b) = from a to a + b
1745  if (String.find(Start) == 0)
1746  return String.substr(Start.length());
1747 
1748  else
1749  return "";
1750 }
1751 
1752 
1753 
1754 // -- search for a certain argument and set cursor to position
1755 inline bool
1756 GetPot::search(const std::string &Option)
1757 {
1758  return search(Option.c_str());
1759 }
1760 
1761 
1762 
1763 // -- search for a certain argument and set cursor to position
1764 inline bool
1765 GetPot::search(const char* Option)
1766 {
1767  unsigned OldCursor = cursor;
1768  const std::string SearchTerm = prefix + Option;
1769 
1770  // (*) record requested arguments for later ufo detection
1771  _record_argument_request(SearchTerm);
1772 
1773  if (OldCursor >= argv.size())
1774  OldCursor = getpot_cast_int<unsigned>(argv.size() - 1);
1775  search_failed_f = true;
1776 
1777  // (*) first loop from cursor position until end
1778  for (unsigned c = cursor; c < argv.size(); c++)
1779  {
1780  if (argv[c] == SearchTerm)
1781  {
1782  cursor = c;
1783  search_failed_f = false;
1784  return true;
1785  }
1786  }
1787  if (!search_loop_f)
1788  return false;
1789 
1790  // (*) second loop from 0 to old cursor position
1791  for (unsigned c = 1; c <= OldCursor; c++)
1792  {
1793  if (argv[c] == SearchTerm)
1794  {
1795  cursor = c;
1796  search_failed_f = false;
1797  return true;
1798  }
1799  }
1800 
1801  // in case nothing is found the cursor stays where it was
1802  return false;
1803 }
1804 
1805 
1806 
1807 inline bool
1808 GetPot::search(unsigned No, const char* P, ...)
1809 {
1810  // (*) recording the requested arguments happens in subroutine 'search'
1811  if (No == 0)
1812  return false;
1813 
1814  // search for the first argument
1815  if (search(P) == true)
1816  return true;
1817 
1818  // start interpreting variable argument list
1819  va_list ap;
1820  va_start(ap, P);
1821  unsigned i = 1;
1822  for (; i < No; i++)
1823  {
1824  char* Opt = va_arg(ap, char *);
1825  // (*) search records itself for later ufo detection
1826  if (search(Opt) == true)
1827  break;
1828  }
1829 
1830  if (i < No)
1831  {
1832  i++;
1833  // loop was left before end of array --> hit but
1834  // make sure that the rest of the search terms is marked
1835  // as requested.
1836  for (; i < No; i++)
1837  {
1838  char* Opt = va_arg(ap, char *);
1839  // (*) record requested arguments for later ufo detection
1841  }
1842  va_end(ap);
1843  return true;
1844  }
1845 
1846  va_end(ap);
1847  // loop was left normally --> no hit
1848  return false;
1849 }
1850 
1851 
1852 
1853 inline void
1855 {
1856  search_failed_f = false;
1857  cursor = 0;
1858 }
1859 
1860 
1861 
1862 inline void
1864 {
1865  disable_loop();
1866  reset_cursor();
1867 }
1868 
1869 
1870 
1872 // (*) direct access to command line arguments
1873 //.............................................................................
1874 //
1875 inline const char*
1876 GetPot::operator[](unsigned idx) const
1877 {
1878  return idx<argv.size() ? argv[idx].c_str() : 0;
1879 }
1880 
1881 
1882 
1883 template <typename T>
1884 inline T
1885 GetPot::get(unsigned int Idx, const T& Default) const
1886 {
1887  if (Idx >= argv.size())
1888  return Default;
1889  return _convert_to_type(argv[Idx], Default);
1890 }
1891 
1892 
1893 
1894 inline const char*
1895 GetPot::get(unsigned int Idx, const char* Default) const
1896 {
1897  if (Idx >= argv.size())
1898  return Default;
1899  return argv[Idx].c_str();
1900 }
1901 
1902 
1903 
1904 inline unsigned
1906 {
1907  return getpot_cast_int<unsigned>(argv.size());
1908 }
1909 
1910 
1911 
1912 // -- next() function group
1913 template <typename T>
1914 inline T
1915 GetPot::next(const T& Default)
1916 {
1917  if (search_failed_f)
1918  return Default;
1919  cursor++;
1920  if (cursor >= argv.size())
1921  {
1922  cursor = getpot_cast_int<unsigned>(argv.size());
1923  return Default;
1924  }
1925 
1926  // (*) record requested argument for later ufo detection
1928 
1929  const std::string Remain = _get_remaining_string(argv[cursor], prefix);
1930 
1931  return Remain != "" ? _convert_to_type(Remain, Default) : Default;
1932 }
1933 
1934 
1935 
1936 inline const char*
1937 GetPot::next(const char* Default)
1938 {
1939  return _internal_managed_copy(next(std::string(Default)));
1940 }
1941 
1942 
1943 
1944 // -- follow() function group
1945 // distinct option to be searched for
1946 template <typename T>
1947 inline T
1948 GetPot::follow(const T& Default, const char* Option)
1949 {
1950  // (*) record requested of argument is entirely handled in 'search()' and 'next()'
1951  if (search(Option) == false)
1952  return Default;
1953 
1954  return next(Default);
1955 }
1956 
1957 
1958 
1959 inline const char*
1960 GetPot::follow(const char* Default, const char* Option)
1961 {
1962  return _internal_managed_copy(follow(std::string(Default), Option));
1963 }
1964 
1965 
1966 
1967 // -- second follow() function group
1968 // multiple option to be searched for
1969 template <typename T>
1970 inline T
1971 GetPot::follow(const T& Default, unsigned int No, const char* P, ...)
1972 {
1973  // (*) record requested of argument is entirely handled in 'search()' and 'next()'
1974  if (No == 0)
1975  return Default;
1976 
1977  if (search(P) == true)
1978  return next(Default);
1979 
1980  va_list ap;
1981  va_start(ap, P);
1982  for (unsigned i=1; i<No; i++)
1983  {
1984  char* Opt = va_arg(ap, char *);
1985  if (search(Opt) == true)
1986  {
1987  va_end(ap);
1988  return next(Default);
1989  }
1990  }
1991  va_end(ap);
1992  return Default;
1993 }
1994 
1995 
1996 
1997 inline const char*
1998 GetPot::follow(const char* Default, unsigned No, const char* P, ...)
1999 {
2000  // (*) record requested of argument is entirely handled in 'search()' and 'next()'
2001  if (No == 0)
2002  return Default;
2003 
2004  if (search(P) == true)
2005  return next(Default);
2006 
2007  va_list ap;
2008  va_start(ap, P);
2009  for (unsigned i=1; i<No; i++)
2010  {
2011  char* Opt = va_arg(ap, char *);
2012  if (search(Opt) == true)
2013  {
2014  va_end(ap);
2015  return next(Default);
2016  }
2017  }
2018  va_end(ap);
2019  return Default;
2020 }
2021 
2022 
2023 
2025 // (*) directly connected options
2026 //.............................................................................
2027 //
2028 template <typename T>
2029 inline T
2030 GetPot::direct_follow(const T& Default, const char* Option)
2031 {
2032  const char* FollowStr = _match_starting_string(Option);
2033 
2034  // (*) record requested of argument for later ufo-detection
2035  _record_argument_request(std::string(Option) + FollowStr);
2036 
2037  if (FollowStr == 0)
2038  return Default;
2039 
2040  if (++cursor >= argv.size())
2041  cursor = getpot_cast_int<unsigned>(argv.size());
2042  return _convert_to_type(FollowStr, Default);
2043 }
2044 
2045 
2046 
2047 inline const char*
2048 GetPot::direct_follow(const char* Default, const char* Option)
2049 {
2050  return _internal_managed_copy(direct_follow(std::string(Default), Option));
2051 }
2052 
2053 
2054 
2055 // pointer to the place where the string after
2056 // the match inside the found argument starts.
2057 // 0 no argument matches the starting string.
2058 inline const char*
2059 GetPot::_match_starting_string(const char* StartString)
2060 {
2061  const unsigned N =
2062  getpot_cast_int<unsigned>(strlen(StartString));
2063  unsigned OldCursor = cursor;
2064 
2065  if (OldCursor >= argv.size())
2066  OldCursor = getpot_cast_int<unsigned>(argv.size() - 1);
2067  search_failed_f = true;
2068 
2069  // (*) first loop from cursor position until end
2070  for (unsigned c = cursor; c < argv.size(); c++)
2071  {
2072  if (strncmp(StartString, argv[c].c_str(), N) == 0)
2073  {
2074  cursor = c;
2075  search_failed_f = false;
2076  return &(argv[c].c_str()[N]);
2077  }
2078  }
2079 
2080  if (!search_loop_f)
2081  return NULL;
2082 
2083  // (*) second loop from 0 to old cursor position
2084  for (unsigned c = 1; c < OldCursor; c++)
2085  {
2086  if (strncmp(StartString, argv[c].c_str(), N) == 0)
2087  {
2088  cursor = c;
2089  search_failed_f = false;
2090  return &(argv[c].c_str()[N]);
2091  }
2092  }
2093  return 0;
2094 }
2095 
2096 
2097 
2099 // (*) search for flags
2100 //.............................................................................
2101 //
2102 inline bool
2103 GetPot::options_contain(const char* FlagList) const
2104 {
2105  // go through all arguments that start with a '-' (but not '--')
2106  std::string str;
2107  STRING_VECTOR::const_iterator it = argv.begin();
2108  for (; it != argv.end(); ++it)
2109  {
2110  str = _get_remaining_string(*it, prefix);
2111 
2112  if (str.length() >= 2 && str[0] == '-' && str[1] != '-')
2113  if (_check_flags(str, FlagList))
2114  return true;
2115  }
2116  return false;
2117 }
2118 
2119 
2120 
2121 inline bool
2122 GetPot::argument_contains(unsigned Idx, const char* FlagList) const
2123 {
2124  if (Idx >= argv.size())
2125  return false;
2126 
2127  // (*) record requested of argument for later ufo-detection
2128  // an argument that is checked for flags is considered to be 'requested'
2130 
2131  if (prefix == "")
2132  // search argument for any flag in flag list
2133  return _check_flags(argv[Idx], FlagList);
2134 
2135  // if a prefix is set, then the argument index is the index
2136  // inside the 'namespace'
2137  // => only check list of arguments that start with prefix
2138  unsigned no_matches = 0;
2139  for (unsigned i=0; i<argv.size(); i++)
2140  {
2141  const std::string Remain = _get_remaining_string(argv[i], prefix);
2142  if (Remain != "")
2143  {
2144  no_matches += 1;
2145  if (no_matches == Idx)
2146  return _check_flags(Remain, FlagList);
2147  }
2148  }
2149 
2150  // no argument in this namespace
2151  return false;
2152 }
2153 
2154 
2155 
2156 inline bool
2157 GetPot::_check_flags(const std::string& Str, const char* FlagList) const
2158 {
2159  for (const char* p=FlagList; *p != '\0' ; p++)
2160  if (Str.find(*p) != std::string::npos)
2161  return true; // found something
2162  return false;
2163 }
2164 
2165 
2166 
2168 // (*) nominus arguments
2169 
2170 // return vector of nominus arguments
2171 inline STRING_VECTOR
2173 {
2174  STRING_VECTOR nv;
2175  std::vector<unsigned>::const_iterator it = idx_nominus.begin();
2176  for (; it != idx_nominus.end(); ++it)
2177  {
2178  nv.push_back(argv[*it]);
2179 
2180  // (*) record for later ufo-detection
2181  // when a nominus vector is requested, the entire set of nominus arguments are
2182  // tagged as 'requested'
2184  }
2185  return nv;
2186 }
2187 
2188 
2189 
2190 inline const char*
2192 {
2193  if (nominus_cursor < int(idx_nominus.size()) - 1)
2194  {
2195  const std::string Tmp = argv[idx_nominus[++nominus_cursor]];
2196 
2197  // (*) record for later ufo-detection
2199 
2200  return _internal_managed_copy(Tmp);
2201  }
2202 
2203  return 0;
2204 }
2205 
2206 
2207 inline std::string
2209 {
2210  if (nominus_cursor < int(idx_nominus.size()) - 1)
2211  {
2212  const std::string Tmp = argv[idx_nominus[++nominus_cursor]];
2213 
2214  // (*) record for later ufo-detection
2216 
2217  return Tmp;
2218  }
2219 
2220  return "";
2221 }
2222 
2223 
2224 
2225 inline void
2227 {
2228  nominus_cursor = -1;
2229 }
2230 
2231 
2232 
2234 // (*) variables
2235 //.............................................................................
2236 //
2237 inline bool
2238 GetPot::have_variable(const char* VarName) const
2239 {
2240  const variable* sv = _request_variable(VarName);
2241 
2242  if (sv == 0)
2243  return false;
2244 
2245  return true;
2246 }
2247 
2248 
2249 
2250 inline bool
2251 GetPot::have_variable(const std::string& VarName) const
2252 {
2253  return have_variable(VarName.c_str());
2254 }
2255 
2256 inline bool
2257 GetPot::have_section(const char* section_name) const
2258 {
2259  std::string s = std::string(section_name);
2260  return this->have_section(s);
2261 }
2262 
2263 inline bool
2264 GetPot::have_section(const std::string& section_name) const
2265 {
2266  const char slash('/');
2267 
2268  std::string::const_reverse_iterator it = section_name.rbegin();
2269 
2270  bool found_section = false;
2271 
2272  // Check if section_name ends with a "/". If not, append it for the search since
2273  // the section names are stored with a "/" at the end.
2274  if( (*it) != slash )
2275  // We need to use a linear search because we can't sort section_list
2276  // without violating some assumptions. See libMesh #481 for more discussion.
2277  found_section = ( std::find(section_list.begin(), section_list.end(), section_name+slash) != section_list.end() );
2278  else
2279  found_section = ( std::find(section_list.begin(), section_list.end(), section_name) != section_list.end() );
2280 
2281  return found_section;
2282 }
2283 
2284 template <typename T>
2285 inline T
2286 GetPot::operator()(const char* VarName, const T& Default) const
2287 {
2288  // (*) recording of requested variables happens in '_request_variable()'
2289  const variable* sv = _request_variable(VarName);
2290 
2291  if (sv == 0)
2292  return Default;
2293 
2294  return _convert_to_type(sv->original, Default);
2295 }
2296 
2297 
2298 
2299 template <typename T>
2300 inline T
2301 GetPot::operator()(const std::string& VarName, const T& Default) const
2302 {
2303  return operator()(VarName.c_str(), Default);
2304 }
2305 
2306 
2307 
2308 inline const char*
2309 GetPot::operator()(const char* VarName, const char* Default) const
2310 {
2311  return _internal_managed_copy(operator()(VarName, std::string(Default)));
2312 }
2313 
2314 
2315 
2316 inline const char*
2317 GetPot::operator()(const std::string& VarName, const char* Default) const
2318 {
2319  return operator()(VarName.c_str(), Default);
2320 }
2321 
2322 
2323 
2324 template <typename T>
2325 inline T
2326 GetPot::operator()(const char* VarName, const T& Default, unsigned int Idx) const
2327 {
2328  // (*) recording of requested variables happens in '_request_variable()'
2329  const variable* sv = _request_variable(VarName);
2330  if (sv == 0)
2331  return Default;
2332 
2333  const std::string* element = sv->get_element(Idx);
2334  if (element == 0)
2335  return Default;
2336  return _convert_to_type(*element, Default);
2337 }
2338 
2339 
2340 
2341 template <typename T>
2342 inline T
2343 GetPot::operator()(const std::string& VarName, const T& Default, unsigned int Idx) const
2344 {
2345  return operator()(VarName.c_str(), Default, Idx);
2346 }
2347 
2348 
2349 
2350 inline const char*
2351 GetPot::operator()(const char* VarName, const char* Default, unsigned int Idx) const
2352 {
2353  return _internal_managed_copy(operator()(VarName, std::string(Default), Idx));
2354 }
2355 
2356 
2357 
2358 inline const char*
2359 GetPot::operator()(const std::string& VarName, const char* Default, unsigned int Idx) const
2360 {
2361  return operator()(VarName.c_str(), Default, Idx);
2362 }
2363 
2364 
2365 
2366 template <typename T>
2367 inline T
2368 GetPot::get_value_no_default(const char* VarName, const T& Default) const
2369 {
2370  // (*) recording of requested variables happens in '_request_variable()'
2371  const variable* sv = _request_variable(VarName);
2372  if (sv == 0)
2373  {
2374  getpot_cerr << "ERROR: cannot find variable "<<VarName<<std::endl;
2375  getpot_error();
2376  }
2377  return _convert_to_type_no_default(VarName, sv->original, Default);
2378 }
2379 
2380 
2381 
2382 template <typename T>
2383 inline T
2384 GetPot::get_value_no_default(const std::string& VarName, const T& Default) const
2385 {
2386  return get_value_no_default(VarName.c_str(),Default);
2387 }
2388 
2389 
2390 
2391 inline const char*
2392 GetPot::get_value_no_default(const char* VarName, const char* Default) const
2393 {
2394  return _internal_managed_copy(get_value_no_default(VarName, std::string(Default)));
2395 }
2396 
2397 
2398 
2399 inline const char*
2400 GetPot::get_value_no_default(const std::string& VarName, const char* Default) const
2401 {
2402  return get_value_no_default(VarName.c_str(),Default);
2403 }
2404 
2405 
2406 
2407 template <typename T>
2408 inline T
2409 GetPot::get_value_no_default(const char* VarName, const T& Default, unsigned int Idx) const
2410 {
2411  // (*) recording of requested variables happens in '_request_variable()'
2412  const variable* sv = _request_variable(VarName);
2413  if (sv == 0)
2414  {
2415  getpot_cerr << "ERROR: cannot find variable "<<VarName<<std::endl;
2416  getpot_error();
2417  }
2418 
2419  const std::string* element = sv->get_element(Idx);
2420  if (element == 0)
2421  {
2422  getpot_cerr << "ERROR: cannot find index "<<Idx<<" of variable "<<VarName<<std::endl;
2423  getpot_error();
2424  }
2425  return _convert_to_type_no_default(VarName, *element, Default);
2426 }
2427 
2428 
2429 
2430 template <typename T>
2431 inline T
2432 GetPot::get_value_no_default(const std::string& VarName, const T& Default, unsigned int Idx) const
2433 {
2434  return get_value_no_default(VarName.c_str(), Default, Idx);
2435 }
2436 
2437 
2438 
2439 inline const char*
2440 GetPot::get_value_no_default(const char* VarName, const char* Default, unsigned int Idx) const
2441 {
2442  return _internal_managed_copy(get_value_no_default(VarName, std::string(Default), Idx));
2443 }
2444 
2445 
2446 
2447 inline const char*
2448 GetPot::get_value_no_default(const std::string& VarName, const char* Default, unsigned int Idx) const
2449 {
2450  return get_value_no_default(VarName.c_str(), Default, Idx);
2451 }
2452 
2453 
2454 
2455 inline void
2456 GetPot::_record_argument_request(const std::string& Name) const
2457 {
2458  if (!request_recording_f)
2459  return;
2460 
2461  // Get a lock before touching anything mutable
2462  SCOPED_MUTEX;
2463 
2464  // (*) record requested variable for later ufo detection
2465  _requested_arguments.insert(Name);
2466 
2467  // (*) record considered section for ufo detection
2468  STRING_VECTOR STree = _get_section_tree(Name);
2469  victorate(std::string, STree, it)
2470  if (_requested_sections.find(*it) == _requested_sections.end())
2471  if (section.length() != 0)
2472  _requested_sections.insert(*it);
2473 }
2474 
2475 
2476 
2477 inline void
2478 GetPot::_record_variable_request(const std::string& Name) const
2479 {
2480  if (!request_recording_f)
2481  return;
2482 
2483  // Get a lock before touching anything mutable
2484  SCOPED_MUTEX;
2485 
2486  // (*) record requested variable for later ufo detection
2487  _requested_variables.insert(Name);
2488 
2489  // (*) record considered section for ufo detection
2490  STRING_VECTOR STree = _get_section_tree(Name);
2491  victorate(std::string, STree, it)
2492  if (_requested_sections.find(*it) == _requested_sections.end())
2493  if (section.length() != 0)
2494  _requested_sections.insert(*it);
2495 }
2496 
2497 
2498 
2499 // (*) following functions are to be used from 'outside', after getpot has parsed its
2500 // arguments => append an argument in the argument vector that reflects the addition
2501 inline void
2502 GetPot::_set_variable(const std::string& VarName,
2503  const std::string& Value, const bool Requested /* = true */)
2504 {
2505  const GetPot::variable* Var = Requested ?
2506  _request_variable(VarName.c_str()) :
2507  _find_variable(VarName.c_str());
2508  if (Var == 0)
2509  variables.push_back(variable(VarName.c_str(), Value.c_str(), _field_separator.c_str()));
2510  else
2511  {
2512  overridden_vars.insert(VarName.c_str());
2513  (const_cast<GetPot::variable*>(Var))->take(Value.c_str(), _field_separator.c_str());
2514  }
2515 }
2516 
2517 
2518 
2519 template <typename T>
2520 inline void
2521 GetPot::set(const char* VarName, const T& Value, const bool Requested /* = true */)
2522 {
2523  std::ostringstream string_value;
2524  string_value << Value;
2525  _set_variable(VarName, string_value.str().c_str(), Requested);
2526 }
2527 
2528 
2529 
2530 template <typename T>
2531 inline void
2532 GetPot::set(const std::string& VarName, const T& Value, const bool Requested /* = true */)
2533 {
2534  set(VarName.c_str(), Value, Requested);
2535 }
2536 
2537 
2538 
2539 inline void
2540 GetPot::set(const char* VarName, const char* Value, const bool Requested /* = true */)
2541 {
2542  _set_variable(VarName, Value, Requested);
2543 }
2544 
2545 
2546 
2547 inline void
2548 GetPot::set(const std::string& VarName, const char* Value, const bool Requested /* = true */)
2549 {
2550  set(VarName.c_str(), Value, Requested);
2551 }
2552 
2553 
2554 
2555 inline unsigned
2556 GetPot::vector_variable_size(const char* VarName) const
2557 {
2558  const variable* sv = _request_variable(VarName);
2559  if (sv == 0)
2560  return 0;
2561  return (unsigned)(sv->value.size());
2562 }
2563 
2564 
2565 
2566 inline unsigned
2567 GetPot::vector_variable_size(const std::string& VarName) const
2568 {
2569  return vector_variable_size(VarName.c_str());
2570 }
2571 
2572 
2573 
2574 inline STRING_VECTOR
2576 {
2577  STRING_VECTOR result;
2578  std::vector<GetPot::variable>::const_iterator it = variables.begin();
2579  for (; it != variables.end(); ++it)
2580  {
2581  const std::string Tmp = _get_remaining_string((*it).name, prefix);
2582  if (Tmp != "")
2583  result.push_back(Tmp);
2584  }
2585  return result;
2586 }
2587 
2588 
2589 
2590 inline STRING_VECTOR
2592 {
2593  return section_list;
2594 }
2595 
2596 
2597 
2598 inline STRING_VECTOR
2599 GetPot::get_subsection_names(const std::string & sec_prefix) const
2600 {
2601  // GetPot functions should understand user-provided section names
2602  // either with or without a trailing slash.
2603  const std::string full_prefix =
2604  *sec_prefix.rbegin() == '/' ? sec_prefix : sec_prefix + '/';
2605 
2606  const std::size_t full_prefix_len = full_prefix.size();
2607 
2608  // Subsections-of-subsections are in the section_list, so we'll be
2609  // adding subsections multiple times. Using std::set as an
2610  // intermediate data structure helps us check for duplicates with
2611  // O(N log N) rather than O(N^2) cost.
2612  std::set<std::string> subsections;
2613 
2614  STRING_VECTOR returnval;
2615 
2616  for (STRING_VECTOR::const_iterator it = section_list.begin();
2617  it != section_list.end(); ++it)
2618  {
2619  const std::string & section_name = *it;
2620 
2621  // If this section name begins with the prefix
2622  if (section_name.compare(0, full_prefix_len, full_prefix) == 0)
2623  {
2624  const std::size_t next_slash_len =
2625  section_name.find('/', full_prefix_len);
2626 
2627  const std::string subsection_name =
2628  section_name.substr(full_prefix_len,
2629  next_slash_len - full_prefix_len);
2630 
2631  // If there is a subsection, and if this is the first time
2632  // we've seen it, add the prefix-less, postfix-less
2633  // subsection name.
2634  if (!subsection_name.empty() &&
2635  !subsections.count(subsection_name))
2636  {
2637  returnval.push_back(subsection_name);
2638  subsections.insert(subsection_name);
2639  }
2640  }
2641  }
2642 
2643  return returnval;
2644 }
2645 
2646 
2647 
2648 inline std::set<std::string>
2650 {
2651  return overridden_vars;
2652 }
2653 
2654 
2655 
2656 inline const GetPot::variable*
2657 GetPot::_find_variable(const char* VarName) const
2658 {
2659  const std::string Name = prefix + VarName;
2660 
2661  std::vector<variable>::const_iterator it = variables.begin();
2662  for (; it != variables.end(); ++it)
2663  {
2664  if ((*it).name == Name)
2665  return &(*it);
2666  }
2667  return 0;
2668 }
2669 
2670 
2671 
2672 inline const GetPot::variable*
2673 GetPot::_request_variable(const char* VarName) const
2674 {
2675  // (*) record requested variable for later ufo detection
2676  this->_record_variable_request(VarName);
2677 
2678  return this->_find_variable(VarName);
2679 }
2680 
2681 
2682 
2684 // (*) ouput (basically for debugging reasons
2685 //.............................................................................
2686 //
2687 inline int
2688 GetPot::print(std::ostream &out_stream) const
2689 {
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;
2695  return 1;
2696 }
2697 
2698 
2699 
2700 // PECOS/HPCT Addition - add option to prepend output with a delimiter
2701 // while also disabling argc print and skipping first print (the name
2702 // of the input file)
2703 //
2704 // PECOS Development Team: (ks. 4/16/09)
2705 inline int
2706 GetPot::print(const char* custom_prefix, std::ostream &out_stream, unsigned int skip_count) const
2707 {
2708  STRING_VECTOR::const_iterator it = argv.begin();
2709  it += skip_count;
2710  for (; it != argv.end(); ++it)
2711  {
2712  out_stream << custom_prefix;
2713  out_stream << *it << std::endl;
2714  }
2715  out_stream << std::endl;
2716  return 1;
2717 }
2718 
2719 
2720 
2721 // (*) dollar bracket expressions (DBEs) ------------------------------------
2722 //
2723 // 1) Entry Function: _DBE_expand_string()
2724 // Takes a string such as
2725 //
2726 // "${+ ${x} ${y}} Subject-${& ${section} ${subsection}}: ${title}"
2727 //
2728 // calls _DBE_expand() for each of the expressions
2729 //
2730 // ${+ ${x} ${y}}
2731 // ${& ${section} ${subsection}}
2732 // ${Title}
2733 //
2734 // and returns the string
2735 //
2736 // "4711 Subject-1.01: Mit den Clowns kamen die Schwaene"
2737 //
2738 // assuming that
2739 // x = "4699"
2740 // y = "12"
2741 // section = "1."
2742 // subsection = "01"
2743 // title = "Mit den Clowns kamen die Schwaene"
2744 //
2745 // 2) _DBE_expand():
2746 //
2747 // checks for the command, i.e. the 'sign' that follows '${'
2748 // divides the argument list into sub-expressions using
2749 // _DBE_get_expr_list()
2750 //
2751 // ${+ ${x} ${y}} -> "${x}" "${y}"
2752 // ${& ${section} ${subsection}} -> "${section}" "${subsection}"
2753 // ${Title} -> Nothing, variable expansion
2754 //
2755 // 3) _DBE_expression_list():
2756 //
2757 // builds a vector of unbracketed whitespace separated strings, i.e.
2758 //
2759 // " ${Number}.a ${: Das Marmorbild} AB-${& Author= ${Eichendorf}-1870}"
2760 //
2761 // is split into a vector
2762 //
2763 // [0] ${Number}.a
2764 // [1] ${: Das Marmorbild}
2765 // [2] AB-${& Author= ${Eichendorf}}-1870
2766 //
2767 // Each sub-expression is expanded using expand().
2768 //---------------------------------------------------------------------------
2769 inline std::string
2770 GetPot::_DBE_expand_string(const std::string& str)
2771 {
2772  // Parses for closing operators '${ }' and expands them letting
2773  // white spaces and other letters as they are.
2774  std::string new_string = "";
2775  unsigned open_brackets = 0;
2776  unsigned first = 0;
2777  for (unsigned i = 0; i<str.size(); i++)
2778  {
2779  if (i < str.size() - 2 && str.substr(i, 2) == "${")
2780  {
2781  if (open_brackets == 0)
2782  first = i+2;
2783  open_brackets++;
2784  }
2785  else if (str[i] == '}' && open_brackets > 0)
2786  {
2787  open_brackets -= 1;
2788  if (open_brackets == 0)
2789  {
2790  const std::string Replacement = _DBE_expand(str.substr(first, i - first));
2791  new_string += Replacement;
2792  }
2793  }
2794  else if (open_brackets == 0)
2795  new_string += str[i];
2796  }
2797  return new_string;
2798 }
2799 
2800 
2801 
2802 inline STRING_VECTOR
2803 GetPot::_DBE_get_expr_list(const std::string& str_, const unsigned ExpectedNumber)
2804 {
2805  // ensures that the resulting vector has the expected number
2806  // of arguments, but they may contain an error message
2807  std::string str = str_;
2808  // Separates expressions by non-bracketed whitespaces, expands them
2809  // and puts them into a list.
2810 
2811  unsigned i=0;
2812  // (1) eat initial whitespaces
2813  for (; i < str.size(); i++)
2814  if (!isspace(str[i]))
2815  break;
2816 
2817  STRING_VECTOR expr_list;
2818  unsigned open_brackets = 0;
2819  std::vector<unsigned> start_idx;
2820  unsigned start_new_string = i;
2821  unsigned l = (unsigned)(str.size());
2822 
2823  // (2) search for ${ } expressions ...
2824  while (i < l)
2825  {
2826  const char letter = str[i];
2827  // whitespace -> end of expression
2828  if (isspace(letter) && open_brackets == 0)
2829  {
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++)
2833  {
2834  if (!isspace(str[i]))
2835  {
2836  no_breakout_f = false;
2837  start_new_string = i;
2838  break;
2839  }
2840  }
2841 
2842  if (no_breakout_f)
2843  {
2844  // end of expression list
2845  if (expr_list.size() < ExpectedNumber)
2846  {
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());
2850  }
2851  return expr_list;
2852  }
2853  }
2854 
2855  // dollar-bracket expression
2856  if (str.length() >= i+2 && str.substr(i, 2) == "${")
2857  {
2858  open_brackets++;
2859  start_idx.push_back(i+2);
2860  }
2861 
2862  else if (letter == '}' && open_brackets > 0)
2863  {
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);
2869  else
2870  str = str.substr(0, start-2) + Replacement + str.substr(i+1);
2871  l = (int)(str.size());
2872  i = start + (int)(Replacement.size()) - 3;
2873  open_brackets--;
2874  }
2875  i++;
2876  }
2877 
2878  // end of expression list
2879  expr_list.push_back(str.substr(start_new_string, i-start_new_string));
2880 
2881  if (expr_list.size() < ExpectedNumber)
2882  {
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());
2886  }
2887 
2888  return expr_list;
2889 }
2890 
2891 
2892 
2893 inline const GetPot::variable*
2894 GetPot::_DBE_get_variable(const std::string& VarName)
2895 {
2896  static GetPot::variable ev;
2897  std::string secure_Prefix = prefix;
2898 
2899  prefix = section;
2900  // (1) first search in currently active section
2901  const GetPot::variable* var = _request_variable(VarName.c_str());
2902  if (var != 0)
2903  {
2904  prefix = secure_Prefix;
2905  return var;
2906  }
2907 
2908  // (2) search in root name space
2909  prefix = "";
2910  var = _request_variable(VarName.c_str());
2911  if (var != 0)
2912  {
2913  prefix = secure_Prefix;
2914  return var;
2915  }
2916 
2917  prefix = secure_Prefix;
2918 
2919  // error occurred => variable name == ""
2920  ev.original = "<<${ } variable '";
2921  ev.original += VarName + "' undefined>>";
2922  return &ev;
2923 }
2924 
2925 
2926 
2927 inline std::string
2928 GetPot::_DBE_expand(const std::string& expr)
2929 {
2930  // ${: } pure text
2931  if (expr[0] == ':')
2932  return expr.substr(1);
2933 
2934  // ${& expr expr ... } text concatenation
2935  else if (expr[0] == '&')
2936  {
2937  const STRING_VECTOR A = _DBE_get_expr_list(expr.substr(1), 1);
2938 
2939  STRING_VECTOR::const_iterator it = A.begin();
2940  std::string result = *it++;
2941  for (; it != A.end(); ++it) result += *it;
2942 
2943  return result;
2944  }
2945 
2946  // ${<-> expr expr expr} text replacement
2947  else if (expr.length() >= 3 && expr.substr(0, 3) == "<->")
2948  {
2949  STRING_VECTOR A = _DBE_get_expr_list(expr.substr(3), 3);
2950  size_t tmp = 0;
2951  const size_t L = A[1].length();
2952 
2953  while ((tmp = A[0].find(A[1])) != std::string::npos)
2954  A[0].replace(tmp, L, A[2]);
2955 
2956  return A[0];
2957  }
2958 
2959  // ${=func [expr...] } function evaluation
2960  else if (expr.length() >= 2 &&
2961  expr.substr(0, 1) == "=" &&
2962  expr.substr(0, 2) != "==")
2963  {
2964  size_t funcnamestart = expr.find_first_not_of(" \t", 1);
2965  if (funcnamestart != std::string::npos)
2966  {
2967  size_t funcnameend = expr.find_first_of(" \t",funcnamestart);
2968  std::string funcname = expr.substr(funcnamestart,
2969  funcnameend-funcnamestart);
2970  if (funcname == "log")
2971  {
2972  STRING_VECTOR A =
2973  _DBE_get_expr_list(expr.substr(funcnameend), 1);
2974  double arg = _convert_to_type(A[0], 0.0);
2975  return _convert_from_type(std::log(arg));
2976  }
2977  else if (funcname == "log10")
2978  {
2979  STRING_VECTOR A =
2980  _DBE_get_expr_list(expr.substr(funcnameend), 1);
2981  double arg = _convert_to_type(A[0], 0.0);
2982  return _convert_from_type(std::log10(arg));
2983  }
2984  else if (funcname == "exp")
2985  {
2986  STRING_VECTOR A =
2987  _DBE_get_expr_list(expr.substr(funcnameend), 1);
2988  double arg = _convert_to_type(A[0], 0.0);
2989  return _convert_from_type(std::exp(arg));
2990  }
2991  else if (funcname == "sin")
2992  {
2993  STRING_VECTOR A =
2994  _DBE_get_expr_list(expr.substr(funcnameend), 1);
2995  double arg = _convert_to_type(A[0], 0.0);
2996  return _convert_from_type(std::sin(arg));
2997  }
2998  else if (funcname == "cos")
2999  {
3000  STRING_VECTOR A =
3001  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3002  double arg = _convert_to_type(A[0], 0.0);
3003  return _convert_from_type(std::cos(arg));
3004  }
3005  else if (funcname == "tan")
3006  {
3007  STRING_VECTOR A =
3008  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3009  double arg = _convert_to_type(A[0], 0.0);
3010  return _convert_from_type(std::tan(arg));
3011  }
3012  else if (funcname == "asin")
3013  {
3014  STRING_VECTOR A =
3015  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3016  double arg = _convert_to_type(A[0], 0.0);
3017  return _convert_from_type(std::asin(arg));
3018  }
3019  else if (funcname == "acos")
3020  {
3021  STRING_VECTOR A =
3022  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3023  double arg = _convert_to_type(A[0], 0.0);
3024  return _convert_from_type(std::acos(arg));
3025  }
3026  else if (funcname == "atan")
3027  {
3028  STRING_VECTOR A =
3029  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3030  double arg = _convert_to_type(A[0], 0.0);
3031  return _convert_from_type(std::atan(arg));
3032  }
3033  else if (funcname == "atan2")
3034  {
3035  STRING_VECTOR A =
3036  _DBE_get_expr_list(expr.substr(funcnameend), 2);
3037  double arg1 = _convert_to_type(A[0], 0.0);
3038  double arg2 = _convert_to_type(A[1], 0.0);
3039  return _convert_from_type(std::atan2(arg1, arg2));
3040  }
3041  else if (funcname == "sinh")
3042  {
3043  STRING_VECTOR A =
3044  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3045  double arg = _convert_to_type(A[0], 0.0);
3046  return _convert_from_type(std::sinh(arg));
3047  }
3048  else if (funcname == "cosh")
3049  {
3050  STRING_VECTOR A =
3051  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3052  double arg = _convert_to_type(A[0], 0.0);
3053  return _convert_from_type(std::cosh(arg));
3054  }
3055  else if (funcname == "tanh")
3056  {
3057  STRING_VECTOR A =
3058  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3059  double arg = _convert_to_type(A[0], 0.0);
3060  return _convert_from_type(std::tanh(arg));
3061  }
3062 #ifdef HAVE_INVERSE_HYPERBOLIC_SINE
3063  else if (funcname == "asinh")
3064  {
3065  STRING_VECTOR A =
3066  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3067  double arg = _convert_to_type(A[0], 0.0);
3068  return _convert_from_type(std::asinh(arg));
3069  }
3070 #endif
3071 #ifdef HAVE_INVERSE_HYPERBOLIC_COSINE
3072  else if (funcname == "acosh")
3073  {
3074  STRING_VECTOR A =
3075  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3076  double arg = _convert_to_type(A[0], 0.0);
3077  return _convert_from_type(std::acosh(arg));
3078  }
3079 #endif
3080 #ifdef HAVE_INVERSE_HYPERBOLIC_TANGENT
3081  else if (funcname == "atanh")
3082  {
3083  STRING_VECTOR A =
3084  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3085  double arg = _convert_to_type(A[0], 0.0);
3086  return _convert_from_type(std::atanh(arg));
3087  }
3088 #endif
3089  else if (funcname == "sqrt")
3090  {
3091  STRING_VECTOR A =
3092  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3093  double arg = _convert_to_type(A[0], 0.0);
3094  return _convert_from_type(std::sqrt(arg));
3095  }
3096  else if (funcname == "abs")
3097  {
3098  STRING_VECTOR A =
3099  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3100  double arg = _convert_to_type(A[0], 0.0);
3101  return _convert_from_type(std::abs(arg));
3102  }
3103  else if (funcname == "max")
3104  {
3105  STRING_VECTOR A =
3106  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3107  STRING_VECTOR::const_iterator it = A.begin();
3108  double result = _convert_to_type(*it++, 0.0);
3109  for (; it != A.end(); ++it)
3110  result = std::max(result, _convert_to_type(*it, 0.0));
3111  return _convert_from_type(result);
3112  }
3113  else if (funcname == "min")
3114  {
3115  STRING_VECTOR A =
3116  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3117  STRING_VECTOR::const_iterator it = A.begin();
3118  double result = _convert_to_type(*it++, 0.0);
3119  for (; it != A.end(); ++it)
3120  result = std::min(result, _convert_to_type(*it, 0.0));
3121  return _convert_from_type(result);
3122  }
3123  else if (funcname == "ceil")
3124  {
3125  STRING_VECTOR A =
3126  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3127  double arg = _convert_to_type(A[0], 0.0);
3128  return _convert_from_type(std::ceil(arg));
3129  }
3130  else if (funcname == "floor")
3131  {
3132  STRING_VECTOR A =
3133  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3134  double arg = _convert_to_type(A[0], 0.0);
3135  return _convert_from_type(std::floor(arg));
3136  }
3137  else if (funcname == "fmod")
3138  {
3139  STRING_VECTOR A =
3140  _DBE_get_expr_list(expr.substr(funcnameend), 2);
3141  double arg1 = _convert_to_type(A[0], 0.0);
3142  double arg2 = _convert_to_type(A[1], 0.0);
3143  return _convert_from_type(std::fmod(arg1, arg2));
3144  }
3145  else if (funcname == "srand")
3146  {
3147  STRING_VECTOR A =
3148  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3149  unsigned int arg = _convert_to_type(A[0], 0u);
3150  std::srand(arg);
3151  return A[0];
3152  }
3153  // ${=rand range} with default range==RAND_MAX
3154  else if (funcname == "rand")
3155  {
3156  if (funcnameend >= expr.length() ||
3157  expr.find_first_not_of(" \t", funcnameend) == std::string::npos)
3158  return _convert_from_type(std::rand());
3159 
3160  STRING_VECTOR A =
3161  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3162  unsigned int range = _convert_to_type(A[0],0u);
3163  if (!range)
3164  return _convert_from_type(0);
3165  const unsigned int x = (RAND_MAX + 1u) / range;
3166  const unsigned int y = x * range;
3167  unsigned int returnval;
3168  do
3169  {
3170  returnval = rand();
3171  } while (returnval >= y);
3172  return _convert_from_type(returnval / x);
3173  }
3174  else if (funcname == "time")
3175  return _convert_from_type(std::time(NULL));
3176  else
3177  {
3178  getpot_cerr << "ERROR: unrecognized function "
3179  << funcname << std::endl;
3180  getpot_error();
3181  }
3182  }
3183  }
3184 
3185  // ${+ ...}, ${- ...}, ${* ...}, ${/ ...} expressions
3186  else if (expr[0] == '+')
3187  {
3188  STRING_VECTOR A = _DBE_get_expr_list(expr.substr(1), 2);
3189  STRING_VECTOR::const_iterator it = A.begin();
3190  double result = _convert_to_type(*it++, 0.0);
3191  for (; it != A.end(); ++it)
3192  result += _convert_to_type(*it, 0.0);
3193 
3194  return _convert_from_type(result);
3195  }
3196  else if (expr[0] == '-')
3197  {
3198  STRING_VECTOR A = _DBE_get_expr_list(expr.substr(1), 2);
3199  STRING_VECTOR::const_iterator it = A.begin();
3200  double result = _convert_to_type(*it++, 0.0);
3201  for (; it != A.end(); ++it)
3202  result -= _convert_to_type(*it, 0.0);
3203 
3204  return _convert_from_type(result);
3205  }
3206  else if (expr[0] == '*')
3207  {
3208  STRING_VECTOR A = _DBE_get_expr_list(expr.substr(1), 2);
3209  STRING_VECTOR::const_iterator it = A.begin();
3210  double result = _convert_to_type(*it++, 0.0);
3211  for (; it != A.end(); ++it)
3212  result *= _convert_to_type(*it, 0.0);
3213 
3214  return _convert_from_type(result);
3215  }
3216  else if (expr[0] == '/')
3217  {
3218  STRING_VECTOR A = _DBE_get_expr_list(expr.substr(1), 2);
3219  STRING_VECTOR::const_iterator it = A.begin();
3220  double result = _convert_to_type(*it++, 0.0);
3221  if (result == 0)
3222  return "0.0";
3223 
3224  for (; it != A.end(); ++it)
3225  {
3226  const double Q = _convert_to_type(*it, 0.0);
3227  result /= Q;
3228  }
3229  return _convert_from_type(result);
3230  }
3231 
3232  // ${^ ... } power expressions
3233  else if (expr[0] == '^')
3234  {
3235  STRING_VECTOR A = _DBE_get_expr_list(expr.substr(1), 2);
3236  STRING_VECTOR::const_iterator it = A.begin();
3237  double result = _convert_to_type(*it++, 0.0);
3238  for (; it != A.end(); ++it)
3239  result = pow(result, _convert_to_type(*it, 0.0));
3240  return _convert_from_type(result);
3241  }
3242 
3243  // ${== } ${<= } ${>= } comparisons (return the number of the first 'match'
3244  else if (expr.length() >= 2 &&
3245  (expr.substr(0,2) == "==" || expr.substr(0,2) == ">=" ||
3246  expr.substr(0,2) == "<=" || expr[0] == '>' || expr[0] == '<'))
3247  {
3248  // differentiate between two and one sign operators
3249  unsigned op = 0;
3250  enum { EQ, GEQ, LEQ, GT, LT };
3251 
3252  if (expr.substr(0, 2) == "==")
3253  op = EQ;
3254 
3255  else if (expr.substr(0, 2) == ">=")
3256  op = GEQ;
3257 
3258  else if (expr.substr(0, 2) == "<=")
3259  op = LEQ;
3260 
3261  else if (expr[0] == '>')
3262  op = GT;
3263 
3264  else
3265  op = LT;
3266 
3267  STRING_VECTOR a;
3268  if (op == GT || op == LT)
3269  a = _DBE_get_expr_list(expr.substr(1), 2);
3270 
3271  else
3272  a = _DBE_get_expr_list(expr.substr(2), 2);
3273 
3274  std::string x_orig = a[0];
3275  double x = _convert_to_type(x_orig, 1e37);
3276  unsigned i = 1;
3277 
3278  STRING_VECTOR::const_iterator y_orig = a.begin();
3279  for (y_orig++; y_orig != a.end(); ++y_orig)
3280  {
3281  double y = _convert_to_type(*y_orig, 1e37);
3282 
3283  // set the strings as reference if one wasn't a number
3284  if (x == 1e37 || y == 1e37)
3285  {
3286  // it's a string comparison
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))
3290  return _convert_from_type(i);
3291  }
3292  else
3293  {
3294  // it's a number comparison
3295  if ((op == EQ && x == y) || (op == GEQ && x >= y) ||
3296  (op == LEQ && x <= y) || (op == GT && x > y) ||
3297  (op == LT && x < y))
3298  return _convert_from_type(i);
3299  }
3300  i++;
3301  }
3302 
3303  // nothing fulfills the condition => return 0
3304  return "0";
3305  }
3306 
3307  // ${?? expr expr} select
3308  else if (expr.length() >= 2 && expr.substr(0, 2) == "??")
3309  {
3310  STRING_VECTOR a = _DBE_get_expr_list(expr.substr(2), 2);
3311  double x = _convert_to_type(a[0], 1e37);
3312 
3313  // last element is always the default argument
3314  if (x == 1e37 || x < 0 || x >= double(a.size() - 1))
3315  return a[a.size()-1];
3316 
3317  // round x to closest integer
3318  return a[int(x+0.5)];
3319  }
3320 
3321  // ${? expr expr expr} if then else conditions
3322  else if (expr[0] == '?')
3323  {
3324  STRING_VECTOR a = _DBE_get_expr_list(expr.substr(1), 2);
3325 
3326  if (_convert_to_type(a[0], 0.0) == 1.0)
3327  return a[1];
3328 
3329  else if (a.size() > 2)
3330  return a[2];
3331  }
3332  // ${! expr} maxro expansion
3333  else if (expr[0] == '!')
3334  {
3335  const GetPot::variable* Var = _DBE_get_variable(expr.substr(1));
3336  // error
3337  if (Var->name == "")
3338  return std::string(Var->original);
3339 
3340  const STRING_VECTOR A = _DBE_get_expr_list(Var->original, 2);
3341  return A[0];
3342  }
3343  // ${@: } - string subscription
3344  else if (expr.length() >= 2 && expr.substr(0,2) == "@:")
3345  {
3346  const STRING_VECTOR A = _DBE_get_expr_list(expr.substr(2), 2);
3347  double x = _convert_to_type(A[1], 1e37);
3348 
3349  // last element is always the default argument
3350  if (x == 1e37 || x < 0 || x >= double(A[0].size() - 1))
3351  return "<<1st index out of range>>";
3352 
3353  if (A.size() > 2)
3354  {
3355  double y = _convert_to_type(A[2], 1e37);
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));
3358 
3359  else if (y == -1)
3360  return A[0].substr(int(x+0.5));
3361 
3362  return "<<2nd index out of range>>";
3363  }
3364  else
3365  {
3366  char* tmp = new char[2];
3367  tmp[0] = A[0][int(x+0.5)]; tmp[1] = '\0';
3368  std::string result(tmp);
3369  delete [] tmp;
3370  return result;
3371  }
3372  }
3373  // ${@ } - vector subscription
3374  else if (expr[0] == '@')
3375  {
3376  STRING_VECTOR A = _DBE_get_expr_list(expr.substr(1), 2);
3377  const GetPot::variable* Var = _DBE_get_variable(A[0]);
3378  // error
3379  if (Var->name == "")
3380  {
3381  // make a copy of the string if an error occurred
3382  // (since the error variable is a static variable inside get_variable())
3383  return std::string(Var->original);
3384  }
3385 
3386  double x = _convert_to_type(A[1], 1e37);
3387 
3388  // last element is always the default argument
3389  if (x == 1e37 || x < 0 || x >= double(Var->value.size()))
3390  return "<<1st index out of range>>";
3391 
3392  if (A.size() > 2)
3393  {
3394  double y = _convert_to_type(A[2], 1e37);
3395  int begin = int(x+0.5);
3396  int end = 0;
3397  if (y != 1e37 && y > 0 && y <= double(Var->value.size()) && y > x)
3398  end = int(y+1.5);
3399  else if (y == -1)
3400  end = int(Var->value.size());
3401  else
3402  return "<<2nd index out of range>>";
3403 
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));
3407  return result;
3408  }
3409  else
3410  return *(Var->get_element(int(x+0.5)));
3411  }
3412 
3413  const STRING_VECTOR A = _DBE_get_expr_list(expr, 1);
3414  const GetPot::variable* B = _DBE_get_variable(A[0]);
3415 
3416  // make a copy of the string if an error occurred
3417  // (since the error variable is a static variable inside get_variable())
3418  if (B->name == "")
3419  return std::string(B->original);
3420 
3421  // (psuggs@pobox.com mentioned to me the warning MSVC++6.0 produces
3422  // with: else return B->original (thanks))
3423  return B->original;
3424 }
3425 
3426 
3427 
3429 // (*) unidentified flying objects
3430 //.............................................................................
3431 //
3432 inline bool
3433 GetPot::_search_string_vector(const STRING_VECTOR& VecStr, const std::string& Str) const
3434 {
3435  victorate(std::string, VecStr, itk)
3436  {
3437  if (*itk == Str)
3438  return true;
3439  }
3440  return false;
3441 }
3442 
3443 
3444 
3445 inline STRING_VECTOR
3447  const char* KnownArgument1, ...) const
3448 {
3449  std::set<std::string> known_arguments;
3450 
3451  // (1) create a vector of known arguments
3452  if (Number == 0)
3453  return STRING_VECTOR();
3454 
3455  va_list ap;
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 *)));
3460  va_end(ap);
3461 
3462  return unidentified_arguments(known_arguments);
3463 }
3464 
3465 
3466 
3467 inline STRING_VECTOR
3469 {
3471 }
3472 
3473 
3474 
3475 inline STRING_VECTOR
3476 GetPot::unidentified_arguments(const std::vector<std::string>& Knowns) const
3477 {
3478  // We use set for efficiency, but want to support vector inputs for
3479  // backwards compatibility.
3480  return unidentified_arguments(std::set<std::string> (Knowns.begin(), Knowns.end()));
3481 }
3482 
3483 
3484 
3485 inline STRING_VECTOR
3486 GetPot::unidentified_arguments(const std::set<std::string>& Knowns) const
3487 {
3488  STRING_VECTOR ufos;
3489  STRING_VECTOR::const_iterator it = argv.begin();
3490  ++it; // forget about argv[0] (application or filename)
3491  for (; it != argv.end(); ++it)
3492  {
3493  // -- argument belongs to prefixed section ?
3494  const std::string arg = _get_remaining_string(*it, prefix);
3495  if (arg == "")
3496  continue;
3497 
3498  // -- check if in list
3499  if (Knowns.find(arg) == Knowns.end())
3500  ufos.push_back(*it);
3501  }
3502  return ufos;
3503 }
3504 
3505 
3506 
3507 inline STRING_VECTOR
3509  const char* KnownOption1, ...) const
3510 {
3511  std::set<std::string> known_options;
3512 
3513  // (1) create a vector of known arguments
3514  if (Number == 0)
3515  return STRING_VECTOR();
3516 
3517  va_list ap;
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 *)));
3522  va_end(ap);
3523 
3524  return unidentified_options(known_options);
3525 }
3526 
3527 
3528 
3529 inline STRING_VECTOR
3531 {
3532  // -- every option is an argument.
3533  // -- the set of requested arguments contains the set of requested options.
3534  // -- IF the set of requested arguments contains unrequested options,
3535  // THEN they were requested as 'follow' and 'next' arguments and not as real options.
3536  //
3537  // => it is not necessary to separate requested options from the list
3539 }
3540 
3541 
3542 
3543 inline STRING_VECTOR
3544 GetPot::unidentified_options(const std::vector<std::string>& Knowns) const
3545 {
3546  // We use set for efficiency, but want to support vector inputs for
3547  // backwards compatibility.
3548  return unidentified_options(std::set<std::string> (Knowns.begin(), Knowns.end()));
3549 }
3550 
3551 
3552 
3553 inline STRING_VECTOR
3554 GetPot::unidentified_options(const std::set<std::string>& Knowns) const
3555 {
3556  STRING_VECTOR ufos;
3557  STRING_VECTOR::const_iterator it = argv.begin();
3558  ++it; // forget about argv[0] (application or filename)
3559  for (; it != argv.end(); ++it)
3560  {
3561  // -- argument belongs to prefixed section ?
3562  const std::string arg = _get_remaining_string(*it, prefix);
3563  if (arg == "")
3564  continue;
3565 
3566  // is argument really an option (starting with '-') ?
3567  if (arg.length() < 1 || arg[0] != '-')
3568  continue;
3569 
3570  if (Knowns.find(arg) == Knowns.end())
3571  ufos.push_back(*it);
3572  }
3573 
3574  return ufos;
3575 }
3576 
3577 
3578 
3579 // Two modes:
3580 // ArgumentNumber >= 0 check specific argument
3581 // ArgumentNumber == -1 check all options starting with one '-'
3582 // for flags
3583 inline std::string
3584 GetPot::unidentified_flags(const char* KnownFlagList, int ArgumentNumber=-1) const
3585 {
3586  std::string ufos;
3587  // STRING_VECTOR known_arguments;
3588  std::string KFL(KnownFlagList);
3589 
3590  // (2) iteration over '-' arguments (options)
3591  if (ArgumentNumber == -1)
3592  {
3593  STRING_VECTOR::const_iterator it = argv.begin();
3594  ++it; // forget about argv[0] (application or filename)
3595  for (; it != argv.end(); ++it)
3596  {
3597  // -- argument belongs to prefixed section ?
3598  const std::string arg = _get_remaining_string(*it, prefix);
3599  if (arg == "") continue;
3600 
3601  // -- does arguments start with '-' (but not '--')
3602  if (arg.length() < 2)
3603  continue;
3604 
3605  else if (arg[0] != '-')
3606  continue;
3607 
3608  else if (arg[1] == '-')
3609  continue;
3610 
3611  // -- check out if flags inside option are contained in KnownFlagList
3612  const char* p=arg.c_str();
3613  p++; // skip starting minus
3614  for (; *p != '\0' ; p++)
3615  if (KFL.find(*p) == std::string::npos) ufos += *p;
3616  }
3617  }
3618  // (1) check specific argument
3619  else
3620  {
3621  // -- only check arguments that start with prefix
3622  int no_matches = 0;
3623  for (unsigned i=1; i<argv.size(); i++)
3624  {
3625  const std::string Remain = _get_remaining_string(argv[i], prefix);
3626  if (Remain != "")
3627  {
3628  no_matches++;
3629  if (no_matches == ArgumentNumber)
3630  {
3631  // -- the right argument number inside the section is found
3632  // => check it for flags
3633  const char* p = Remain.c_str();
3634  p++; // skip starting minus
3635  for (; *p != '\0' ; p++)
3636  if (KFL.find(*p) == std::string::npos) ufos += *p;
3637  return ufos;
3638  }
3639  }
3640  }
3641  }
3642  return ufos;
3643 }
3644 
3645 
3646 
3647 inline STRING_VECTOR
3649  const char* KnownVariable1, ...) const
3650 {
3651  std::set<std::string> known_variables;
3652 
3653  // create vector of known arguments
3654  if (Number == 0)
3655  return STRING_VECTOR();
3656 
3657  va_list ap;
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 *)));
3662  va_end(ap);
3663 
3664  return unidentified_variables(known_variables);
3665 }
3666 
3667 
3668 
3669 inline STRING_VECTOR
3670 GetPot::unidentified_variables(const std::vector<std::string>& Knowns) const
3671 {
3672  // We use set for efficiency, but want to support vector inputs for
3673  // backwards compatibility.
3674  return unidentified_variables(std::set<std::string> (Knowns.begin(), Knowns.end()));
3675 }
3676 
3677 
3678 
3679 inline STRING_VECTOR
3680 GetPot::unidentified_variables(const std::set<std::string>& Knowns) const
3681 {
3682  STRING_VECTOR ufos;
3683 
3684  victorate(GetPot::variable, variables, it)
3685  {
3686  // -- check if variable has specific prefix
3687  const std::string var_name = _get_remaining_string((*it).name, prefix);
3688  if (var_name == "")
3689  continue;
3690 
3691  // -- check if variable is known
3692  if (Knowns.find(var_name) == Knowns.end())
3693  ufos.push_back((*it).name);
3694  }
3695  return ufos;
3696 }
3697 
3698 
3699 
3700 inline STRING_VECTOR
3702 {
3704 }
3705 
3706 
3707 
3708 inline STRING_VECTOR
3710  const char* KnownSection1, ...) const
3711 {
3712  std::set<std::string> known_sections;
3713 
3714  // (1) create a vector of known arguments
3715  if (Number == 0)
3716  return STRING_VECTOR();
3717 
3718  va_list ap;
3719  va_start(ap, KnownSection1);
3720  known_sections.insert(std::string(KnownSection1));
3721  for (unsigned i=1; i<Number; i++)
3722  {
3723  std::string tmp = std::string(va_arg(ap, char *));
3724 
3725  if (tmp.length() == 0)
3726  continue;
3727 
3728  if (tmp[tmp.length()-1] != '/')
3729  tmp += '/';
3730 
3731  known_sections.insert(tmp);
3732  }
3733  va_end(ap);
3734 
3735  return unidentified_sections(known_sections);
3736 }
3737 
3738 
3739 
3740 inline STRING_VECTOR
3742 {
3744 }
3745 
3746 
3747 
3748 inline STRING_VECTOR
3749 GetPot::unidentified_sections(const std::vector<std::string>& Knowns) const
3750 {
3751  // We use set for efficiency, but want to support vector inputs for
3752  // backwards compatibility.
3753  return unidentified_sections(std::set<std::string> (Knowns.begin(), Knowns.end()));
3754 }
3755 
3756 
3757 
3758 inline STRING_VECTOR
3759 GetPot::unidentified_sections(const std::set<std::string>& Knowns) const
3760 {
3761  STRING_VECTOR ufos;
3762 
3763  victorate(std::string, section_list, it)
3764  {
3765  // -- check if section conform to prefix
3766  const std::string sec_name = _get_remaining_string(*it, prefix);
3767  if (sec_name == "")
3768  continue;
3769 
3770  // -- check if section is known
3771  if (Knowns.find(sec_name) == Knowns.end())
3772  ufos.push_back(*it);
3773  }
3774 
3775  return ufos;
3776 }
3777 
3778 
3779 
3780 inline STRING_VECTOR
3781 GetPot::unidentified_nominuses(unsigned Number, const char* Known, ...) const
3782 {
3783  std::set<std::string> known_nominuses;
3784 
3785  // create vector of known arguments
3786  if (Number == 0)
3787  return STRING_VECTOR();
3788 
3789  va_list ap;
3790  va_start(ap, Known);
3791  known_nominuses.insert(std::string(Known));
3792  for (unsigned i=1; i<Number; i++)
3793  {
3794  std::string tmp = std::string(va_arg(ap, char *));
3795  if (tmp.length() == 0)
3796  continue;
3797  known_nominuses.insert(tmp);
3798  }
3799  va_end(ap);
3800 
3801  return unidentified_nominuses(known_nominuses);
3802 }
3803 
3804 
3805 
3806 inline STRING_VECTOR
3808 {
3809  // -- every nominus is an argument.
3810  // -- the set of requested arguments contains the set of requested nominuss.
3811  // -- IF the set of requested arguments contains unrequested nominuss,
3812  // THEN they were requested as 'follow' and 'next' arguments and not as real nominuses.
3813  //
3814  // => it is not necessary to separate requested nominus from the list
3815 
3817 }
3818 
3819 
3820 
3821 inline STRING_VECTOR
3822 GetPot::unidentified_nominuses(const std::vector<std::string>& Knowns) const
3823 {
3824  // We use set for efficiency, but want to support vector inputs for
3825  // backwards compatibility.
3826  return unidentified_nominuses(std::set<std::string> (Knowns.begin(), Knowns.end()));
3827 }
3828 
3829 
3830 
3831 inline STRING_VECTOR
3832 GetPot::unidentified_nominuses(const std::set<std::string>& Knowns) const
3833 {
3834  STRING_VECTOR ufos;
3835 
3836  // (2) iterate over all arguments
3837  STRING_VECTOR::const_iterator it = argv.begin();
3838  ++it; // forget about argv[0] (application or filename)
3839  for (; it != argv.end(); ++it)
3840  {
3841  // -- check if nominus part of prefix
3842  const std::string arg = _get_remaining_string(*it, prefix);
3843  if (arg == "")
3844  continue;
3845 
3846  if (arg.length() < 1)
3847  continue;
3848 
3849  // option ? --> not a nomius
3850  if (arg[0] == '-')
3851  continue;
3852 
3853  // section ? --> not a real nominus
3854  if (arg[0] == '[' && arg[arg.length()-1] == ']')
3855  continue;
3856 
3857  // variable definition ? --> not a real nominus
3858  bool continue_f = false;
3859  for (unsigned i=0; i<arg.length() ; i++)
3860  if (arg[i] == '=')
3861  {
3862  continue_f = true;
3863  break;
3864  }
3865 
3866  if (continue_f)
3867  continue;
3868 
3869  // real nominuses are compared with the given list
3870  if (Knowns.find(arg) == Knowns.end())
3871  ufos.push_back(*it);
3872  }
3873  return ufos;
3874 }
3875 
3876 
3878 // (*) Accessors for requested types
3879 //.............................................................................
3880 
3881 inline
3882 std::set<std::string>
3884 {
3885  return _requested_arguments;
3886 }
3887 
3888 
3889 
3890 inline
3891 std::set<std::string>
3893 {
3894  return _requested_variables;
3895 }
3896 
3897 
3898 
3899 inline
3900 std::set<std::string>
3902 {
3903  return _requested_sections;
3904 }
3905 
3906 
3907 
3909 // (*) variable class
3910 //.............................................................................
3911 //
3912 inline
3914  : name(),
3915  value(),
3916  original()
3917 {}
3918 
3919 
3920 
3921 inline
3923 {
3924 #ifdef WIN32
3925  operator=(Other);
3926 #else
3928 #endif
3929 }
3930 
3931 
3932 
3933 inline
3934 GetPot::variable::variable(const char* Name, const char* Value, const char* FieldSeparator)
3935  : name(Name)
3936 {
3937  // make a copy of the 'Value'
3938  take(Value, FieldSeparator);
3939 }
3940 
3941 
3942 
3943 inline const std::string*
3945 {
3946  if (Idx >= value.size())
3947  return 0;
3948  else
3949  return &(value[Idx]);
3950 }
3951 
3952 
3953 
3954 inline void
3955 GetPot::variable::take(const char* Value, const char* FieldSeparator)
3956 {
3957  original = std::string(Value); // string member var
3958  value.clear(); // vector<string> member var
3959 
3960  /*
3961  // separate string by white space delimiters using 'strtok'
3962  // thread safe usage of strtok (no static members)
3963  char* spt = 0;
3964  // make a copy of the 'Value'
3965  char* copy = new char[strlen(Value)+1];
3966  strcpy(copy, Value);
3967  char* follow_token = strtok_r(copy, FieldSeparator, &spt);
3968  while (follow_token != 0)
3969  {
3970  value.push_back(std::string(follow_token));
3971  follow_token = strtok_r(NULL, FieldSeparator, &spt);
3972  }
3973 
3974  delete [] copy;
3975  */
3976 
3977  // Don't use strtok, instead tokenize the input char "Value" using std::string operations so
3978  // that the results end up in the local "value" member
3979 
3980  // Construct std::string objects from the input char*s. I think the only
3981  // FieldSeparator recognized by GetPot is whitespace?
3982  std::string Value_str = std::string(Value);
3983  std::string delimiters = std::string(FieldSeparator);
3984 
3985  // Skip delimiters at beginning.
3986  std::string::size_type lastPos = Value_str.find_first_not_of(delimiters, 0);
3987 
3988  // Find first "non-delimiter".
3989  std::string::size_type pos = Value_str.find_first_of(delimiters, lastPos);
3990 
3991  // Loop over the input string until all the tokens have been pushed back
3992  // into the local "value" member.
3993  while (std::string::npos != pos || std::string::npos != lastPos)
3994  {
3995  // Found a token, add it to the vector.
3996  value.push_back(Value_str.substr(lastPos, pos - lastPos));
3997 
3998  // Skip delimiters. Note the "not_of"
3999  lastPos = Value_str.find_first_not_of(delimiters, pos);
4000 
4001  // Find next "non-delimiter"
4002  pos = Value_str.find_first_of(delimiters, lastPos);
4003  }
4004 
4005  // We're done, all the tokens should now be in the vector<string>
4006 }
4007 
4008 inline
4010 {}
4011 
4012 
4013 
4014 inline GetPot::variable&
4016 {
4017  if (&Other != this)
4018  {
4019  name = Other.name;
4020  value = Other.value;
4021  original = Other.original;
4022  }
4023  return *this;
4024 }
4025 
4026 #ifdef GETPOT_NAMESPACE
4027 }
4028 #endif
4029 
4030 #undef victorate
4031 
4032 #endif // LIBMESH_GETPOT_H
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
bool search_failed() const
Definition: getpot.h:355
double abs(double a)
bool argument_contains(unsigned Idx, const char *FlagList) const
Definition: getpot.h:2122
STRING_VECTOR unidentified_variables() const
Definition: getpot.h:3701
static STRING_VECTOR _get_section_tree(const std::string &FullPath)
Definition: getpot.h:701
T get_value_no_default(const char *VarName, const T &Default) const
Definition: getpot.h:2368
const std::string _get_string(std::istream &istr)
Definition: getpot.h:1424
bool _search_string_vector(const STRING_VECTOR &Vec, const std::string &Str) const
Definition: getpot.h:3433
std::string _DBE_expand(const std::string &str)
Definition: getpot.h:2928
std::set< std::string > get_requested_variables() const
Definition: getpot.h:3892
bool have_section(const char *section_name) const
Definition: getpot.h:2257
STRING_VECTOR _read_in_stream(std::istream &istr)
Definition: getpot.h:1233
std::string section
Definition: getpot.h:509
STRING_VECTOR get_variable_names() const
Definition: getpot.h:2575
T _convert_to_type_no_default(const char *VarName, const std::string &String, const T &Default) const
Definition: getpot.h:1633
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(" \\"))
Definition: getpot.h:897
STRING_VECTOR unidentified_nominuses() const
Definition: getpot.h:3807
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)
Definition: getpot.h:1450
bool search(const char *option)
Definition: getpot.h:1765
const variable * _find_variable(const char *) const
Definition: getpot.h:2657
STRING_VECTOR unidentified_sections() const
Definition: getpot.h:3741
static std::string _convert_from_type(const T &Value)
Definition: getpot.h:690
const std::string _get_until_closing_square_bracket(std::istream &istr)
Definition: getpot.h:1483
bool operator()(const char *s1, const char *s2) const
Definition: getpot.h:548
STRING_VECTOR unidentified_arguments() const
Definition: getpot.h:3468
unsigned nominus_size() const
Definition: getpot.h:413
IterBase * end
variable & operator=(const variable &Other)
Definition: getpot.h:4015
int print(std::ostream &out_stream=std::cout) const
Definition: getpot.h:2688
const std::string * get_element(unsigned Idx) const
Definition: getpot.h:3944
void _parse_argument_vector(const STRING_VECTOR &ARGV)
Definition: getpot.h:1130
void set(const char *VarName, const T &Value, const bool Requested=true)
Definition: getpot.h:2521
T follow(const T &Default, const char *Option)
Definition: getpot.h:1948
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
Definition: getpot.h:1738
long double max(long double a, double b)
void disable_request_recording()
Definition: getpot.h:209
const std::string _get_next_token(std::istream &istr)
Definition: getpot.h:1367
std::vector< unsigned > idx_nominus
Definition: getpot.h:525
bool _check_flags(const std::string &Str, const char *FlagList) const
Definition: getpot.h:2157
STRING_VECTOR get_subsection_names(const std::string &section_name) const
Definition: getpot.h:2599
STRING_VECTOR _DBE_get_expr_list(const std::string &str, const unsigned ExpectedNumber)
Definition: getpot.h:2803
std::string prefix
Definition: getpot.h:508
std::vector< variable > variables
Definition: getpot.h:530
T operator()(const char *VarName, const T &Default) const
Definition: getpot.h:2286
GetPot & operator=(const GetPot &)
Definition: getpot.h:1030
const char * _match_starting_string(const char *StartString)
Definition: getpot.h:2059
T direct_follow(const T &Default, const char *Option)
Definition: getpot.h:2030
unsigned vector_variable_size(const char *VarName) const
Definition: getpot.h:2556
void absorb(const GetPot &Other)
Definition: getpot.h:1087
void _basic_initialization()
Definition: getpot.h:720
std::set< std::string > get_overridden_variables() const
Definition: getpot.h:2649
T _convert_to_type(const std::string &String, const T &Default) const
Definition: getpot.h:1568
const char * _internal_managed_copy(const std::string &Arg) const
Definition: getpot.h:1706
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(" \\"))
Definition: getpot.h:945
std::set< std::string > _requested_sections
Definition: getpot.h:581
void _skip_whitespace(std::istream &istr)
Definition: getpot.h:1305
STRING_VECTOR argv
Definition: getpot.h:515
double pow(double a, int b)
void enable_request_recording()
Definition: getpot.h:210
STRING_VECTOR nominus_vector() const
Definition: getpot.h:2172
std::set< std::string > get_requested_sections() const
Definition: getpot.h:3901
bool have_variable(const char *VarName) const
Definition: getpot.h:2238
const char * next_nominus()
Definition: getpot.h:2191
const GetPot::variable * _DBE_get_variable(const std::string &str)
Definition: getpot.h:2894
unsigned size() const
Definition: getpot.h:1905
void set_prefix(const char *Prefix)
Definition: getpot.h:354
STRING_VECTOR unidentified_options() const
Definition: getpot.h:3530
const variable * _request_variable(const char *) const
Definition: getpot.h:2673
std::string next_nominus_string()
Definition: getpot.h:2208
static PetscErrorCode Mat * A
void init_multiple_occurrence()
Definition: getpot.h:1863
static const bool value
Definition: xdr_io.C:109
void _set_variable(const std::string &VarName, const std::string &Value, const bool Requested)
Definition: getpot.h:2502
std::set< std::string > _requested_variables
Definition: getpot.h:580
std::string _process_section_label(const std::string &Section, STRING_VECTOR &section_stack)
Definition: getpot.h:1511
std::string _field_separator
Definition: getpot.h:541
void take(const char *Value, const char *FieldSeparator)
Definition: getpot.h:3955
T get(unsigned Idx, const T &Default) const
void parse_command_line(const int argc_, const char *const *argv_, const char *FieldSeparator=0x0)
Definition: getpot.h:804
bool options_contain(const char *FlagList) const
Definition: getpot.h:2103
std::string _comment_end
Definition: getpot.h:536
STRING_VECTOR section_list
Definition: getpot.h:510
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
const char * operator[](unsigned Idx) const
Definition: getpot.h:1876
std::set< std::string > get_requested_arguments() const
Definition: getpot.h:3883
T next(const T &Default)
Definition: getpot.h:1915
std::string _comment_start
Definition: getpot.h:535
STRING_VECTOR get_section_names() const
Definition: getpot.h:2591
long double min(long double a, double b)
std::string unidentified_flags(const char *Known, int ArgumentNumber) const
Definition: getpot.h:3584
std::set< std::string > overridden_vars
Definition: getpot.h:519
std::set< std::string > _requested_arguments
Definition: getpot.h:579
void _record_argument_request(const std::string &Arg) const
Definition: getpot.h:2456
void _record_variable_request(const std::string &Arg) const
Definition: getpot.h:2478
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
std::string _DBE_expand_string(const std::string &str)
Definition: getpot.h:2770
std::set< const char *, ltstr > _internal_string_container
Definition: getpot.h:567