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

Generated on Tue Jun 5 2018 19:48:54 for queso-0.57.1 by  doxygen 1.8.5