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