libMesh
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(),
757 #if !defined(GETPOT_DISABLE_MUTEX)
758  _getpot_mtx(),
759 #endif
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(),
788 #if !defined(GETPOT_DISABLE_MUTEX)
789  _getpot_mtx(),
790 #endif
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(),
849 #if !defined(GETPOT_DISABLE_MUTEX)
850  _getpot_mtx(),
851 #endif
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(),
884 #if !defined(GETPOT_DISABLE_MUTEX)
885  _getpot_mtx(),
886 #endif
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(),
929 #if !defined(GETPOT_DISABLE_MUTEX)
930  _getpot_mtx(),
931 #endif
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),
984  overridden_vars(),
986  idx_nominus(Other.idx_nominus),
987  variables(Other.variables),
989  _comment_end(Other._comment_end),
991  // #if !defined(GETPOT_DISABLE_MUTEX)
992  // _getpot_mtx(Other._getpot_mtx),
993  // #endif
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  char* newcopy = new char[strlen(otherstr)+1];
1076  strncpy(newcopy, otherstr, strlen(otherstr)+1);
1077  this->_internal_string_container.insert(newcopy);
1078  }
1079 
1080  return *this;
1081 }
1082 
1083 
1084 
1085 inline void
1086 GetPot::absorb(const GetPot& Other)
1087 {
1088  if (&Other == this)
1089  return;
1090 
1091  // variables that are not influenced by absorption:
1092  // _comment_start
1093  // _comment_end
1094  // cursor
1095  // nominus_cursor
1096  // search_failed
1097  // idx_nominus
1098  // search_loop_f
1099  argv = Other.argv;
1100  variables = Other.variables;
1101 
1102  if (request_recording_f)
1103  {
1104  // Get a lock before touching anything mutable
1105  SCOPED_MUTEX;
1106 
1107  _requested_arguments.insert(Other._requested_arguments.begin(), Other._requested_arguments.end());
1108  _requested_variables.insert(Other._requested_variables.begin(), Other._requested_variables.end());
1109  _requested_sections.insert(Other._requested_sections.begin(), Other._requested_sections.end());
1110  }
1111 }
1112 
1113 
1114 
1115 inline void
1117 {
1118  // Get a lock before touching anything mutable
1119  SCOPED_MUTEX;
1120 
1121  _requested_arguments.clear();
1122  _requested_variables.clear();
1123  _requested_sections.clear();
1124 }
1125 
1126 
1127 
1128 inline void
1130 {
1131  if (ARGV.empty())
1132  return;
1133 
1134  // build internal databases:
1135  // 1) array with no-minus arguments (usually used as filenames)
1136  // 2) variable assignments:
1137  // 'variable name' '=' number | string
1138  STRING_VECTOR section_stack;
1139  STRING_VECTOR::const_iterator it = ARGV.begin();
1140 
1141 
1142  section = "";
1143 
1144  // -- do not parse the first argument, so that this parsing source
1145  // name is not interpreted a s a nominus or so. If we already
1146  // have parsed arguments, don't bother adding another parsing
1147  // source name
1148  if (argv.empty())
1149  argv.push_back(*it);
1150  ++it;
1151 
1152  // -- loop over remaining arguments
1153  for (; it != ARGV.end(); ++it)
1154  {
1155  std::string arg = *it;
1156 
1157  if (arg.length() == 0)
1158  continue;
1159 
1160  // -- [section] labels and [include file] directives
1161  if (arg.length() > 1 && arg[0] == '[' && arg[arg.length()-1] == ']')
1162  {
1163 
1164  // Is this an include file directive?
1165  std::size_t include_pos = arg.find("include ", 1);
1166  if (include_pos != std::string::npos)
1167  {
1168 
1169  const std::string includefile =
1170  _DBE_expand_string(arg.substr(9, arg.length()-9-include_pos));
1171 
1172  this->parse_input_file
1173  (includefile, _comment_start, _comment_end, _field_separator);
1174  }
1175 
1176  else
1177  {
1178  // (*) sections are considered 'requested arguments'
1179  if (request_recording_f)
1180  {
1181  // Get a lock before touching anything mutable
1182  SCOPED_MUTEX;
1183 
1184  _requested_arguments.insert(arg);
1185  }
1186 
1187  const std::string Name = _DBE_expand_string(arg.substr(1, arg.length()-2));
1188  section = _process_section_label(Name, section_stack);
1189  // new section --> append to list of sections
1190  if (find(section_list.begin(), section_list.end(), section) == section_list.end())
1191  if (section.length() != 0) section_list.push_back(section);
1192  argv.push_back(arg);
1193  }
1194  }
1195  else
1196  {
1197  arg = section + _DBE_expand_string(arg);
1198  argv.push_back(arg);
1199  }
1200 
1201  // -- separate array for nominus arguments
1202  if (arg[0] != '-')
1203  idx_nominus.push_back(getpot_cast_int<unsigned>(argv.size()-1));
1204 
1205  // -- variables: does arg contain a '=' operator ?
1206  const std::size_t equals_pos = arg.find_first_of('=');
1207  if (equals_pos != std::string::npos)
1208  {
1209  // (*) record for later ufo detection
1210  // arguments carrying variables are always treated as 'requested' arguments.
1211  // unrequested variables have to be detected with the ufo-variable
1212  // detection routine.
1213  if (request_recording_f)
1214  {
1215  // Get a lock before touching anything mutable
1216  SCOPED_MUTEX;
1217 
1218  _requested_arguments.insert(arg);
1219  }
1220 
1221  // => arg (from start to '=') = Name of variable
1222  // (from '=' to end) = value of variable
1223  _set_variable(arg.substr(0,equals_pos),
1224  arg.substr(equals_pos+1), false);
1225  }
1226  }
1227 }
1228 
1229 
1230 
1231 inline STRING_VECTOR
1232 GetPot::_read_in_stream(std::istream& istr)
1233 {
1234  STRING_VECTOR brute_tokens;
1235  while (istr)
1236  {
1237  _skip_whitespace(istr);
1238  const std::string Token = _get_next_token(istr);
1239  // Allow 'keyword =' to parse with an empty string as value.
1240  // Only break at EOF.
1241  // if (Token.length() == 0 || Token[0] == EOF) break;
1242  if (Token[0] == EOF)
1243  break;
1244  brute_tokens.push_back(Token);
1245  }
1246 
1247  // -- reduce expressions of token1'='token2 to a single
1248  // string 'token1=token2'
1249  // -- copy everything into 'argv'
1250  // -- arguments preceded by something like '[' name ']' (section)
1251  // produce a second copy of each argument with a prefix '[name]argument'
1252  unsigned i1 = 0;
1253  unsigned i2 = 1;
1254  unsigned i3 = 2;
1255 
1256  STRING_VECTOR arglist;
1257  while (i1 < brute_tokens.size())
1258  {
1259  // 1) concatenate 'abcdef' '=' 'efgasdef' to 'abcdef=efgasdef'
1260  // note: java.lang.String: substring(a,b) = from a to b-1
1261  // C++ string: substr(a,b) = from a to a + b
1262  std::string result;
1263  if (i2 < brute_tokens.size() && brute_tokens[i2] == "=")
1264  {
1265  if (i3 >= brute_tokens.size())
1266  result = brute_tokens[i1] + brute_tokens[i2];
1267  else
1268  result = brute_tokens[i1] + brute_tokens[i2] + brute_tokens[i3];
1269  i1 = i3+1; i2 = i3+2; i3 = i3+3;
1270  }
1271  else if (i2 < brute_tokens.size() &&
1272  brute_tokens[i2].length() > 0 &&
1273  brute_tokens[i2][0] == '=')
1274  {
1275  // This case should not be hit if '=' at the beginning of a word
1276  // is always separated into its own word
1277  result = brute_tokens[i1] + brute_tokens[i2];
1278  i1 = i3; i2 = i3+1; i3 = i3+2;
1279  }
1280  else if (i2 < brute_tokens.size() && brute_tokens[i1][brute_tokens[i1].size()-1] == '=')
1281  {
1282  result = brute_tokens[i1] + brute_tokens[i2];
1283  i1 = i3; i2 = i3+1; i3 = i3+2;
1284  }
1285  else
1286  {
1287  result = brute_tokens[i1];
1288  i1=i2; i2=i3; i3++;
1289  }
1290 
1291  // Now strip out any comment
1292  size_t comment_start_loc = result.find(_comment_start, 0);
1293  if (comment_start_loc != std::string::npos)
1294  result = result.substr(0, comment_start_loc);
1295 
1296  arglist.push_back(result);
1297  }
1298  return arglist;
1299 }
1300 
1301 
1302 
1303 inline void
1304 GetPot::_skip_whitespace(std::istream& istr)
1305 {
1306  // find next non-whitespace while deleting comments
1307  int tmp = istr.get();
1308  do {
1309  // -- search a non whitespace
1310  while (isspace(tmp))
1311  {
1312  tmp = istr.get();
1313  if (!istr)
1314  return;
1315  }
1316 
1317  // -- look if characters match the comment starter string
1318  for (unsigned i=0; i<_comment_start.length() ; i++)
1319  {
1320  if (tmp != _comment_start[i])
1321  {
1322  // -- one step more backwards, since 'tmp' already at non-whitespace
1323  istr.unget();
1324  return;
1325  }
1326 
1327  // RHS: Why is this here? It breaks on empty comments
1328  // tmp = istr.get();
1329  // if (!istr) { istr.unget(); return; }
1330  }
1331  // 'tmp' contains last character of _comment_starter
1332 
1333  // -- comment starter found -> search for comment ender
1334  unsigned match_no=0;
1335  while (true)
1336  {
1337  tmp = istr.get();
1338  if (!istr)
1339  {
1340  istr.unget();
1341  return;
1342  }
1343 
1344  if (tmp == _comment_end[match_no])
1345  {
1346  match_no++;
1347  if (match_no == _comment_end.length())
1348  {
1349  istr.unget();
1350  break; // shuffle more whitespace, end of comment found
1351  }
1352  }
1353  else
1354  match_no = 0;
1355  }
1356 
1357  tmp = istr.get();
1358 
1359  } while (istr);
1360  istr.unget();
1361 }
1362 
1363 
1364 
1365 inline const std::string
1366 GetPot::_get_next_token(std::istream& istr)
1367 {
1368  // get next concatenates string token. consider quotes that embrace
1369  // whitespaces
1370  std::string token;
1371  int tmp = 0;
1372  while (true)
1373  {
1374  int last_letter = tmp;
1375  tmp = istr.get();
1376 
1377  if (tmp == '=')
1378  {
1379  // Always break at '='.
1380  // This separates '=' at the beginning of a word into its own word.
1381  token += getpot_cast_int<char>(tmp);
1382  return token;
1383  }
1384 
1385  else if (tmp == EOF || ((tmp == ' ' || tmp == '\t' || tmp == '\n') && last_letter != '\\'))
1386  return token;
1387 
1388  else if (tmp == '\'' && last_letter != '\\')
1389  {
1390  // QUOTES: un-backslashed quotes => it's a string
1391  token += _get_string(istr);
1392  continue;
1393  }
1394 
1395  else if (tmp == '{' && last_letter == '$')
1396  {
1397  token += '{' + _get_until_closing_bracket(istr);
1398  continue;
1399  }
1400 
1401  else if (tmp == '[')
1402  {
1403  token += '[' + _get_until_closing_square_bracket(istr);
1404  continue;
1405  }
1406 
1407  else if (tmp == '$' && last_letter == '\\')
1408  {
1409  token += getpot_cast_int<char>(tmp); tmp = 0; // so that last_letter will become = 0, not '$';
1410  continue;
1411  }
1412 
1413  else if (tmp == '\\' && last_letter != '\\')
1414  continue; // don't append un-backslashed backslashes
1415 
1416  token += getpot_cast_int<char>(tmp);
1417  }
1418 }
1419 
1420 
1421 
1422 inline const std::string
1423 GetPot::_get_string(std::istream& istr)
1424 {
1425  // parse input until next matching '
1426  std::string str;
1427  int tmp = 0;
1428  while (true)
1429  {
1430  int last_letter = tmp;
1431  tmp = istr.get();
1432  if (tmp == EOF)
1433  return str;
1434 
1435  // un-backslashed quotes => it's the end of the string
1436  else if (tmp == '\'' && last_letter != '\\')
1437  return str;
1438 
1439  else if (tmp == '\\' && last_letter != '\\')
1440  continue; // don't append
1441 
1442  str += getpot_cast_int<char>(tmp);
1443  }
1444 }
1445 
1446 
1447 
1448 inline const std::string
1450 {
1451  // parse input until next matching }
1452  std::string str = "";
1453  int tmp = 0;
1454  int brackets = 1;
1455  while (true)
1456  {
1457  int last_letter = tmp;
1458  tmp = istr.get();
1459  if (tmp == EOF)
1460  return str;
1461 
1462  else if (tmp == '{' && last_letter == '$')
1463  brackets += 1;
1464 
1465  else if (tmp == '}')
1466  {
1467  brackets -= 1;
1468  // un-backslashed brackets => it's the end of the string
1469  if (brackets == 0)
1470  return str + '}';
1471 
1472  else if (tmp == '\\' && last_letter != '\\')
1473  continue; // do not append an unbackslashed backslash
1474  }
1475  str += getpot_cast_int<char>(tmp);
1476  }
1477 }
1478 
1479 
1480 
1481 inline const std::string
1483 {
1484  // parse input until next matching ]
1485  std::string str = "";
1486  int brackets = 1;
1487  while (true)
1488  {
1489  int tmp = istr.get();
1490  if (tmp == EOF)
1491  return str;
1492 
1493  else if (tmp == '[')
1494  brackets += 1;
1495 
1496  else if (tmp == ']')
1497  {
1498  brackets -= 1;
1499  if (brackets == 0)
1500  return str + ']';
1501  }
1502 
1503  str += getpot_cast_int<char>(tmp);
1504  }
1505 }
1506 
1507 
1508 
1509 inline std::string
1510 GetPot::_process_section_label(const std::string& Section,
1511  STRING_VECTOR& section_stack)
1512 {
1513  std::string sname = Section;
1514  // 1) subsection of actual section ('./' prefix)
1515  if (sname.length() >= 2 && sname.substr(0, 2) == "./")
1516  sname = sname.substr(2);
1517 
1518  // 2) subsection of parent section ('../' prefix)
1519  else if (sname.length() >= 3 && sname.substr(0, 3) == "../")
1520  {
1521  do
1522  {
1523  if (section_stack.end() != section_stack.begin())
1524  section_stack.pop_back();
1525  sname = sname.substr(3);
1526  } while (sname.substr(0, 3) == "../");
1527  }
1528 
1529  // 3) subsection of the root-section
1530  else
1531  // [] => back to root section
1532  section_stack.erase(section_stack.begin(), section_stack.end());
1533 
1534  if (sname != "")
1535  {
1536  // parse section name for 'slashes'
1537  unsigned i=0;
1538  while (i < sname.length())
1539  {
1540  if (sname[i] == '/')
1541  {
1542  section_stack.push_back(sname.substr(0,i));
1543  if (i+1 < sname.length())
1544  sname = sname.substr(i+1);
1545  i = 0;
1546  }
1547  else
1548  i++;
1549  }
1550  section_stack.push_back(sname);
1551  }
1552 
1553  std::string section_label = "";
1554  if (!section_stack.empty())
1555  {
1556  victorate(std::string, section_stack, it)
1557  section_label += *it + "/";
1558  }
1559  return section_label;
1560 }
1561 
1562 
1563 
1564 // Use C++ istream/ostream to handle most type conversions.
1565 template <typename T>
1566 inline T
1567 GetPot::_convert_to_type(const std::string& String, const T& Default) const
1568 {
1569  std::istringstream in_string(String);
1570  T retval;
1571  in_string >> retval;
1572  if (in_string.fail())
1573  retval = Default;
1574  return retval;
1575 }
1576 
1577 
1578 
1579 // copy string - operator>> would have stopped upon seeing whitespace!
1580 template <>
1581 inline std::string
1582 GetPot::_convert_to_type(const std::string& String, const std::string&) const
1583 {
1584  return String;
1585 }
1586 
1587 
1588 
1589 // copy string
1590 inline std::string
1591 GetPot::_convert_to_type(const std::string& String, const char*) const
1592 {
1593  return String;
1594 }
1595 
1596 
1597 
1598 // be more liberal than std C++ in what we interpret as a boolean
1599 template<>
1600 inline bool
1601 GetPot::_convert_to_type<bool>(const std::string& String, const bool & Default) const
1602 {
1603  std::string newstring(String);
1604  //std::transform(newstring.begin(), newstring.end(), newstring.begin(), std::toupper);
1605  for (unsigned int i=0; i<newstring.length(); ++i)
1606  newstring[i] = getpot_cast_int<char>(toupper(newstring[i]));
1607 
1608  // "true"/"True"/"TRUE" should work
1609  if (newstring.find("TRUE")!=std::string::npos)
1610  return true;
1611 
1612  if (newstring.find("FALSE")!=std::string::npos)
1613  return false;
1614 
1615  // And if we don't find that, let's search for an integer and use C unsigned
1616  // int->bool conversion before giving up; i.e. a user could specify "0" for
1617  // false or "1" for true
1618  std::istringstream in_string(String);
1619  unsigned int retval;
1620  in_string >> retval;
1621  if (in_string.fail())
1622  return Default;
1623 
1624  return retval;
1625 }
1626 
1627 
1628 
1629 // Use C++ istream/ostream to handle most type conversions.
1630 template <typename T>
1631 inline T
1632 GetPot::_convert_to_type_no_default(const char* VarName, const std::string& String, const T&) const
1633 {
1634  std::istringstream in_string(String);
1635  T retval;
1636  in_string >> retval;
1637  if (in_string.fail())
1638  {
1639  getpot_cerr <<"ERROR: Input value for variable "<<VarName<<" is of the wrong type."<<std::endl;
1640  getpot_cerr <<" value = "<<String<<" expected type = "<<typeid(T).name()<<std::endl;
1641  getpot_error();
1642  }
1643  return retval;
1644 }
1645 
1646 
1647 
1648 // copy string - operator>> would have stopped upon seeing whitespace!
1649 template <>
1650 inline std::string
1651 GetPot::_convert_to_type_no_default(const char*, const std::string& String, const std::string&) const
1652 {
1653  return String;
1654 }
1655 
1656 
1657 
1658 // copy string
1659 inline std::string
1660 GetPot::_convert_to_type_no_default(const char*, const std::string& String, const char*) const
1661 {
1662  return String;
1663 }
1664 
1665 
1666 
1667 // be more liberal than std C++ in what we interpret as a boolean
1668 template<>
1669 inline bool
1670 GetPot::_convert_to_type_no_default<bool>(const char* VarName, const std::string& String, const bool &) const
1671 {
1672  std::string newstring(String);
1673  //std::transform(newstring.begin(), newstring.end(), newstring.begin(), std::toupper);
1674  for (unsigned int i=0; i<newstring.length(); ++i)
1675  {
1676  newstring[i]=getpot_cast_int<char>(toupper(newstring[i]));
1677  }
1678 
1679  // "true"/"True"/"TRUE" should work
1680  if (newstring.find("TRUE")!=std::string::npos)
1681  return true;
1682 
1683  if (newstring.find("FALSE")!=std::string::npos)
1684  return false;
1685 
1686  // And if we don't find that, let's search for an integer and use C unsigned
1687  // int->bool conversion before giving up; i.e. a user could specify "0" for
1688  // false or "1" for true
1689  std::istringstream in_string(String);
1690  unsigned int retval;
1691  in_string >> retval;
1692  if (in_string.fail())
1693  {
1694  getpot_cerr <<"ERROR: Input value for variable "<<VarName<<" is of the wrong type."<<std::endl;
1695  getpot_cerr <<" value = "<<String<<" expected type = "<<typeid(bool).name()<<std::endl;
1696  getpot_error();
1697  }
1698 
1699  return retval;
1700 }
1701 
1702 
1703 
1704 inline const char*
1705 GetPot::_internal_managed_copy(const std::string& Arg) const
1706 {
1707  const char* arg = Arg.c_str();
1708 
1709  // Get a lock before touching anything mutable
1710  SCOPED_MUTEX;
1711 
1712  // See if there's already an identical string saved
1713  std::set<const char*,ltstr>::const_iterator it =
1714  _internal_string_container.find(arg);
1715 
1716  // If so, return it
1717  if (it != _internal_string_container.end())
1718  return *it;
1719 
1720  // Otherwise, create a new one
1721  char* newcopy = new char[strlen(arg)+1];
1722  strncpy(newcopy, arg, strlen(arg)+1);
1723  _internal_string_container.insert(newcopy);
1724  return newcopy;
1725 }
1726 
1727 
1728 
1730 // (*) cursor oriented functions
1731 //.............................................................................
1732 
1733 // Checks if 'String' begins with 'Start' and returns the remaining String.
1734 // Returns None if String does not begin with Start.
1735 inline const std::string
1736 GetPot::_get_remaining_string(const std::string& String, const std::string& Start) const
1737 {
1738  if (Start == "")
1739  return String;
1740 
1741  // note: java.lang.String: substring(a,b) = from a to b-1
1742  // C++ string: substr(a,b) = from a to a + b
1743  if (String.find(Start) == 0)
1744  return String.substr(Start.length());
1745 
1746  else
1747  return "";
1748 }
1749 
1750 
1751 
1752 // -- search for a certain argument and set cursor to position
1753 inline bool
1754 GetPot::search(const std::string &Option)
1755 {
1756  return search(Option.c_str());
1757 }
1758 
1759 
1760 
1761 // -- search for a certain argument and set cursor to position
1762 inline bool
1763 GetPot::search(const char* Option)
1764 {
1765  unsigned OldCursor = cursor;
1766  const std::string SearchTerm = prefix + Option;
1767 
1768  // (*) record requested arguments for later ufo detection
1769  _record_argument_request(SearchTerm);
1770 
1771  if (OldCursor >= argv.size())
1772  OldCursor = getpot_cast_int<unsigned>(argv.size() - 1);
1773  search_failed_f = true;
1774 
1775  // (*) first loop from cursor position until end
1776  for (unsigned c = cursor; c < argv.size(); c++)
1777  {
1778  if (argv[c] == SearchTerm)
1779  {
1780  cursor = c;
1781  search_failed_f = false;
1782  return true;
1783  }
1784  }
1785  if (!search_loop_f)
1786  return false;
1787 
1788  // (*) second loop from 0 to old cursor position
1789  for (unsigned c = 1; c <= OldCursor; c++)
1790  {
1791  if (argv[c] == SearchTerm)
1792  {
1793  cursor = c;
1794  search_failed_f = false;
1795  return true;
1796  }
1797  }
1798 
1799  // in case nothing is found the cursor stays where it was
1800  return false;
1801 }
1802 
1803 
1804 
1805 inline bool
1806 GetPot::search(unsigned No, const char* P, ...)
1807 {
1808  // (*) recording the requested arguments happens in subroutine 'search'
1809  if (No == 0)
1810  return false;
1811 
1812  // search for the first argument
1813  if (search(P) == true)
1814  return true;
1815 
1816  // start interpreting variable argument list
1817  va_list ap;
1818  va_start(ap, P);
1819  unsigned i = 1;
1820  for (; i < No; i++)
1821  {
1822  char* Opt = va_arg(ap, char *);
1823  // (*) search records itself for later ufo detection
1824  if (search(Opt) == true)
1825  break;
1826  }
1827 
1828  if (i < No)
1829  {
1830  i++;
1831  // loop was left before end of array --> hit but
1832  // make sure that the rest of the search terms is marked
1833  // as requested.
1834  for (; i < No; i++)
1835  {
1836  char* Opt = va_arg(ap, char *);
1837  // (*) record requested arguments for later ufo detection
1839  }
1840  va_end(ap);
1841  return true;
1842  }
1843 
1844  va_end(ap);
1845  // loop was left normally --> no hit
1846  return false;
1847 }
1848 
1849 
1850 
1851 inline void
1853 {
1854  search_failed_f = false;
1855  cursor = 0;
1856 }
1857 
1858 
1859 
1860 inline void
1862 {
1863  disable_loop();
1864  reset_cursor();
1865 }
1866 
1867 
1868 
1870 // (*) direct access to command line arguments
1871 //.............................................................................
1872 //
1873 inline const char*
1874 GetPot::operator[](unsigned idx) const
1875 {
1876  return idx<argv.size() ? argv[idx].c_str() : 0;
1877 }
1878 
1879 
1880 
1881 template <typename T>
1882 inline T
1883 GetPot::get(unsigned int Idx, const T& Default) const
1884 {
1885  if (Idx >= argv.size())
1886  return Default;
1887  return _convert_to_type(argv[Idx], Default);
1888 }
1889 
1890 
1891 
1892 inline const char*
1893 GetPot::get(unsigned int Idx, const char* Default) const
1894 {
1895  if (Idx >= argv.size())
1896  return Default;
1897  return argv[Idx].c_str();
1898 }
1899 
1900 
1901 
1902 inline unsigned
1904 {
1905  return getpot_cast_int<unsigned>(argv.size());
1906 }
1907 
1908 
1909 
1910 // -- next() function group
1911 template <typename T>
1912 inline T
1913 GetPot::next(const T& Default)
1914 {
1915  if (search_failed_f)
1916  return Default;
1917  cursor++;
1918  if (cursor >= argv.size())
1919  {
1920  cursor = getpot_cast_int<unsigned>(argv.size());
1921  return Default;
1922  }
1923 
1924  // (*) record requested argument for later ufo detection
1926 
1927  const std::string Remain = _get_remaining_string(argv[cursor], prefix);
1928 
1929  return Remain != "" ? _convert_to_type(Remain, Default) : Default;
1930 }
1931 
1932 
1933 
1934 inline const char*
1935 GetPot::next(const char* Default)
1936 {
1937  return _internal_managed_copy(next(std::string(Default)));
1938 }
1939 
1940 
1941 
1942 // -- follow() function group
1943 // distinct option to be searched for
1944 template <typename T>
1945 inline T
1946 GetPot::follow(const T& Default, const char* Option)
1947 {
1948  // (*) record requested of argument is entirely handled in 'search()' and 'next()'
1949  if (search(Option) == false)
1950  return Default;
1951 
1952  return next(Default);
1953 }
1954 
1955 
1956 
1957 inline const char*
1958 GetPot::follow(const char* Default, const char* Option)
1959 {
1960  return _internal_managed_copy(follow(std::string(Default), Option));
1961 }
1962 
1963 
1964 
1965 // -- second follow() function group
1966 // multiple option to be searched for
1967 template <typename T>
1968 inline T
1969 GetPot::follow(const T& Default, unsigned int No, const char* P, ...)
1970 {
1971  // (*) record requested of argument is entirely handled in 'search()' and 'next()'
1972  if (No == 0)
1973  return Default;
1974 
1975  if (search(P) == true)
1976  return next(Default);
1977 
1978  va_list ap;
1979  va_start(ap, P);
1980  for (unsigned i=1; i<No; i++)
1981  {
1982  char* Opt = va_arg(ap, char *);
1983  if (search(Opt) == true)
1984  {
1985  va_end(ap);
1986  return next(Default);
1987  }
1988  }
1989  va_end(ap);
1990  return Default;
1991 }
1992 
1993 
1994 
1995 inline const char*
1996 GetPot::follow(const char* Default, unsigned No, const char* P, ...)
1997 {
1998  // (*) record requested of argument is entirely handled in 'search()' and 'next()'
1999  if (No == 0)
2000  return Default;
2001 
2002  if (search(P) == true)
2003  return next(Default);
2004 
2005  va_list ap;
2006  va_start(ap, P);
2007  for (unsigned i=1; i<No; i++)
2008  {
2009  char* Opt = va_arg(ap, char *);
2010  if (search(Opt) == true)
2011  {
2012  va_end(ap);
2013  return next(Default);
2014  }
2015  }
2016  va_end(ap);
2017  return Default;
2018 }
2019 
2020 
2021 
2023 // (*) directly connected options
2024 //.............................................................................
2025 //
2026 template <typename T>
2027 inline T
2028 GetPot::direct_follow(const T& Default, const char* Option)
2029 {
2030  const char* FollowStr = _match_starting_string(Option);
2031 
2032  // (*) record requested of argument for later ufo-detection
2033  _record_argument_request(std::string(Option) + FollowStr);
2034 
2035  if (FollowStr == 0)
2036  return Default;
2037 
2038  if (++cursor >= argv.size())
2039  cursor = getpot_cast_int<unsigned>(argv.size());
2040  return _convert_to_type(FollowStr, Default);
2041 }
2042 
2043 
2044 
2045 inline const char*
2046 GetPot::direct_follow(const char* Default, const char* Option)
2047 {
2048  return _internal_managed_copy(direct_follow(std::string(Default), Option));
2049 }
2050 
2051 
2052 
2053 // pointer to the place where the string after
2054 // the match inside the found argument starts.
2055 // 0 no argument matches the starting string.
2056 inline const char*
2057 GetPot::_match_starting_string(const char* StartString)
2058 {
2059  const unsigned N =
2060  getpot_cast_int<unsigned>(strlen(StartString));
2061  unsigned OldCursor = cursor;
2062 
2063  if (OldCursor >= argv.size())
2064  OldCursor = getpot_cast_int<unsigned>(argv.size() - 1);
2065  search_failed_f = true;
2066 
2067  // (*) first loop from cursor position until end
2068  for (unsigned c = cursor; c < argv.size(); c++)
2069  {
2070  if (strncmp(StartString, argv[c].c_str(), N) == 0)
2071  {
2072  cursor = c;
2073  search_failed_f = false;
2074  return &(argv[c].c_str()[N]);
2075  }
2076  }
2077 
2078  if (!search_loop_f)
2079  return NULL;
2080 
2081  // (*) second loop from 0 to old cursor position
2082  for (unsigned c = 1; c < OldCursor; c++)
2083  {
2084  if (strncmp(StartString, argv[c].c_str(), N) == 0)
2085  {
2086  cursor = c;
2087  search_failed_f = false;
2088  return &(argv[c].c_str()[N]);
2089  }
2090  }
2091  return 0;
2092 }
2093 
2094 
2095 
2097 // (*) search for flags
2098 //.............................................................................
2099 //
2100 inline bool
2101 GetPot::options_contain(const char* FlagList) const
2102 {
2103  // go through all arguments that start with a '-' (but not '--')
2104  std::string str;
2105  STRING_VECTOR::const_iterator it = argv.begin();
2106  for (; it != argv.end(); ++it)
2107  {
2108  str = _get_remaining_string(*it, prefix);
2109 
2110  if (str.length() >= 2 && str[0] == '-' && str[1] != '-')
2111  if (_check_flags(str, FlagList))
2112  return true;
2113  }
2114  return false;
2115 }
2116 
2117 
2118 
2119 inline bool
2120 GetPot::argument_contains(unsigned Idx, const char* FlagList) const
2121 {
2122  if (Idx >= argv.size())
2123  return false;
2124 
2125  // (*) record requested of argument for later ufo-detection
2126  // an argument that is checked for flags is considered to be 'requested'
2128 
2129  if (prefix == "")
2130  // search argument for any flag in flag list
2131  return _check_flags(argv[Idx], FlagList);
2132 
2133  // if a prefix is set, then the argument index is the index
2134  // inside the 'namespace'
2135  // => only check list of arguments that start with prefix
2136  unsigned no_matches = 0;
2137  for (unsigned i=0; i<argv.size(); i++)
2138  {
2139  const std::string Remain = _get_remaining_string(argv[i], prefix);
2140  if (Remain != "")
2141  {
2142  no_matches += 1;
2143  if (no_matches == Idx)
2144  return _check_flags(Remain, FlagList);
2145  }
2146  }
2147 
2148  // no argument in this namespace
2149  return false;
2150 }
2151 
2152 
2153 
2154 inline bool
2155 GetPot::_check_flags(const std::string& Str, const char* FlagList) const
2156 {
2157  for (const char* p=FlagList; *p != '\0' ; p++)
2158  if (Str.find(*p) != std::string::npos)
2159  return true; // found something
2160  return false;
2161 }
2162 
2163 
2164 
2166 // (*) nominus arguments
2167 
2168 // return vector of nominus arguments
2169 inline STRING_VECTOR
2171 {
2172  STRING_VECTOR nv;
2173  std::vector<unsigned>::const_iterator it = idx_nominus.begin();
2174  for (; it != idx_nominus.end(); ++it)
2175  {
2176  nv.push_back(argv[*it]);
2177 
2178  // (*) record for later ufo-detection
2179  // when a nominus vector is requested, the entire set of nominus arguments are
2180  // tagged as 'requested'
2182  }
2183  return nv;
2184 }
2185 
2186 
2187 
2188 inline const char*
2190 {
2191  if (nominus_cursor < int(idx_nominus.size()) - 1)
2192  {
2193  const std::string Tmp = argv[idx_nominus[++nominus_cursor]];
2194 
2195  // (*) record for later ufo-detection
2197 
2198  return _internal_managed_copy(Tmp);
2199  }
2200 
2201  return 0;
2202 }
2203 
2204 
2205 inline std::string
2207 {
2208  if (nominus_cursor < int(idx_nominus.size()) - 1)
2209  {
2210  const std::string Tmp = argv[idx_nominus[++nominus_cursor]];
2211 
2212  // (*) record for later ufo-detection
2214 
2215  return Tmp;
2216  }
2217 
2218  return "";
2219 }
2220 
2221 
2222 
2223 inline void
2225 {
2226  nominus_cursor = -1;
2227 }
2228 
2229 
2230 
2232 // (*) variables
2233 //.............................................................................
2234 //
2235 inline bool
2236 GetPot::have_variable(const char* VarName) const
2237 {
2238  const variable* sv = _request_variable(VarName);
2239 
2240  if (sv == 0)
2241  return false;
2242 
2243  return true;
2244 }
2245 
2246 
2247 
2248 inline bool
2249 GetPot::have_variable(const std::string& VarName) const
2250 {
2251  return have_variable(VarName.c_str());
2252 }
2253 
2254 inline bool
2255 GetPot::have_section(const char* section_name) const
2256 {
2257  std::string s = std::string(section_name);
2258  return this->have_section(s);
2259 }
2260 
2261 inline bool
2262 GetPot::have_section(const std::string& section_name) const
2263 {
2264  const char slash('/');
2265 
2266  std::string::const_reverse_iterator it = section_name.rbegin();
2267 
2268  bool found_section = false;
2269 
2270  // Check if section_name ends with a "/". If not, append it for the search since
2271  // the section names are stored with a "/" at the end.
2272  if( (*it) != slash )
2273  // We need to use a linear search because we can't sort section_list
2274  // without violating some assumptions. See libMesh #481 for more discussion.
2275  found_section = ( std::find(section_list.begin(), section_list.end(), section_name+slash) != section_list.end() );
2276  else
2277  found_section = ( std::find(section_list.begin(), section_list.end(), section_name) != section_list.end() );
2278 
2279  return found_section;
2280 }
2281 
2282 template <typename T>
2283 inline T
2284 GetPot::operator()(const char* VarName, const T& Default) const
2285 {
2286  // (*) recording of requested variables happens in '_request_variable()'
2287  const variable* sv = _request_variable(VarName);
2288 
2289  if (sv == 0)
2290  return Default;
2291 
2292  return _convert_to_type(sv->original, Default);
2293 }
2294 
2295 
2296 
2297 template <typename T>
2298 inline T
2299 GetPot::operator()(const std::string& VarName, const T& Default) const
2300 {
2301  return operator()(VarName.c_str(), Default);
2302 }
2303 
2304 
2305 
2306 inline const char*
2307 GetPot::operator()(const char* VarName, const char* Default) const
2308 {
2309  return _internal_managed_copy(operator()(VarName, std::string(Default)));
2310 }
2311 
2312 
2313 
2314 inline const char*
2315 GetPot::operator()(const std::string& VarName, const char* Default) const
2316 {
2317  return operator()(VarName.c_str(), Default);
2318 }
2319 
2320 
2321 
2322 template <typename T>
2323 inline T
2324 GetPot::operator()(const char* VarName, const T& Default, unsigned int Idx) const
2325 {
2326  // (*) recording of requested variables happens in '_request_variable()'
2327  const variable* sv = _request_variable(VarName);
2328  if (sv == 0)
2329  return Default;
2330 
2331  const std::string* element = sv->get_element(Idx);
2332  if (element == 0)
2333  return Default;
2334  return _convert_to_type(*element, Default);
2335 }
2336 
2337 
2338 
2339 template <typename T>
2340 inline T
2341 GetPot::operator()(const std::string& VarName, const T& Default, unsigned int Idx) const
2342 {
2343  return operator()(VarName.c_str(), Default, Idx);
2344 }
2345 
2346 
2347 
2348 inline const char*
2349 GetPot::operator()(const char* VarName, const char* Default, unsigned int Idx) const
2350 {
2351  return _internal_managed_copy(operator()(VarName, std::string(Default), Idx));
2352 }
2353 
2354 
2355 
2356 inline const char*
2357 GetPot::operator()(const std::string& VarName, const char* Default, unsigned int Idx) const
2358 {
2359  return operator()(VarName.c_str(), Default, Idx);
2360 }
2361 
2362 
2363 
2364 template <typename T>
2365 inline T
2366 GetPot::get_value_no_default(const char* VarName, const T& Default) const
2367 {
2368  // (*) recording of requested variables happens in '_request_variable()'
2369  const variable* sv = _request_variable(VarName);
2370  if (sv == 0)
2371  {
2372  getpot_cerr << "ERROR: cannot find variable "<<VarName<<std::endl;
2373  getpot_error();
2374  }
2375  return _convert_to_type_no_default(VarName, sv->original, Default);
2376 }
2377 
2378 
2379 
2380 template <typename T>
2381 inline T
2382 GetPot::get_value_no_default(const std::string& VarName, const T& Default) const
2383 {
2384  return get_value_no_default(VarName.c_str(),Default);
2385 }
2386 
2387 
2388 
2389 inline const char*
2390 GetPot::get_value_no_default(const char* VarName, const char* Default) const
2391 {
2392  return _internal_managed_copy(get_value_no_default(VarName, std::string(Default)));
2393 }
2394 
2395 
2396 
2397 inline const char*
2398 GetPot::get_value_no_default(const std::string& VarName, const char* Default) const
2399 {
2400  return get_value_no_default(VarName.c_str(),Default);
2401 }
2402 
2403 
2404 
2405 template <typename T>
2406 inline T
2407 GetPot::get_value_no_default(const char* VarName, const T& Default, unsigned int Idx) const
2408 {
2409  // (*) recording of requested variables happens in '_request_variable()'
2410  const variable* sv = _request_variable(VarName);
2411  if (sv == 0)
2412  {
2413  getpot_cerr << "ERROR: cannot find variable "<<VarName<<std::endl;
2414  getpot_error();
2415  }
2416 
2417  const std::string* element = sv->get_element(Idx);
2418  if (element == 0)
2419  {
2420  getpot_cerr << "ERROR: cannot find index "<<Idx<<" of variable "<<VarName<<std::endl;
2421  getpot_error();
2422  }
2423  return _convert_to_type_no_default(VarName, *element, Default);
2424 }
2425 
2426 
2427 
2428 template <typename T>
2429 inline T
2430 GetPot::get_value_no_default(const std::string& VarName, const T& Default, unsigned int Idx) const
2431 {
2432  return get_value_no_default(VarName.c_str(), Default, Idx);
2433 }
2434 
2435 
2436 
2437 inline const char*
2438 GetPot::get_value_no_default(const char* VarName, const char* Default, unsigned int Idx) const
2439 {
2440  return _internal_managed_copy(get_value_no_default(VarName, std::string(Default), Idx));
2441 }
2442 
2443 
2444 
2445 inline const char*
2446 GetPot::get_value_no_default(const std::string& VarName, const char* Default, unsigned int Idx) const
2447 {
2448  return get_value_no_default(VarName.c_str(), Default, Idx);
2449 }
2450 
2451 
2452 
2453 inline void
2454 GetPot::_record_argument_request(const std::string& Name) const
2455 {
2456  if (!request_recording_f)
2457  return;
2458 
2459  // Get a lock before touching anything mutable
2460  SCOPED_MUTEX;
2461 
2462  // (*) record requested variable for later ufo detection
2463  _requested_arguments.insert(Name);
2464 
2465  // (*) record considered section for ufo detection
2466  STRING_VECTOR STree = _get_section_tree(Name);
2467  victorate(std::string, STree, it)
2468  if (_requested_sections.find(*it) == _requested_sections.end())
2469  if (section.length() != 0)
2470  _requested_sections.insert(*it);
2471 }
2472 
2473 
2474 
2475 inline void
2476 GetPot::_record_variable_request(const std::string& Name) const
2477 {
2478  if (!request_recording_f)
2479  return;
2480 
2481  // Get a lock before touching anything mutable
2482  SCOPED_MUTEX;
2483 
2484  // (*) record requested variable for later ufo detection
2485  _requested_variables.insert(Name);
2486 
2487  // (*) record considered section for ufo detection
2488  STRING_VECTOR STree = _get_section_tree(Name);
2489  victorate(std::string, STree, it)
2490  if (_requested_sections.find(*it) == _requested_sections.end())
2491  if (section.length() != 0)
2492  _requested_sections.insert(*it);
2493 }
2494 
2495 
2496 
2497 // (*) following functions are to be used from 'outside', after getpot has parsed its
2498 // arguments => append an argument in the argument vector that reflects the addition
2499 inline void
2500 GetPot::_set_variable(const std::string& VarName,
2501  const std::string& Value, const bool Requested /* = true */)
2502 {
2503  const GetPot::variable* Var = Requested ?
2504  _request_variable(VarName.c_str()) :
2505  _find_variable(VarName.c_str());
2506  if (Var == 0)
2507  variables.push_back(variable(VarName.c_str(), Value.c_str(), _field_separator.c_str()));
2508  else
2509  {
2510  overridden_vars.insert(VarName.c_str());
2511  (const_cast<GetPot::variable*>(Var))->take(Value.c_str(), _field_separator.c_str());
2512  }
2513 }
2514 
2515 
2516 
2517 template <typename T>
2518 inline void
2519 GetPot::set(const char* VarName, const T& Value, const bool Requested /* = true */)
2520 {
2521  std::ostringstream string_value;
2522  string_value << Value;
2523  _set_variable(VarName, string_value.str().c_str(), Requested);
2524 }
2525 
2526 
2527 
2528 template <typename T>
2529 inline void
2530 GetPot::set(const std::string& VarName, const T& Value, const bool Requested /* = true */)
2531 {
2532  set(VarName.c_str(), Value, Requested);
2533 }
2534 
2535 
2536 
2537 inline void
2538 GetPot::set(const char* VarName, const char* Value, const bool Requested /* = true */)
2539 {
2540  _set_variable(VarName, Value, Requested);
2541 }
2542 
2543 
2544 
2545 inline void
2546 GetPot::set(const std::string& VarName, const char* Value, const bool Requested /* = true */)
2547 {
2548  set(VarName.c_str(), Value, Requested);
2549 }
2550 
2551 
2552 
2553 inline unsigned
2554 GetPot::vector_variable_size(const char* VarName) const
2555 {
2556  const variable* sv = _request_variable(VarName);
2557  if (sv == 0)
2558  return 0;
2559  return (unsigned)(sv->value.size());
2560 }
2561 
2562 
2563 
2564 inline unsigned
2565 GetPot::vector_variable_size(const std::string& VarName) const
2566 {
2567  return vector_variable_size(VarName.c_str());
2568 }
2569 
2570 
2571 
2572 inline STRING_VECTOR
2574 {
2575  STRING_VECTOR result;
2576  std::vector<GetPot::variable>::const_iterator it = variables.begin();
2577  for (; it != variables.end(); ++it)
2578  {
2579  const std::string Tmp = _get_remaining_string((*it).name, prefix);
2580  if (Tmp != "")
2581  result.push_back(Tmp);
2582  }
2583  return result;
2584 }
2585 
2586 
2587 
2588 inline STRING_VECTOR
2590 {
2591  return section_list;
2592 }
2593 
2594 
2595 
2596 inline STRING_VECTOR
2597 GetPot::get_subsection_names(const std::string & prefix) const
2598 {
2599  // GetPot functions should understand user-provided section names
2600  // either with or without a trailing slash.
2601  const std::string full_prefix =
2602  *prefix.rbegin() == '/' ? prefix : prefix + '/';
2603 
2604  const std::size_t full_prefix_len = full_prefix.size();
2605 
2606  // Subsections-of-subsections are in the section_list, so we'll be
2607  // adding subsections multiple times. Using std::set as an
2608  // intermediate data structure helps us check for duplicates with
2609  // O(N log N) rather than O(N^2) cost.
2610  std::set<std::string> subsections;
2611 
2612  STRING_VECTOR returnval;
2613 
2614  for (STRING_VECTOR::const_iterator it = section_list.begin();
2615  it != section_list.end(); ++it)
2616  {
2617  const std::string & section_name = *it;
2618 
2619  // If this section name begins with the prefix
2620  if (section_name.compare(0, full_prefix_len, full_prefix) == 0)
2621  {
2622  const std::size_t next_slash_len =
2623  section_name.find('/', full_prefix_len);
2624 
2625  const std::string subsection_name =
2626  section_name.substr(full_prefix_len,
2627  next_slash_len - full_prefix_len);
2628 
2629  // If there is a subsection, and if this is the first time
2630  // we've seen it, add the prefix-less, postfix-less
2631  // subsection name.
2632  if (!subsection_name.empty() &&
2633  !subsections.count(subsection_name))
2634  {
2635  returnval.push_back(subsection_name);
2636  subsections.insert(subsection_name);
2637  }
2638  }
2639  }
2640 
2641  return returnval;
2642 }
2643 
2644 
2645 
2646 inline std::set<std::string>
2648 {
2649  return overridden_vars;
2650 }
2651 
2652 
2653 
2654 inline const GetPot::variable*
2655 GetPot::_find_variable(const char* VarName) const
2656 {
2657  const std::string Name = prefix + VarName;
2658 
2659  std::vector<variable>::const_iterator it = variables.begin();
2660  for (; it != variables.end(); ++it)
2661  {
2662  if ((*it).name == Name)
2663  return &(*it);
2664  }
2665  return 0;
2666 }
2667 
2668 
2669 
2670 inline const GetPot::variable*
2671 GetPot::_request_variable(const char* VarName) const
2672 {
2673  // (*) record requested variable for later ufo detection
2674  this->_record_variable_request(VarName);
2675 
2676  return this->_find_variable(VarName);
2677 }
2678 
2679 
2680 
2682 // (*) ouput (basically for debugging reasons
2683 //.............................................................................
2684 //
2685 inline int
2686 GetPot::print(std::ostream &out_stream) const
2687 {
2688  out_stream << "argc = " << argv.size() << std::endl;
2689  STRING_VECTOR::const_iterator it = argv.begin();
2690  for (; it != argv.end(); ++it)
2691  out_stream << *it << std::endl;
2692  out_stream << std::endl;
2693  return 1;
2694 }
2695 
2696 
2697 
2698 // PECOS/HPCT Addition - add option to prepend output with a delimiter
2699 // while also disabling argc print and skipping first print (the name
2700 // of the input file)
2701 //
2702 // PECOS Development Team: (ks. 4/16/09)
2703 inline int
2704 GetPot::print(const char* custom_prefix, std::ostream &out_stream, unsigned int skip_count) const
2705 {
2706  STRING_VECTOR::const_iterator it = argv.begin();
2707  it += skip_count;
2708  for (; it != argv.end(); ++it)
2709  {
2710  out_stream << custom_prefix;
2711  out_stream << *it << std::endl;
2712  }
2713  out_stream << std::endl;
2714  return 1;
2715 }
2716 
2717 
2718 
2719 // (*) dollar bracket expressions (DBEs) ------------------------------------
2720 //
2721 // 1) Entry Function: _DBE_expand_string()
2722 // Takes a string such as
2723 //
2724 // "${+ ${x} ${y}} Subject-${& ${section} ${subsection}}: ${title}"
2725 //
2726 // calls _DBE_expand() for each of the expressions
2727 //
2728 // ${+ ${x} ${y}}
2729 // ${& ${section} ${subsection}}
2730 // ${Title}
2731 //
2732 // and returns the string
2733 //
2734 // "4711 Subject-1.01: Mit den Clowns kamen die Schwaene"
2735 //
2736 // assuming that
2737 // x = "4699"
2738 // y = "12"
2739 // section = "1."
2740 // subsection = "01"
2741 // title = "Mit den Clowns kamen die Schwaene"
2742 //
2743 // 2) _DBE_expand():
2744 //
2745 // checks for the command, i.e. the 'sign' that follows '${'
2746 // divides the argument list into sub-expressions using
2747 // _DBE_get_expr_list()
2748 //
2749 // ${+ ${x} ${y}} -> "${x}" "${y}"
2750 // ${& ${section} ${subsection}} -> "${section}" "${subsection}"
2751 // ${Title} -> Nothing, variable expansion
2752 //
2753 // 3) _DBE_expression_list():
2754 //
2755 // builds a vector of unbracketed whitespace separated strings, i.e.
2756 //
2757 // " ${Number}.a ${: Das Marmorbild} AB-${& Author= ${Eichendorf}-1870}"
2758 //
2759 // is split into a vector
2760 //
2761 // [0] ${Number}.a
2762 // [1] ${: Das Marmorbild}
2763 // [2] AB-${& Author= ${Eichendorf}}-1870
2764 //
2765 // Each sub-expression is expanded using expand().
2766 //---------------------------------------------------------------------------
2767 inline std::string
2768 GetPot::_DBE_expand_string(const std::string& str)
2769 {
2770  // Parses for closing operators '${ }' and expands them letting
2771  // white spaces and other letters as they are.
2772  std::string new_string = "";
2773  unsigned open_brackets = 0;
2774  unsigned first = 0;
2775  for (unsigned i = 0; i<str.size(); i++)
2776  {
2777  if (i < str.size() - 2 && str.substr(i, 2) == "${")
2778  {
2779  if (open_brackets == 0)
2780  first = i+2;
2781  open_brackets++;
2782  }
2783  else if (str[i] == '}' && open_brackets > 0)
2784  {
2785  open_brackets -= 1;
2786  if (open_brackets == 0)
2787  {
2788  const std::string Replacement = _DBE_expand(str.substr(first, i - first));
2789  new_string += Replacement;
2790  }
2791  }
2792  else if (open_brackets == 0)
2793  new_string += str[i];
2794  }
2795  return new_string;
2796 }
2797 
2798 
2799 
2800 inline STRING_VECTOR
2801 GetPot::_DBE_get_expr_list(const std::string& str_, const unsigned ExpectedNumber)
2802 {
2803  // ensures that the resulting vector has the expected number
2804  // of arguments, but they may contain an error message
2805  std::string str = str_;
2806  // Separates expressions by non-bracketed whitespaces, expands them
2807  // and puts them into a list.
2808 
2809  unsigned i=0;
2810  // (1) eat initial whitespaces
2811  for (; i < str.size(); i++)
2812  if (!isspace(str[i]))
2813  break;
2814 
2815  STRING_VECTOR expr_list;
2816  unsigned open_brackets = 0;
2817  std::vector<unsigned> start_idx;
2818  unsigned start_new_string = i;
2819  unsigned l = (unsigned)(str.size());
2820 
2821  // (2) search for ${ } expressions ...
2822  while (i < l)
2823  {
2824  const char letter = str[i];
2825  // whitespace -> end of expression
2826  if (isspace(letter) && open_brackets == 0)
2827  {
2828  expr_list.push_back(str.substr(start_new_string, i - start_new_string));
2829  bool no_breakout_f = true;
2830  for (i++; i < l ; i++)
2831  {
2832  if (!isspace(str[i]))
2833  {
2834  no_breakout_f = false;
2835  start_new_string = i;
2836  break;
2837  }
2838  }
2839 
2840  if (no_breakout_f)
2841  {
2842  // end of expression list
2843  if (expr_list.size() < ExpectedNumber)
2844  {
2845  const std::string pre_tmp("<< ${ }: missing arguments>>");
2846  STRING_VECTOR tmp(ExpectedNumber - expr_list.size(), pre_tmp);
2847  expr_list.insert(expr_list.end(), tmp.begin(), tmp.end());
2848  }
2849  return expr_list;
2850  }
2851  }
2852 
2853  // dollar-bracket expression
2854  if (str.length() >= i+2 && str.substr(i, 2) == "${")
2855  {
2856  open_brackets++;
2857  start_idx.push_back(i+2);
2858  }
2859 
2860  else if (letter == '}' && open_brackets > 0)
2861  {
2862  int start = start_idx[start_idx.size()-1];
2863  start_idx.pop_back();
2864  const std::string Replacement = _DBE_expand(str.substr(start, i-start));
2865  if (start - 3 < (int)0)
2866  str = Replacement + str.substr(i+1);
2867  else
2868  str = str.substr(0, start-2) + Replacement + str.substr(i+1);
2869  l = (int)(str.size());
2870  i = start + (int)(Replacement.size()) - 3;
2871  open_brackets--;
2872  }
2873  i++;
2874  }
2875 
2876  // end of expression list
2877  expr_list.push_back(str.substr(start_new_string, i-start_new_string));
2878 
2879  if (expr_list.size() < ExpectedNumber)
2880  {
2881  const std::string pre_tmp("<< ${ }: missing arguments>>");
2882  STRING_VECTOR tmp(ExpectedNumber - expr_list.size(), pre_tmp);
2883  expr_list.insert(expr_list.end(), tmp.begin(), tmp.end());
2884  }
2885 
2886  return expr_list;
2887 }
2888 
2889 
2890 
2891 inline const GetPot::variable*
2892 GetPot::_DBE_get_variable(const std::string& VarName)
2893 {
2894  static GetPot::variable ev;
2895  std::string secure_Prefix = prefix;
2896 
2897  prefix = section;
2898  // (1) first search in currently active section
2899  const GetPot::variable* var = _request_variable(VarName.c_str());
2900  if (var != 0)
2901  {
2902  prefix = secure_Prefix;
2903  return var;
2904  }
2905 
2906  // (2) search in root name space
2907  prefix = "";
2908  var = _request_variable(VarName.c_str());
2909  if (var != 0)
2910  {
2911  prefix = secure_Prefix;
2912  return var;
2913  }
2914 
2915  prefix = secure_Prefix;
2916 
2917  // error occurred => variable name == ""
2918  ev.original = "<<${ } variable '";
2919  ev.original += VarName + "' undefined>>";
2920  return &ev;
2921 }
2922 
2923 
2924 
2925 inline std::string
2926 GetPot::_DBE_expand(const std::string& expr)
2927 {
2928  // ${: } pure text
2929  if (expr[0] == ':')
2930  return expr.substr(1);
2931 
2932  // ${& expr expr ... } text concatenation
2933  else if (expr[0] == '&')
2934  {
2935  const STRING_VECTOR A = _DBE_get_expr_list(expr.substr(1), 1);
2936 
2937  STRING_VECTOR::const_iterator it = A.begin();
2938  std::string result = *it++;
2939  for (; it != A.end(); ++it) result += *it;
2940 
2941  return result;
2942  }
2943 
2944  // ${<-> expr expr expr} text replacement
2945  else if (expr.length() >= 3 && expr.substr(0, 3) == "<->")
2946  {
2947  STRING_VECTOR A = _DBE_get_expr_list(expr.substr(3), 3);
2948  size_t tmp = 0;
2949  const size_t L = A[1].length();
2950 
2951  while ((tmp = A[0].find(A[1])) != std::string::npos)
2952  A[0].replace(tmp, L, A[2]);
2953 
2954  return A[0];
2955  }
2956 
2957  // ${=func [expr...] } function evaluation
2958  else if (expr.length() >= 2 &&
2959  expr.substr(0, 1) == "=" &&
2960  expr.substr(0, 2) != "==")
2961  {
2962  size_t funcnamestart = expr.find_first_not_of(" \t", 1);
2963  if (funcnamestart != std::string::npos)
2964  {
2965  size_t funcnameend = expr.find_first_of(" \t",funcnamestart);
2966  std::string funcname = expr.substr(funcnamestart,
2967  funcnameend-funcnamestart);
2968  if (funcname == "log")
2969  {
2970  STRING_VECTOR A =
2971  _DBE_get_expr_list(expr.substr(funcnameend), 1);
2972  double arg = _convert_to_type(A[0], 0.0);
2973  return _convert_from_type(std::log(arg));
2974  }
2975  else if (funcname == "log10")
2976  {
2977  STRING_VECTOR A =
2978  _DBE_get_expr_list(expr.substr(funcnameend), 1);
2979  double arg = _convert_to_type(A[0], 0.0);
2980  return _convert_from_type(std::log10(arg));
2981  }
2982  else if (funcname == "exp")
2983  {
2984  STRING_VECTOR A =
2985  _DBE_get_expr_list(expr.substr(funcnameend), 1);
2986  double arg = _convert_to_type(A[0], 0.0);
2987  return _convert_from_type(std::exp(arg));
2988  }
2989  else if (funcname == "sin")
2990  {
2991  STRING_VECTOR A =
2992  _DBE_get_expr_list(expr.substr(funcnameend), 1);
2993  double arg = _convert_to_type(A[0], 0.0);
2994  return _convert_from_type(std::sin(arg));
2995  }
2996  else if (funcname == "cos")
2997  {
2998  STRING_VECTOR A =
2999  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3000  double arg = _convert_to_type(A[0], 0.0);
3001  return _convert_from_type(std::cos(arg));
3002  }
3003  else if (funcname == "tan")
3004  {
3005  STRING_VECTOR A =
3006  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3007  double arg = _convert_to_type(A[0], 0.0);
3008  return _convert_from_type(std::tan(arg));
3009  }
3010  else if (funcname == "asin")
3011  {
3012  STRING_VECTOR A =
3013  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3014  double arg = _convert_to_type(A[0], 0.0);
3015  return _convert_from_type(std::asin(arg));
3016  }
3017  else if (funcname == "acos")
3018  {
3019  STRING_VECTOR A =
3020  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3021  double arg = _convert_to_type(A[0], 0.0);
3022  return _convert_from_type(std::acos(arg));
3023  }
3024  else if (funcname == "atan")
3025  {
3026  STRING_VECTOR A =
3027  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3028  double arg = _convert_to_type(A[0], 0.0);
3029  return _convert_from_type(std::atan(arg));
3030  }
3031  else if (funcname == "atan2")
3032  {
3033  STRING_VECTOR A =
3034  _DBE_get_expr_list(expr.substr(funcnameend), 2);
3035  double arg1 = _convert_to_type(A[0], 0.0);
3036  double arg2 = _convert_to_type(A[1], 0.0);
3037  return _convert_from_type(std::atan2(arg1, arg2));
3038  }
3039  else if (funcname == "sinh")
3040  {
3041  STRING_VECTOR A =
3042  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3043  double arg = _convert_to_type(A[0], 0.0);
3044  return _convert_from_type(std::sinh(arg));
3045  }
3046  else if (funcname == "cosh")
3047  {
3048  STRING_VECTOR A =
3049  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3050  double arg = _convert_to_type(A[0], 0.0);
3051  return _convert_from_type(std::cosh(arg));
3052  }
3053  else if (funcname == "tanh")
3054  {
3055  STRING_VECTOR A =
3056  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3057  double arg = _convert_to_type(A[0], 0.0);
3058  return _convert_from_type(std::tanh(arg));
3059  }
3060 #ifdef HAVE_INVERSE_HYPERBOLIC_SINE
3061  else if (funcname == "asinh")
3062  {
3063  STRING_VECTOR A =
3064  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3065  double arg = _convert_to_type(A[0], 0.0);
3066  return _convert_from_type(std::asinh(arg));
3067  }
3068 #endif
3069 #ifdef HAVE_INVERSE_HYPERBOLIC_COSINE
3070  else if (funcname == "acosh")
3071  {
3072  STRING_VECTOR A =
3073  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3074  double arg = _convert_to_type(A[0], 0.0);
3075  return _convert_from_type(std::acosh(arg));
3076  }
3077 #endif
3078 #ifdef HAVE_INVERSE_HYPERBOLIC_TANGENT
3079  else if (funcname == "atanh")
3080  {
3081  STRING_VECTOR A =
3082  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3083  double arg = _convert_to_type(A[0], 0.0);
3084  return _convert_from_type(std::atanh(arg));
3085  }
3086 #endif
3087  else if (funcname == "sqrt")
3088  {
3089  STRING_VECTOR A =
3090  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3091  double arg = _convert_to_type(A[0], 0.0);
3092  return _convert_from_type(std::sqrt(arg));
3093  }
3094  else if (funcname == "abs")
3095  {
3096  STRING_VECTOR A =
3097  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3098  double arg = _convert_to_type(A[0], 0.0);
3099  return _convert_from_type(std::abs(arg));
3100  }
3101  else if (funcname == "max")
3102  {
3103  STRING_VECTOR A =
3104  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3105  STRING_VECTOR::const_iterator it = A.begin();
3106  double result = _convert_to_type(*it++, 0.0);
3107  for (; it != A.end(); ++it)
3108  result = std::max(result, _convert_to_type(*it, 0.0));
3109  return _convert_from_type(result);
3110  }
3111  else if (funcname == "min")
3112  {
3113  STRING_VECTOR A =
3114  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3115  STRING_VECTOR::const_iterator it = A.begin();
3116  double result = _convert_to_type(*it++, 0.0);
3117  for (; it != A.end(); ++it)
3118  result = std::min(result, _convert_to_type(*it, 0.0));
3119  return _convert_from_type(result);
3120  }
3121  else if (funcname == "ceil")
3122  {
3123  STRING_VECTOR A =
3124  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3125  double arg = _convert_to_type(A[0], 0.0);
3126  return _convert_from_type(std::ceil(arg));
3127  }
3128  else if (funcname == "floor")
3129  {
3130  STRING_VECTOR A =
3131  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3132  double arg = _convert_to_type(A[0], 0.0);
3133  return _convert_from_type(std::floor(arg));
3134  }
3135  else if (funcname == "fmod")
3136  {
3137  STRING_VECTOR A =
3138  _DBE_get_expr_list(expr.substr(funcnameend), 2);
3139  double arg1 = _convert_to_type(A[0], 0.0);
3140  double arg2 = _convert_to_type(A[1], 0.0);
3141  return _convert_from_type(std::fmod(arg1, arg2));
3142  }
3143  else if (funcname == "srand")
3144  {
3145  STRING_VECTOR A =
3146  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3147  unsigned int arg = _convert_to_type(A[0], 0u);
3148  std::srand(arg);
3149  return A[0];
3150  }
3151  // ${=rand range} with default range==RAND_MAX
3152  else if (funcname == "rand")
3153  {
3154  if (funcnameend >= expr.length() ||
3155  expr.find_first_not_of(" \t", funcnameend) == std::string::npos)
3156  return _convert_from_type(std::rand());
3157 
3158  STRING_VECTOR A =
3159  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3160  unsigned int range = _convert_to_type(A[0],0u);
3161  if (!range)
3162  return _convert_from_type(0);
3163  const unsigned int x = (RAND_MAX + 1u) / range;
3164  const unsigned int y = x * range;
3165  unsigned int returnval;
3166  do
3167  {
3168  returnval = rand();
3169  } while (returnval >= y);
3170  return _convert_from_type(returnval / x);
3171  }
3172  else if (funcname == "time")
3173  return _convert_from_type(std::time(NULL));
3174  else
3175  {
3176  getpot_cerr << "ERROR: unrecognized function "
3177  << funcname << std::endl;
3178  getpot_error();
3179  }
3180  }
3181  }
3182 
3183  // ${+ ...}, ${- ...}, ${* ...}, ${/ ...} expressions
3184  else if (expr[0] == '+')
3185  {
3186  STRING_VECTOR A = _DBE_get_expr_list(expr.substr(1), 2);
3187  STRING_VECTOR::const_iterator it = A.begin();
3188  double result = _convert_to_type(*it++, 0.0);
3189  for (; it != A.end(); ++it)
3190  result += _convert_to_type(*it, 0.0);
3191 
3192  return _convert_from_type(result);
3193  }
3194  else if (expr[0] == '-')
3195  {
3196  STRING_VECTOR A = _DBE_get_expr_list(expr.substr(1), 2);
3197  STRING_VECTOR::const_iterator it = A.begin();
3198  double result = _convert_to_type(*it++, 0.0);
3199  for (; it != A.end(); ++it)
3200  result -= _convert_to_type(*it, 0.0);
3201 
3202  return _convert_from_type(result);
3203  }
3204  else if (expr[0] == '*')
3205  {
3206  STRING_VECTOR A = _DBE_get_expr_list(expr.substr(1), 2);
3207  STRING_VECTOR::const_iterator it = A.begin();
3208  double result = _convert_to_type(*it++, 0.0);
3209  for (; it != A.end(); ++it)
3210  result *= _convert_to_type(*it, 0.0);
3211 
3212  return _convert_from_type(result);
3213  }
3214  else if (expr[0] == '/')
3215  {
3216  STRING_VECTOR A = _DBE_get_expr_list(expr.substr(1), 2);
3217  STRING_VECTOR::const_iterator it = A.begin();
3218  double result = _convert_to_type(*it++, 0.0);
3219  if (result == 0)
3220  return "0.0";
3221 
3222  for (; it != A.end(); ++it)
3223  {
3224  const double Q = _convert_to_type(*it, 0.0);
3225  result /= Q;
3226  }
3227  return _convert_from_type(result);
3228  }
3229 
3230  // ${^ ... } power expressions
3231  else if (expr[0] == '^')
3232  {
3233  STRING_VECTOR A = _DBE_get_expr_list(expr.substr(1), 2);
3234  STRING_VECTOR::const_iterator it = A.begin();
3235  double result = _convert_to_type(*it++, 0.0);
3236  for (; it != A.end(); ++it)
3237  result = pow(result, _convert_to_type(*it, 0.0));
3238  return _convert_from_type(result);
3239  }
3240 
3241  // ${== } ${<= } ${>= } comparisons (return the number of the first 'match'
3242  else if (expr.length() >= 2 &&
3243  (expr.substr(0,2) == "==" || expr.substr(0,2) == ">=" ||
3244  expr.substr(0,2) == "<=" || expr[0] == '>' || expr[0] == '<'))
3245  {
3246  // differentiate between two and one sign operators
3247  unsigned op = 0;
3248  enum { EQ, GEQ, LEQ, GT, LT };
3249 
3250  if (expr.substr(0, 2) == "==")
3251  op = EQ;
3252 
3253  else if (expr.substr(0, 2) == ">=")
3254  op = GEQ;
3255 
3256  else if (expr.substr(0, 2) == "<=")
3257  op = LEQ;
3258 
3259  else if (expr[0] == '>')
3260  op = GT;
3261 
3262  else
3263  op = LT;
3264 
3265  STRING_VECTOR a;
3266  if (op == GT || op == LT)
3267  a = _DBE_get_expr_list(expr.substr(1), 2);
3268 
3269  else
3270  a = _DBE_get_expr_list(expr.substr(2), 2);
3271 
3272  std::string x_orig = a[0];
3273  double x = _convert_to_type(x_orig, 1e37);
3274  unsigned i = 1;
3275 
3276  STRING_VECTOR::const_iterator y_orig = a.begin();
3277  for (y_orig++; y_orig != a.end(); ++y_orig)
3278  {
3279  double y = _convert_to_type(*y_orig, 1e37);
3280 
3281  // set the strings as reference if one wasn't a number
3282  if (x == 1e37 || y == 1e37)
3283  {
3284  // it's a string comparison
3285  if ((op == EQ && x_orig == *y_orig) || (op == GEQ && x_orig >= *y_orig) ||
3286  (op == LEQ && x_orig <= *y_orig) || (op == GT && x_orig > *y_orig) ||
3287  (op == LT && x_orig < *y_orig))
3288  return _convert_from_type(i);
3289  }
3290  else
3291  {
3292  // it's a number comparison
3293  if ((op == EQ && x == y) || (op == GEQ && x >= y) ||
3294  (op == LEQ && x <= y) || (op == GT && x > y) ||
3295  (op == LT && x < y))
3296  return _convert_from_type(i);
3297  }
3298  i++;
3299  }
3300 
3301  // nothing fulfills the condition => return 0
3302  return "0";
3303  }
3304 
3305  // ${?? expr expr} select
3306  else if (expr.length() >= 2 && expr.substr(0, 2) == "??")
3307  {
3308  STRING_VECTOR a = _DBE_get_expr_list(expr.substr(2), 2);
3309  double x = _convert_to_type(a[0], 1e37);
3310 
3311  // last element is always the default argument
3312  if (x == 1e37 || x < 0 || x >= a.size() - 1)
3313  return a[a.size()-1];
3314 
3315  // round x to closest integer
3316  return a[int(x+0.5)];
3317  }
3318 
3319  // ${? expr expr expr} if then else conditions
3320  else if (expr[0] == '?')
3321  {
3322  STRING_VECTOR a = _DBE_get_expr_list(expr.substr(1), 2);
3323 
3324  if (_convert_to_type(a[0], 0.0) == 1.0)
3325  return a[1];
3326 
3327  else if (a.size() > 2)
3328  return a[2];
3329  }
3330  // ${! expr} maxro expansion
3331  else if (expr[0] == '!')
3332  {
3333  const GetPot::variable* Var = _DBE_get_variable(expr.substr(1));
3334  // error
3335  if (Var->name == "")
3336  return std::string(Var->original);
3337 
3338  const STRING_VECTOR A = _DBE_get_expr_list(Var->original, 2);
3339  return A[0];
3340  }
3341  // ${@: } - string subscription
3342  else if (expr.length() >= 2 && expr.substr(0,2) == "@:")
3343  {
3344  const STRING_VECTOR A = _DBE_get_expr_list(expr.substr(2), 2);
3345  double x = _convert_to_type(A[1], 1e37);
3346 
3347  // last element is always the default argument
3348  if (x == 1e37 || x < 0 || x >= A[0].size() - 1)
3349  return "<<1st index out of range>>";
3350 
3351  if (A.size() > 2)
3352  {
3353  double y = _convert_to_type(A[2], 1e37);
3354  if (y != 1e37 && y > 0 && y <= A[0].size() - 1 && y > x)
3355  return A[0].substr(int(x+0.5), int(y+1.5) - int(x+0.5));
3356 
3357  else if (y == -1)
3358  return A[0].substr(int(x+0.5));
3359 
3360  return "<<2nd index out of range>>";
3361  }
3362  else
3363  {
3364  char* tmp = new char[2];
3365  tmp[0] = A[0][int(x+0.5)]; tmp[1] = '\0';
3366  std::string result(tmp);
3367  delete [] tmp;
3368  return result;
3369  }
3370  }
3371  // ${@ } - vector subscription
3372  else if (expr[0] == '@')
3373  {
3374  STRING_VECTOR A = _DBE_get_expr_list(expr.substr(1), 2);
3375  const GetPot::variable* Var = _DBE_get_variable(A[0]);
3376  // error
3377  if (Var->name == "")
3378  {
3379  // make a copy of the string if an error occurred
3380  // (since the error variable is a static variable inside get_variable())
3381  return std::string(Var->original);
3382  }
3383 
3384  double x = _convert_to_type(A[1], 1e37);
3385 
3386  // last element is always the default argument
3387  if (x == 1e37 || x < 0 || x >= Var->value.size())
3388  return "<<1st index out of range>>";
3389 
3390  if (A.size() > 2)
3391  {
3392  double y = _convert_to_type(A[2], 1e37);
3393  int begin = int(x+0.5);
3394  int end = 0;
3395  if (y != 1e37 && y > 0 && y <= Var->value.size() && y > x)
3396  end = int(y+1.5);
3397  else if (y == -1)
3398  end = int(Var->value.size());
3399  else
3400  return "<<2nd index out of range>>";
3401 
3402  std::string result = *(Var->get_element(begin));
3403  for (int i = begin+1; i < end; i++)
3404  result += std::string(" ") + *(Var->get_element(i));
3405  return result;
3406  }
3407  else
3408  return *(Var->get_element(int(x+0.5)));
3409  }
3410 
3411  const STRING_VECTOR A = _DBE_get_expr_list(expr, 1);
3412  const GetPot::variable* B = _DBE_get_variable(A[0]);
3413 
3414  // make a copy of the string if an error occurred
3415  // (since the error variable is a static variable inside get_variable())
3416  if (B->name == "")
3417  return std::string(B->original);
3418 
3419  // (psuggs@pobox.com mentioned to me the warning MSVC++6.0 produces
3420  // with: else return B->original (thanks))
3421  return B->original;
3422 }
3423 
3424 
3425 
3427 // (*) unidentified flying objects
3428 //.............................................................................
3429 //
3430 inline bool
3431 GetPot::_search_string_vector(const STRING_VECTOR& VecStr, const std::string& Str) const
3432 {
3433  victorate(std::string, VecStr, itk)
3434  {
3435  if (*itk == Str)
3436  return true;
3437  }
3438  return false;
3439 }
3440 
3441 
3442 
3443 inline STRING_VECTOR
3445  const char* KnownArgument1, ...) const
3446 {
3447  std::set<std::string> known_arguments;
3448 
3449  // (1) create a vector of known arguments
3450  if (Number == 0)
3451  return STRING_VECTOR();
3452 
3453  va_list ap;
3454  va_start(ap, KnownArgument1);
3455  known_arguments.insert(std::string(KnownArgument1));
3456  for (unsigned i=1; i<Number; i++)
3457  known_arguments.insert(std::string(va_arg(ap, char *)));
3458  va_end(ap);
3459 
3460  return unidentified_arguments(known_arguments);
3461 }
3462 
3463 
3464 
3465 inline STRING_VECTOR
3467 {
3469 }
3470 
3471 
3472 
3473 inline STRING_VECTOR
3474 GetPot::unidentified_arguments(const std::vector<std::string>& Knowns) const
3475 {
3476  // We use set for efficiency, but want to support vector inputs for
3477  // backwards compatibility.
3478  return unidentified_arguments(std::set<std::string> (Knowns.begin(), Knowns.end()));
3479 }
3480 
3481 
3482 
3483 inline STRING_VECTOR
3484 GetPot::unidentified_arguments(const std::set<std::string>& Knowns) const
3485 {
3486  STRING_VECTOR ufos;
3487  STRING_VECTOR::const_iterator it = argv.begin();
3488  ++it; // forget about argv[0] (application or filename)
3489  for (; it != argv.end(); ++it)
3490  {
3491  // -- argument belongs to prefixed section ?
3492  const std::string arg = _get_remaining_string(*it, prefix);
3493  if (arg == "")
3494  continue;
3495 
3496  // -- check if in list
3497  if (Knowns.find(arg) == Knowns.end())
3498  ufos.push_back(*it);
3499  }
3500  return ufos;
3501 }
3502 
3503 
3504 
3505 inline STRING_VECTOR
3507  const char* KnownOption1, ...) const
3508 {
3509  std::set<std::string> known_options;
3510 
3511  // (1) create a vector of known arguments
3512  if (Number == 0)
3513  return STRING_VECTOR();
3514 
3515  va_list ap;
3516  va_start(ap, KnownOption1);
3517  known_options.insert(std::string(KnownOption1));
3518  for (unsigned i=1; i<Number; i++)
3519  known_options.insert(std::string(va_arg(ap, char *)));
3520  va_end(ap);
3521 
3522  return unidentified_options(known_options);
3523 }
3524 
3525 
3526 
3527 inline STRING_VECTOR
3529 {
3530  // -- every option is an argument.
3531  // -- the set of requested arguments contains the set of requested options.
3532  // -- IF the set of requested arguments contains unrequested options,
3533  // THEN they were requested as 'follow' and 'next' arguments and not as real options.
3534  //
3535  // => it is not necessary to separate requested options from the list
3537 }
3538 
3539 
3540 
3541 inline STRING_VECTOR
3542 GetPot::unidentified_options(const std::vector<std::string>& Knowns) const
3543 {
3544  // We use set for efficiency, but want to support vector inputs for
3545  // backwards compatibility.
3546  return unidentified_options(std::set<std::string> (Knowns.begin(), Knowns.end()));
3547 }
3548 
3549 
3550 
3551 inline STRING_VECTOR
3552 GetPot::unidentified_options(const std::set<std::string>& Knowns) const
3553 {
3554  STRING_VECTOR ufos;
3555  STRING_VECTOR::const_iterator it = argv.begin();
3556  ++it; // forget about argv[0] (application or filename)
3557  for (; it != argv.end(); ++it)
3558  {
3559  // -- argument belongs to prefixed section ?
3560  const std::string arg = _get_remaining_string(*it, prefix);
3561  if (arg == "")
3562  continue;
3563 
3564  // is argument really an option (starting with '-') ?
3565  if (arg.length() < 1 || arg[0] != '-')
3566  continue;
3567 
3568  if (Knowns.find(arg) == Knowns.end())
3569  ufos.push_back(*it);
3570  }
3571 
3572  return ufos;
3573 }
3574 
3575 
3576 
3577 // Two modes:
3578 // ArgumentNumber >= 0 check specific argument
3579 // ArgumentNumber == -1 check all options starting with one '-'
3580 // for flags
3581 inline std::string
3582 GetPot::unidentified_flags(const char* KnownFlagList, int ArgumentNumber=-1) const
3583 {
3584  std::string ufos;
3585  // STRING_VECTOR known_arguments;
3586  std::string KFL(KnownFlagList);
3587 
3588  // (2) iteration over '-' arguments (options)
3589  if (ArgumentNumber == -1)
3590  {
3591  STRING_VECTOR::const_iterator it = argv.begin();
3592  ++it; // forget about argv[0] (application or filename)
3593  for (; it != argv.end(); ++it)
3594  {
3595  // -- argument belongs to prefixed section ?
3596  const std::string arg = _get_remaining_string(*it, prefix);
3597  if (arg == "") continue;
3598 
3599  // -- does arguments start with '-' (but not '--')
3600  if (arg.length() < 2)
3601  continue;
3602 
3603  else if (arg[0] != '-')
3604  continue;
3605 
3606  else if (arg[1] == '-')
3607  continue;
3608 
3609  // -- check out if flags inside option are contained in KnownFlagList
3610  const char* p=arg.c_str();
3611  p++; // skip starting minus
3612  for (; *p != '\0' ; p++)
3613  if (KFL.find(*p) == std::string::npos) ufos += *p;
3614  }
3615  }
3616  // (1) check specific argument
3617  else
3618  {
3619  // -- only check arguments that start with prefix
3620  int no_matches = 0;
3621  for (unsigned i=1; i<argv.size(); i++)
3622  {
3623  const std::string Remain = _get_remaining_string(argv[i], prefix);
3624  if (Remain != "")
3625  {
3626  no_matches++;
3627  if (no_matches == ArgumentNumber)
3628  {
3629  // -- the right argument number inside the section is found
3630  // => check it for flags
3631  const char* p = Remain.c_str();
3632  p++; // skip starting minus
3633  for (; *p != '\0' ; p++)
3634  if (KFL.find(*p) == std::string::npos) ufos += *p;
3635  return ufos;
3636  }
3637  }
3638  }
3639  }
3640  return ufos;
3641 }
3642 
3643 
3644 
3645 inline STRING_VECTOR
3647  const char* KnownVariable1, ...) const
3648 {
3649  std::set<std::string> known_variables;
3650 
3651  // create vector of known arguments
3652  if (Number == 0)
3653  return STRING_VECTOR();
3654 
3655  va_list ap;
3656  va_start(ap, KnownVariable1);
3657  known_variables.insert(std::string(KnownVariable1));
3658  for (unsigned i=1; i<Number; i++)
3659  known_variables.insert(std::string(va_arg(ap, char *)));
3660  va_end(ap);
3661 
3662  return unidentified_variables(known_variables);
3663 }
3664 
3665 
3666 
3667 inline STRING_VECTOR
3668 GetPot::unidentified_variables(const std::vector<std::string>& Knowns) const
3669 {
3670  // We use set for efficiency, but want to support vector inputs for
3671  // backwards compatibility.
3672  return unidentified_variables(std::set<std::string> (Knowns.begin(), Knowns.end()));
3673 }
3674 
3675 
3676 
3677 inline STRING_VECTOR
3678 GetPot::unidentified_variables(const std::set<std::string>& Knowns) const
3679 {
3680  STRING_VECTOR ufos;
3681 
3682  victorate(GetPot::variable, variables, it)
3683  {
3684  // -- check if variable has specific prefix
3685  const std::string var_name = _get_remaining_string((*it).name, prefix);
3686  if (var_name == "")
3687  continue;
3688 
3689  // -- check if variable is known
3690  if (Knowns.find(var_name) == Knowns.end())
3691  ufos.push_back((*it).name);
3692  }
3693  return ufos;
3694 }
3695 
3696 
3697 
3698 inline STRING_VECTOR
3700 {
3702 }
3703 
3704 
3705 
3706 inline STRING_VECTOR
3708  const char* KnownSection1, ...) const
3709 {
3710  std::set<std::string> known_sections;
3711 
3712  // (1) create a vector of known arguments
3713  if (Number == 0)
3714  return STRING_VECTOR();
3715 
3716  va_list ap;
3717  va_start(ap, KnownSection1);
3718  known_sections.insert(std::string(KnownSection1));
3719  for (unsigned i=1; i<Number; i++)
3720  {
3721  std::string tmp = std::string(va_arg(ap, char *));
3722 
3723  if (tmp.length() == 0)
3724  continue;
3725 
3726  if (tmp[tmp.length()-1] != '/')
3727  tmp += '/';
3728 
3729  known_sections.insert(tmp);
3730  }
3731  va_end(ap);
3732 
3733  return unidentified_sections(known_sections);
3734 }
3735 
3736 
3737 
3738 inline STRING_VECTOR
3740 {
3742 }
3743 
3744 
3745 
3746 inline STRING_VECTOR
3747 GetPot::unidentified_sections(const std::vector<std::string>& Knowns) const
3748 {
3749  // We use set for efficiency, but want to support vector inputs for
3750  // backwards compatibility.
3751  return unidentified_sections(std::set<std::string> (Knowns.begin(), Knowns.end()));
3752 }
3753 
3754 
3755 
3756 inline STRING_VECTOR
3757 GetPot::unidentified_sections(const std::set<std::string>& Knowns) const
3758 {
3759  STRING_VECTOR ufos;
3760 
3761  victorate(std::string, section_list, it)
3762  {
3763  // -- check if section conform to prefix
3764  const std::string sec_name = _get_remaining_string(*it, prefix);
3765  if (sec_name == "")
3766  continue;
3767 
3768  // -- check if section is known
3769  if (Knowns.find(sec_name) == Knowns.end())
3770  ufos.push_back(*it);
3771  }
3772 
3773  return ufos;
3774 }
3775 
3776 
3777 
3778 inline STRING_VECTOR
3779 GetPot::unidentified_nominuses(unsigned Number, const char* Known, ...) const
3780 {
3781  std::set<std::string> known_nominuses;
3782 
3783  // create vector of known arguments
3784  if (Number == 0)
3785  return STRING_VECTOR();
3786 
3787  va_list ap;
3788  va_start(ap, Known);
3789  known_nominuses.insert(std::string(Known));
3790  for (unsigned i=1; i<Number; i++)
3791  {
3792  std::string tmp = std::string(va_arg(ap, char *));
3793  if (tmp.length() == 0)
3794  continue;
3795  known_nominuses.insert(tmp);
3796  }
3797  va_end(ap);
3798 
3799  return unidentified_nominuses(known_nominuses);
3800 }
3801 
3802 
3803 
3804 inline STRING_VECTOR
3806 {
3807  // -- every nominus is an argument.
3808  // -- the set of requested arguments contains the set of requested nominuss.
3809  // -- IF the set of requested arguments contains unrequested nominuss,
3810  // THEN they were requested as 'follow' and 'next' arguments and not as real nominuses.
3811  //
3812  // => it is not necessary to separate requested nominus from the list
3813 
3815 }
3816 
3817 
3818 
3819 inline STRING_VECTOR
3820 GetPot::unidentified_nominuses(const std::vector<std::string>& Knowns) const
3821 {
3822  // We use set for efficiency, but want to support vector inputs for
3823  // backwards compatibility.
3824  return unidentified_nominuses(std::set<std::string> (Knowns.begin(), Knowns.end()));
3825 }
3826 
3827 
3828 
3829 inline STRING_VECTOR
3830 GetPot::unidentified_nominuses(const std::set<std::string>& Knowns) const
3831 {
3832  STRING_VECTOR ufos;
3833 
3834  // (2) iterate over all arguments
3835  STRING_VECTOR::const_iterator it = argv.begin();
3836  ++it; // forget about argv[0] (application or filename)
3837  for (; it != argv.end(); ++it)
3838  {
3839  // -- check if nominus part of prefix
3840  const std::string arg = _get_remaining_string(*it, prefix);
3841  if (arg == "")
3842  continue;
3843 
3844  if (arg.length() < 1)
3845  continue;
3846 
3847  // option ? --> not a nomius
3848  if (arg[0] == '-')
3849  continue;
3850 
3851  // section ? --> not a real nominus
3852  if (arg[0] == '[' && arg[arg.length()-1] == ']')
3853  continue;
3854 
3855  // variable definition ? --> not a real nominus
3856  bool continue_f = false;
3857  for (unsigned i=0; i<arg.length() ; i++)
3858  if (arg[i] == '=')
3859  {
3860  continue_f = true;
3861  break;
3862  }
3863 
3864  if (continue_f)
3865  continue;
3866 
3867  // real nominuses are compared with the given list
3868  if (Knowns.find(arg) == Knowns.end())
3869  ufos.push_back(*it);
3870  }
3871  return ufos;
3872 }
3873 
3874 
3876 // (*) Accessors for requested types
3877 //.............................................................................
3878 
3879 inline
3880 std::set<std::string>
3882 {
3883  return _requested_arguments;
3884 }
3885 
3886 
3887 
3888 inline
3889 std::set<std::string>
3891 {
3892  return _requested_variables;
3893 }
3894 
3895 
3896 
3897 inline
3898 std::set<std::string>
3900 {
3901  return _requested_sections;
3902 }
3903 
3904 
3905 
3907 // (*) variable class
3908 //.............................................................................
3909 //
3910 inline
3912  : name(),
3913  value(),
3914  original()
3915 {}
3916 
3917 
3918 
3919 inline
3921 {
3922 #ifdef WIN32
3923  operator=(Other);
3924 #else
3926 #endif
3927 }
3928 
3929 
3930 
3931 inline
3932 GetPot::variable::variable(const char* Name, const char* Value, const char* FieldSeparator)
3933  : name(Name)
3934 {
3935  // make a copy of the 'Value'
3936  take(Value, FieldSeparator);
3937 }
3938 
3939 
3940 
3941 inline const std::string*
3943 {
3944  if (Idx >= value.size())
3945  return 0;
3946  else
3947  return &(value[Idx]);
3948 }
3949 
3950 
3951 
3952 inline void
3953 GetPot::variable::take(const char* Value, const char* FieldSeparator)
3954 {
3955  original = std::string(Value); // string member var
3956  value.clear(); // vector<string> member var
3957 
3958  /*
3959  // separate string by white space delimiters using 'strtok'
3960  // thread safe usage of strtok (no static members)
3961  char* spt = 0;
3962  // make a copy of the 'Value'
3963  char* copy = new char[strlen(Value)+1];
3964  strcpy(copy, Value);
3965  char* follow_token = strtok_r(copy, FieldSeparator, &spt);
3966  while (follow_token != 0)
3967  {
3968  value.push_back(std::string(follow_token));
3969  follow_token = strtok_r(NULL, FieldSeparator, &spt);
3970  }
3971 
3972  delete [] copy;
3973  */
3974 
3975  // Don't use strtok, instead tokenize the input char "Value" using std::string operations so
3976  // that the results end up in the local "value" member
3977 
3978  // Construct std::string objects from the input char*s. I think the only
3979  // FieldSeparator recognized by GetPot is whitespace?
3980  std::string Value_str = std::string(Value);
3981  std::string delimiters = std::string(FieldSeparator);
3982 
3983  // Skip delimiters at beginning.
3984  std::string::size_type lastPos = Value_str.find_first_not_of(delimiters, 0);
3985 
3986  // Find first "non-delimiter".
3987  std::string::size_type pos = Value_str.find_first_of(delimiters, lastPos);
3988 
3989  // Loop over the input string until all the tokens have been pushed back
3990  // into the local "value" member.
3991  while (std::string::npos != pos || std::string::npos != lastPos)
3992  {
3993  // Found a token, add it to the vector.
3994  value.push_back(Value_str.substr(lastPos, pos - lastPos));
3995 
3996  // Skip delimiters. Note the "not_of"
3997  lastPos = Value_str.find_first_not_of(delimiters, pos);
3998 
3999  // Find next "non-delimiter"
4000  pos = Value_str.find_first_of(delimiters, lastPos);
4001  }
4002 
4003  // We're done, all the tokens should now be in the vector<string>
4004 }
4005 
4006 inline
4008 {}
4009 
4010 
4011 
4012 inline GetPot::variable&
4014 {
4015  if (&Other != this)
4016  {
4017  name = Other.name;
4018  value = Other.value;
4019  original = Other.original;
4020  }
4021  return *this;
4022 }
4023 
4024 #ifdef GETPOT_NAMESPACE
4025 }
4026 #endif
4027 
4028 #undef victorate
4029 
4030 #endif // LIBMESH_GETPOT_H
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:39
std::set< std::string > get_requested_sections() const
Definition: getpot.h:3899
STRING_VECTOR unidentified_nominuses() const
Definition: getpot.h:3805
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
prefix extraction
Definition: getpot.h:1736
double abs(double a)
GETPOT_MUTEX_DECLARE
we have some mutable non-thread-safe members, but we want to be able to call const member functions f...
Definition: getpot.h:557
static STRING_VECTOR _get_section_tree(const std::string &FullPath)
cuts a variable name into a tree of sub-sections.
Definition: getpot.h:701
int nominus_cursor
nominus vector
Definition: getpot.h:524
const std::string _get_string(std::istream &istr)
Definition: getpot.h:1423
STRING_VECTOR get_section_names() const
Definition: getpot.h:2589
std::string _DBE_expand(const std::string &str)
Definition: getpot.h:2926
T _convert_to_type(const std::string &String, const T &Default) const
type conversion if possible
Definition: getpot.h:1567
void disable_loop()
enable/disable search for an option in loop
Definition: getpot.h:360
void reset_cursor()
reset cursor to position &#39;1&#39;
Definition: getpot.h:1852
void _record_argument_request(const std::string &Arg) const
if an argument is requested record it and the &#39;tag&#39; the section branch to which it belongs...
Definition: getpot.h:2454
STRING_VECTOR _read_in_stream(std::istream &istr)
Definition: getpot.h:1232
bool argument_contains(unsigned Idx, const char *FlagList) const
Definition: getpot.h:2120
std::string section
Definition: getpot.h:509
Variable to be specified on the command line or in input files.
Definition: getpot.h:478
variable()
constructors, destructors, assignment operator
Definition: getpot.h:3911
std::string name
data members
Definition: getpot.h:500
bool options_contain(const char *FlagList) const
flags
Definition: getpot.h:2101
const char * _internal_managed_copy(const std::string &Arg) const
some functions return a char pointer to a temporarily existing string this function adds them to our ...
Definition: getpot.h:1705
helper functor for creating sets of C-style strings
Definition: getpot.h:546
const std::string _get_until_closing_bracket(std::istream &istr)
Definition: getpot.h:1449
bool search(const char *option)
search for a certain option and set cursor to position
Definition: getpot.h:1763
STRING_VECTOR get_subsection_names(const std::string &section_name) const
Definition: getpot.h:2597
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:1482
IterBase * end
Also have a polymorphic pointer to the end object, this prevents iterating past the end...
variable & operator=(const variable &Other)
Definition: getpot.h:4013
void _parse_argument_vector(const STRING_VECTOR &ARGV)
produce three basic data vectors:
Definition: getpot.h:1129
void set(const char *VarName, const T &Value, const bool Requested=true)
setting variables i) from outside of GetPot (considering prefix etc.) ii) from inside, use &#39;_set_variable()&#39; below
Definition: getpot.h:2519
T follow(const T &Default, const char *Option)
search for option and get argument at cursor++
Definition: getpot.h:1946
long double max(long double a, double b)
bool _check_flags(const std::string &Str, const char *FlagList) const
support search for flags in a specific argument
Definition: getpot.h:2155
bool search_failed() const
Definition: getpot.h:355
void disable_request_recording()
Definition: getpot.h:209
const std::string _get_next_token(std::istream &istr)
Definition: getpot.h:1366
const variable * _request_variable(const char *) const
search (and record request) for a variable in &#39;variables&#39; array
Definition: getpot.h:2671
std::vector< unsigned > idx_nominus
Definition: getpot.h:525
bool operator()(const char *s1, const char *s2) const
Definition: getpot.h:548
STRING_VECTOR _DBE_get_expr_list(const std::string &str, const unsigned ExpectedNumber)
Definition: getpot.h:2801
std::string prefix
member variables
Definition: getpot.h:508
std::vector< variable > variables
variables (arguments of the form "variable=value")
Definition: getpot.h:530
GetPot & operator=(const GetPot &)
Definition: getpot.h:1030
Definition: assembly.h:38
STRING_VECTOR unidentified_variables() const
Definition: getpot.h:3699
STRING_VECTOR get_variable_names() const
Definition: getpot.h:2573
const char * _match_starting_string(const char *StartString)
support finding directly followed arguments
Definition: getpot.h:2057
std::string unidentified_flags(const char *Known, int ArgumentNumber) const
Definition: getpot.h:3582
T direct_follow(const T &Default, const char *Option)
directly followed arguments
Definition: getpot.h:2028
PetscErrorCode Vec x
STRING_VECTOR unidentified_arguments() const
Definition: getpot.h:3466
GetPot - A class for parsing command line arguments and configuration files.
Definition: getpot.h:153
GetPot()
constructors, destructor, assignment operator
Definition: getpot.h:743
void absorb(const GetPot &Other)
absorbing contents of another GetPot object
Definition: getpot.h:1086
void _basic_initialization()
Definition: getpot.h:720
STRING_VECTOR unidentified_options() const
Definition: getpot.h:3528
unsigned vector_variable_size(const char *VarName) const
Definition: getpot.h:2554
std::set< std::string > _requested_sections
Definition: getpot.h:581
void _skip_whitespace(std::istream &istr)
helpers to parse input file create an argument vector based on data found in an input file...
Definition: getpot.h:1304
STRING_VECTOR argv
argument vector
Definition: getpot.h:515
T _convert_to_type_no_default(const char *VarName, const std::string &String, const T &Default) const
Definition: getpot.h:1632
unsigned nominus_size() const
Definition: getpot.h:413
double pow(double a, int b)
bool have_section(const char *section_name) const
Check for a section name.
Definition: getpot.h:2255
void enable_request_recording()
Definition: getpot.h:210
T get_value_no_default(const char *VarName, const T &Default) const
access variables, but error out if not present scalar values
Definition: getpot.h:2366
bool _search_string_vector(const STRING_VECTOR &Vec, const std::string &Str) const
search for a specific string
Definition: getpot.h:3431
void _record_variable_request(const std::string &Arg) const
Definition: getpot.h:2476
bool have_variable(const char *VarName) const
variables
Definition: getpot.h:2236
const char * next_nominus()
Definition: getpot.h:2189
const GetPot::variable * _DBE_get_variable(const std::string &str)
Definition: getpot.h:2892
void set_prefix(const char *Prefix)
cursor oriented functions
Definition: getpot.h:354
void parse_input_stream(std::istream &FileStream, const std::string &FileName=std::string("ParsedFromStream"), const std::string &CommentStart=std::string("#"), const std::string &CommentEnd=std::string("\n"), const std::string &FieldSeparator=std::string(" \t\n"))
Definition: getpot.h:945
void reset_nominus_cursor()
nominus arguments
Definition: getpot.h:2224
unsigned size() const
Definition: getpot.h:1903
void clear_requests()
for ufo detection: recording requested arguments, options etc.
Definition: getpot.h:1116
std::string next_nominus_string()
Definition: getpot.h:2206
static PetscErrorCode Mat * A
void init_multiple_occurrence()
Definition: getpot.h:1861
static const bool value
Definition: xdr_io.C:108
void _set_variable(const std::string &VarName, const std::string &Value, const bool Requested)
helper functions
Definition: getpot.h:2500
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:1510
const variable * _find_variable(const char *) const
helpers for argument list processing
Definition: getpot.h:2655
void parse_input_file(const std::string &FileName, const std::string &CommentStart=std::string("#"), const std::string &CommentEnd=std::string("\n"), const std::string &FieldSeparator=std::string(" \t\n"))
Definition: getpot.h:897
const char * operator[](unsigned Idx) const
direct access to command line arguments
Definition: getpot.h:1874
std::string _field_separator
field separator (separating elements of a vector)
Definition: getpot.h:541
int print(std::ostream &out_stream=std::cout) const
output
Definition: getpot.h:2686
STRING_VECTOR nominus_vector() const
Definition: getpot.h:2170
void take(const char *Value, const char *FieldSeparator)
Definition: getpot.h:3953
void parse_command_line(const int argc_, const char *const *argv_, const char *FieldSeparator=0x0)
Re-initialization methods.
Definition: getpot.h:804
std::set< std::string > get_requested_variables() const
Definition: getpot.h:3890
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
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_element(unsigned Idx) const
get a specific element in the string vector (return 0 if not present)
Definition: getpot.h:3942
std::set< std::string > get_overridden_variables() const
Definition: getpot.h:2647
T next(const T &Default)
get argument at cursor++
Definition: getpot.h:1913
std::string _comment_start
comment delimiters
Definition: getpot.h:535
long double min(long double a, double b)
std::set< std::string > get_requested_arguments() const
Accessors for requested variables.
Definition: getpot.h:3881
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360
STRING_VECTOR unidentified_sections() const
Definition: getpot.h:3739
std::set< std::string > overridden_vars
Definition: getpot.h:519
std::set< std::string > _requested_arguments
keeping track about arguments that are requested, so that the UFO detection can be simplified ...
Definition: getpot.h:579
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
A useful inline function which replaces the macros used previously.
std::string _DBE_expand_string(const std::string &str)
dollar bracket expressions
Definition: getpot.h:2768
T get(unsigned Idx, const T &Default) const
std::set< const char *, ltstr > _internal_string_container
some functions return a char pointer to a string created on the fly.
Definition: getpot.h:567
T operator()(const char *VarName, const T &Default) const
scalar values
Definition: getpot.h:2284