queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
GETPOT_NAMESPACE::GetPot Class Reference

#include <getpot.h>

Classes

struct  ltstr
 
struct  variable
 

Public Member Functions

 GetPot ()
 
 GetPot (const GetPot &)
 
 GetPot (const int argc_, const char *const *argv_, const char *FieldSeparator=0x0)
 
 GetPot (const char *FileName, const char *CommentStart=0x0, const char *CommentEnd=0x0, const char *FieldSeparator=0x0)
 
 GetPot (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"))
 
 GetPot (std::istream &FileStream, const std::string &CommentStart=std::string("#"), const std::string &CommentEnd=std::string("\n"), const std::string &FieldSeparator=std::string(" \t\n"))
 
 ~GetPot ()
 
GetPotoperator= (const GetPot &)
 
void parse_command_line (const int argc_, const char *const *argv_, const char *FieldSeparator=0x0)
 
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"))
 
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"))
 
void absorb (const GetPot &Other)
 
void clear_requests ()
 
void disable_request_recording ()
 
void enable_request_recording ()
 
const char * operator[] (unsigned Idx) const
 
template<typename T >
get (unsigned Idx, const T &Default) const
 
const char * get (unsigned Idx, const char *Default) const
 
unsigned size () const
 
bool options_contain (const char *FlagList) const
 
bool argument_contains (unsigned Idx, const char *FlagList) const
 
bool have_variable (const char *VarName) const
 
bool have_variable (const std::string &VarName) const
 
bool have_section (const char *section_name) const
 
bool have_section (const std::string &section_name) const
 
template<typename T >
operator() (const char *VarName, const T &Default) const
 
template<typename T >
operator() (const std::string &VarName, const T &Default) const
 
const char * operator() (const char *VarName, const char *Default) const
 
const char * operator() (const std::string &VarName, const char *Default) const
 
template<typename T >
operator() (const char *VarName, const T &Default, unsigned Idx) const
 
template<typename T >
operator() (const std::string &VarName, const T &Default, unsigned Idx) const
 
const char * operator() (const char *VarName, const char *Default, unsigned Idx) const
 
const char * operator() (const std::string &VarName, const char *Default, unsigned Idx) const
 
template<typename T >
get_value_no_default (const char *VarName, const T &Default) const
 
template<typename T >
get_value_no_default (const std::string &VarName, const T &Default) const
 
const char * get_value_no_default (const char *VarName, const char *Default) const
 
const char * get_value_no_default (const std::string &VarName, const char *Default) const
 
template<typename T >
get_value_no_default (const char *VarName, const T &Default, unsigned Idx) const
 
template<typename T >
get_value_no_default (const std::string &VarName, const T &Default, unsigned Idx) const
 
const char * get_value_no_default (const char *VarName, const char *Default, unsigned Idx) const
 
const char * get_value_no_default (const std::string &VarName, const char *Default, unsigned Idx) const
 
template<typename T >
void set (const char *VarName, const T &Value, const bool Requested=true)
 
template<typename T >
void set (const std::string &VarName, const T &Value, const bool Requested=true)
 
void set (const char *VarName, const char *Value, const bool Requested=true)
 
void set (const std::string &VarName, const char *Value, const bool Requested=true)
 
unsigned vector_variable_size (const char *VarName) const
 
unsigned vector_variable_size (const std::string &VarName) const
 
STRING_VECTOR get_variable_names () const
 
STRING_VECTOR get_section_names () const
 
std::set< std::string > get_overridden_variables () const
 
void set_prefix (const char *Prefix)
 
bool search_failed () const
 
void disable_loop ()
 
void enable_loop ()
 
void reset_cursor ()
 
void init_multiple_occurrence ()
 
bool search (const char *option)
 
bool search (const std::string &option)
 
bool search (unsigned No, const char *P,...)
 
template<typename T >
next (const T &Default)
 
const char * next (const char *Default)
 
template<typename T >
follow (const T &Default, const char *Option)
 
const char * follow (const char *Default, const char *Option)
 
template<typename T >
follow (const T &Default, unsigned No, const char *Option,...)
 
const char * follow (const char *Default, unsigned No, const char *Option,...)
 
template<typename T >
direct_follow (const T &Default, const char *Option)
 
const char * direct_follow (const char *Default, const char *Option)
 
void reset_nominus_cursor ()
 
STRING_VECTOR nominus_vector () const
 
unsigned nominus_size () const
 
const char * next_nominus ()
 
std::string next_nominus_string ()
 
STRING_VECTOR unidentified_arguments (unsigned Number, const char *Known,...) const
 
STRING_VECTOR unidentified_arguments (const std::set< std::string > &Knowns) const
 
STRING_VECTOR unidentified_arguments (const std::vector< std::string > &Knowns) const
 
STRING_VECTOR unidentified_arguments () const
 
STRING_VECTOR unidentified_options (unsigned Number, const char *Known,...) const
 
STRING_VECTOR unidentified_options (const std::set< std::string > &Knowns) const
 
STRING_VECTOR unidentified_options (const std::vector< std::string > &Knowns) const
 
STRING_VECTOR unidentified_options () const
 
std::string unidentified_flags (const char *Known, int ArgumentNumber) const
 
STRING_VECTOR unidentified_variables (unsigned Number, const char *Known,...) const
 
STRING_VECTOR unidentified_variables (const std::set< std::string > &Knowns) const
 
STRING_VECTOR unidentified_variables (const std::vector< std::string > &Knowns) const
 
STRING_VECTOR unidentified_variables () const
 
STRING_VECTOR unidentified_sections (unsigned Number, const char *Known,...) const
 
STRING_VECTOR unidentified_sections (const std::set< std::string > &Knowns) const
 
STRING_VECTOR unidentified_sections (const std::vector< std::string > &Knowns) const
 
STRING_VECTOR unidentified_sections () const
 
STRING_VECTOR unidentified_nominuses (unsigned Number, const char *Known,...) const
 
STRING_VECTOR unidentified_nominuses (const std::set< std::string > &Knowns) const
 
STRING_VECTOR unidentified_nominuses (const std::vector< std::string > &Knowns) const
 
STRING_VECTOR unidentified_nominuses () const
 
std::set< std::string > get_requested_arguments () const
 
std::set< std::string > get_requested_variables () const
 
std::set< std::string > get_requested_sections () const
 
int print (std::ostream &out_stream=std::cout) const
 
int print (const char *custom_prefix, std::ostream &out_stream=std::cout, unsigned int skip_count=1) const
 
template<>
std::string _convert_to_type (const std::string &String, const std::string &) const
 
template<>
std::string _convert_to_type_no_default (const char *, const std::string &String, const std::string &) const
 
template<typename T >
get (unsigned int Idx, const T &Default) const
 
template<typename T >
follow (const T &Default, unsigned int No, const char *P,...)
 
template<typename T >
operator() (const char *VarName, const T &Default, unsigned int Idx) const
 
template<typename T >
operator() (const std::string &VarName, const T &Default, unsigned int Idx) const
 
template<typename T >
get_value_no_default (const char *VarName, const T &Default, unsigned int Idx) const
 
template<typename T >
get_value_no_default (const std::string &VarName, const T &Default, unsigned int Idx) const
 

Private Member Functions

void _basic_initialization ()
 
const char * _internal_managed_copy (const std::string &Arg) const
 
void _record_argument_request (const std::string &Arg) const
 
void _record_variable_request (const std::string &Arg) const
 
void _set_variable (const std::string &VarName, const std::string &Value, const bool Requested)
 
void _parse_argument_vector (const STRING_VECTOR &ARGV)
 
const variable_find_variable (const char *) const
 
const variable_request_variable (const char *) const
 
const char * _match_starting_string (const char *StartString)
 
bool _check_flags (const std::string &Str, const char *FlagList) const
 
template<typename T >
_convert_to_type (const std::string &String, const T &Default) const
 
std::string _convert_to_type (const std::string &String, const char *Default) const
 
template<typename T >
_convert_to_type_no_default (const char *VarName, const std::string &String, const T &Default) const
 
std::string _convert_to_type_no_default (const char *VarName, const std::string &String, const char *Default) const
 
const std::string _get_remaining_string (const std::string &String, const std::string &Start) const
 
bool _search_string_vector (const STRING_VECTOR &Vec, const std::string &Str) const
 
void _skip_whitespace (std::istream &istr)
 
const std::string _get_next_token (std::istream &istr)
 
const std::string _get_string (std::istream &istr)
 
const std::string _get_until_closing_bracket (std::istream &istr)
 
const std::string _get_until_closing_square_bracket (std::istream &istr)
 
STRING_VECTOR _read_in_stream (std::istream &istr)
 
std::string _process_section_label (const std::string &Section, STRING_VECTOR &section_stack)
 
std::string _DBE_expand_string (const std::string &str)
 
std::string _DBE_expand (const std::string &str)
 
const GetPot::variable_DBE_get_variable (const std::string &str)
 
STRING_VECTOR _DBE_get_expr_list (const std::string &str, const unsigned ExpectedNumber)
 
template<>
bool _convert_to_type (const std::string &String, const bool &Default) const
 
template<>
bool _convert_to_type_no_default (const char *VarName, const std::string &String, const bool &) const
 

Static Private Member Functions

template<typename T >
static std::string _convert_from_type (const T &Value)
 
static STRING_VECTOR _get_section_tree (const std::string &FullPath)
 

Private Attributes

std::string prefix
 
std::string section
 
STRING_VECTOR section_list
 
STRING_VECTOR argv
 
unsigned cursor
 
bool search_loop_f
 
bool search_failed_f
 
std::set< std::string > overridden_vars
 
int nominus_cursor
 
std::vector< unsigned > idx_nominus
 
std::vector< variablevariables
 
std::string _comment_start
 
std::string _comment_end
 
std::string _field_separator
 
 GETPOT_MUTEX_DECLARE
 
std::set< const char *, ltstr_internal_string_container
 
std::set< std::string > _requested_arguments
 
std::set< std::string > _requested_variables
 
std::set< std::string > _requested_sections
 
bool request_recording_f
 

Detailed Description

GetPot - A class for parsing comand line arguments and configuration files.

Author
Frank R. Schaefer
Date
(C) 2001-2002

Definition at line 152 of file getpot.h.

Constructor & Destructor Documentation

GETPOT_NAMESPACE::GetPot::GetPot ( )
inline

constructors, destructor, assignment operator

Definition at line 721 of file getpot.h.

References _basic_initialization().

721  :
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(),
735 #if !defined(GETPOT_DISABLE_MUTEX)
736  _getpot_mtx(),
737 #endif
743 {
745 }
std::set< const char *, ltstr > _internal_string_container
Definition: getpot.h:545
std::string _comment_start
Definition: getpot.h:513
STRING_VECTOR argv
Definition: getpot.h:493
std::vector< unsigned > idx_nominus
Definition: getpot.h:503
std::string prefix
Definition: getpot.h:486
STRING_VECTOR section_list
Definition: getpot.h:488
void _basic_initialization()
Definition: getpot.h:698
std::string _field_separator
Definition: getpot.h:519
std::string section
Definition: getpot.h:487
std::set< std::string > _requested_variables
Definition: getpot.h:558
std::set< std::string > _requested_arguments
Definition: getpot.h:557
std::vector< variable > variables
Definition: getpot.h:508
std::string _comment_end
Definition: getpot.h:514
std::set< std::string > _requested_sections
Definition: getpot.h:559
GETPOT_NAMESPACE::GetPot::GetPot ( const GetPot Other)
inline

Definition at line 954 of file getpot.h.

References _internal_string_container.

954  :
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
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 }
std::set< const char *, ltstr > _internal_string_container
Definition: getpot.h:545
std::string _comment_start
Definition: getpot.h:513
STRING_VECTOR argv
Definition: getpot.h:493
std::vector< unsigned > idx_nominus
Definition: getpot.h:503
std::string prefix
Definition: getpot.h:486
STRING_VECTOR section_list
Definition: getpot.h:488
std::string _field_separator
Definition: getpot.h:519
std::string section
Definition: getpot.h:487
std::set< std::string > _requested_variables
Definition: getpot.h:558
std::set< std::string > _requested_arguments
Definition: getpot.h:557
std::vector< variable > variables
Definition: getpot.h:508
std::set< std::string > overridden_vars
Definition: getpot.h:497
std::string _comment_end
Definition: getpot.h:514
std::set< std::string > _requested_sections
Definition: getpot.h:559
GETPOT_NAMESPACE::GetPot::GetPot ( const int  argc_,
const char *const *  argv_,
const char *  FieldSeparator = 0x0 
)
inline

Definition at line 750 of file getpot.h.

References parse_command_line().

751  :
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(),
766 #if !defined(GETPOT_DISABLE_MUTEX)
767  _getpot_mtx(),
768 #endif
774 {
775  this->parse_command_line(argc_, argv_, FieldSeparator);
776 }
std::set< const char *, ltstr > _internal_string_container
Definition: getpot.h:545
std::string _comment_start
Definition: getpot.h:513
STRING_VECTOR argv
Definition: getpot.h:493
std::vector< unsigned > idx_nominus
Definition: getpot.h:503
std::string prefix
Definition: getpot.h:486
STRING_VECTOR section_list
Definition: getpot.h:488
std::string _field_separator
Definition: getpot.h:519
std::string section
Definition: getpot.h:487
void parse_command_line(const int argc_, const char *const *argv_, const char *FieldSeparator=0x0)
Definition: getpot.h:782
std::set< std::string > _requested_variables
Definition: getpot.h:558
std::set< std::string > _requested_arguments
Definition: getpot.h:557
std::vector< variable > variables
Definition: getpot.h:508
std::string _comment_end
Definition: getpot.h:514
std::set< std::string > _requested_sections
Definition: getpot.h:559
GETPOT_NAMESPACE::GetPot::GetPot ( const char *  FileName,
const char *  CommentStart = 0x0,
const char *  CommentEnd = 0x0,
const char *  FieldSeparator = 0x0 
)
inline

Definition at line 811 of file getpot.h.

References parse_input_file().

813  :
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(),
827 #if !defined(GETPOT_DISABLE_MUTEX)
828  _getpot_mtx(),
829 #endif
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 }
std::set< const char *, ltstr > _internal_string_container
Definition: getpot.h:545
std::string _comment_start
Definition: getpot.h:513
STRING_VECTOR argv
Definition: getpot.h:493
std::vector< unsigned > idx_nominus
Definition: getpot.h:503
std::string prefix
Definition: getpot.h:486
STRING_VECTOR section_list
Definition: getpot.h:488
std::string _field_separator
Definition: getpot.h:519
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
std::string section
Definition: getpot.h:487
std::set< std::string > _requested_variables
Definition: getpot.h:558
std::set< std::string > _requested_arguments
Definition: getpot.h:557
std::vector< variable > variables
Definition: getpot.h:508
std::string _comment_end
Definition: getpot.h:514
std::set< std::string > _requested_sections
Definition: getpot.h:559
GETPOT_NAMESPACE::GetPot::GetPot ( 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") 
)
inline

Definition at line 845 of file getpot.h.

References parse_input_file().

848  :
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(),
862 #if !defined(GETPOT_DISABLE_MUTEX)
863  _getpot_mtx(),
864 #endif
870 {
871  this->parse_input_file(FileName, CommentStart, CommentEnd, FieldSeparator);
872 }
std::set< const char *, ltstr > _internal_string_container
Definition: getpot.h:545
std::string _comment_start
Definition: getpot.h:513
STRING_VECTOR argv
Definition: getpot.h:493
std::vector< unsigned > idx_nominus
Definition: getpot.h:503
std::string prefix
Definition: getpot.h:486
STRING_VECTOR section_list
Definition: getpot.h:488
std::string _field_separator
Definition: getpot.h:519
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
std::string section
Definition: getpot.h:487
std::set< std::string > _requested_variables
Definition: getpot.h:558
std::set< std::string > _requested_arguments
Definition: getpot.h:557
std::vector< variable > variables
Definition: getpot.h:508
std::string _comment_end
Definition: getpot.h:514
std::set< std::string > _requested_sections
Definition: getpot.h:559
GETPOT_NAMESPACE::GetPot::GetPot ( std::istream &  FileStream,
const std::string &  CommentStart = std::string("#"),
const std::string &  CommentEnd = std::string("\n"),
const std::string &  FieldSeparator = std::string(" \t\n") 
)
inline

This constructor is mainly for testing. The std::string based constructor should be preferred.

Definition at line 890 of file getpot.h.

References parse_input_stream().

893  :
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(),
907 #if !defined(GETPOT_DISABLE_MUTEX)
908  _getpot_mtx(),
909 #endif
915 {
916  this->parse_input_stream(FileStream,
917  std::string("ParsedFromStream"),// We don't have a filename here
918  CommentStart, CommentEnd, FieldSeparator);
919 }
std::set< const char *, ltstr > _internal_string_container
Definition: getpot.h:545
std::string _comment_start
Definition: getpot.h:513
STRING_VECTOR argv
Definition: getpot.h:493
std::vector< unsigned > idx_nominus
Definition: getpot.h:503
std::string prefix
Definition: getpot.h:486
STRING_VECTOR section_list
Definition: getpot.h:488
std::string _field_separator
Definition: getpot.h:519
std::string section
Definition: getpot.h:487
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
std::set< std::string > _requested_variables
Definition: getpot.h:558
std::set< std::string > _requested_arguments
Definition: getpot.h:557
std::vector< variable > variables
Definition: getpot.h:508
std::string _comment_end
Definition: getpot.h:514
std::set< std::string > _requested_sections
Definition: getpot.h:559
GETPOT_NAMESPACE::GetPot::~GetPot ( )
inline

Definition at line 996 of file getpot.h.

References _internal_string_container.

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 }
std::set< const char *, ltstr > _internal_string_container
Definition: getpot.h:545

Member Function Documentation

void GETPOT_NAMESPACE::GetPot::_basic_initialization ( )
inlineprivate

Definition at line 698 of file getpot.h.

References _comment_end, _comment_start, _field_separator, cursor, nominus_cursor, prefix, request_recording_f, search_failed_f, search_loop_f, and section.

Referenced by GetPot(), parse_command_line(), and parse_input_stream().

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 }
std::string _comment_start
Definition: getpot.h:513
std::string prefix
Definition: getpot.h:486
std::string _field_separator
Definition: getpot.h:519
std::string section
Definition: getpot.h:487
std::string _comment_end
Definition: getpot.h:514
bool GETPOT_NAMESPACE::GetPot::_check_flags ( const std::string &  Str,
const char *  FlagList 
) const
inlineprivate

support search for flags in a specific argument

Definition at line 2133 of file getpot.h.

Referenced by argument_contains(), and options_contain().

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 }
template<typename T >
static std::string GETPOT_NAMESPACE::GetPot::_convert_from_type ( const T &  Value)
inlinestaticprivate

Definition at line 668 of file getpot.h.

Referenced by _DBE_expand().

669  {
670  std::ostringstream out_string;
671  out_string << Value;
672  return out_string.str();
673  }
template<typename T >
T GETPOT_NAMESPACE::GetPot::_convert_to_type ( const std::string &  String,
const T &  Default 
) const
inlineprivate

type conversion if possible

Definition at line 1545 of file getpot.h.

Referenced by _DBE_expand(), direct_follow(), get(), next(), and operator()().

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 }
std::string GETPOT_NAMESPACE::GetPot::_convert_to_type ( const std::string &  String,
const char *  Default 
) const
inlineprivate

Definition at line 1569 of file getpot.h.

1570 {
1571  return String;
1572 }
template<>
std::string GETPOT_NAMESPACE::GetPot::_convert_to_type ( const std::string &  String,
const std::string &   
) const
inline

Definition at line 1560 of file getpot.h.

1561 {
1562  return String;
1563 }
template<>
bool GETPOT_NAMESPACE::GetPot::_convert_to_type ( const std::string &  String,
const bool &  Default 
) const
inlineprivate

Definition at line 1579 of file getpot.h.

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 }
template<typename T >
T GETPOT_NAMESPACE::GetPot::_convert_to_type_no_default ( const char *  VarName,
const std::string &  String,
const T &  Default 
) const
inlineprivate

Definition at line 1610 of file getpot.h.

Referenced by get_value_no_default().

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 }
std::string GETPOT_NAMESPACE::GetPot::_convert_to_type_no_default ( const char *  VarName,
const std::string &  String,
const char *  Default 
) const
inlineprivate

Definition at line 1638 of file getpot.h.

1639 {
1640  return String;
1641 }
template<>
std::string GETPOT_NAMESPACE::GetPot::_convert_to_type_no_default ( const char *  ,
const std::string &  String,
const std::string &   
) const
inline

Definition at line 1629 of file getpot.h.

1630 {
1631  return String;
1632 }
template<>
bool GETPOT_NAMESPACE::GetPot::_convert_to_type_no_default ( const char *  VarName,
const std::string &  String,
const bool &   
) const
inlineprivate

Definition at line 1648 of file getpot.h.

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 }
std::string GETPOT_NAMESPACE::GetPot::_DBE_expand ( const std::string &  str)
inlineprivate

Definition at line 2854 of file getpot.h.

References _convert_from_type(), _convert_to_type(), _DBE_get_expr_list(), _DBE_get_variable(), GETPOT_NAMESPACE::GetPot::variable::name, GETPOT_NAMESPACE::GetPot::variable::original, and size().

Referenced by _DBE_expand_string(), and _DBE_get_expr_list().

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 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:131
static std::string _convert_from_type(const T &Value)
Definition: getpot.h:668
T _convert_to_type(const std::string &String, const T &Default) const
Definition: getpot.h:1545
unsigned size() const
Definition: getpot.h:1881
const GetPot::variable * _DBE_get_variable(const std::string &str)
Definition: getpot.h:2820
STRING_VECTOR _DBE_get_expr_list(const std::string &str, const unsigned ExpectedNumber)
Definition: getpot.h:2729
std::string GETPOT_NAMESPACE::GetPot::_DBE_expand_string ( const std::string &  str)
inlineprivate

dollar bracket expressions

Definition at line 2696 of file getpot.h.

References _DBE_expand().

Referenced by _parse_argument_vector().

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 }
std::string _DBE_expand(const std::string &str)
Definition: getpot.h:2854
STRING_VECTOR GETPOT_NAMESPACE::GetPot::_DBE_get_expr_list ( const std::string &  str,
const unsigned  ExpectedNumber 
)
inlineprivate

Definition at line 2729 of file getpot.h.

References _DBE_expand().

Referenced by _DBE_expand().

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 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:131
std::string _DBE_expand(const std::string &str)
Definition: getpot.h:2854
const GetPot::variable * GETPOT_NAMESPACE::GetPot::_DBE_get_variable ( const std::string &  str)
inlineprivate

Definition at line 2820 of file getpot.h.

References _request_variable(), GETPOT_NAMESPACE::GetPot::variable::original, prefix, and section.

Referenced by _DBE_expand().

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 }
const variable * _request_variable(const char *) const
Definition: getpot.h:2599
std::string prefix
Definition: getpot.h:486
std::string section
Definition: getpot.h:487
const GetPot::variable * GETPOT_NAMESPACE::GetPot::_find_variable ( const char *  VarName) const
inlineprivate

helpers for argument list processing search for a variable in 'variables' array

Definition at line 2583 of file getpot.h.

References prefix, and variables.

Referenced by _request_variable(), and _set_variable().

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 }
std::string prefix
Definition: getpot.h:486
std::vector< variable > variables
Definition: getpot.h:508
const std::string GETPOT_NAMESPACE::GetPot::_get_next_token ( std::istream &  istr)
inlineprivate

Definition at line 1344 of file getpot.h.

References _get_string(), _get_until_closing_bracket(), and _get_until_closing_square_bracket().

Referenced by _read_in_stream().

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 }
const std::string _get_string(std::istream &istr)
Definition: getpot.h:1401
const std::string _get_until_closing_bracket(std::istream &istr)
Definition: getpot.h:1427
const std::string _get_until_closing_square_bracket(std::istream &istr)
Definition: getpot.h:1460
const std::string GETPOT_NAMESPACE::GetPot::_get_remaining_string ( const std::string &  String,
const std::string &  Start 
) const
inlineprivate

prefix extraction

Definition at line 1714 of file getpot.h.

Referenced by argument_contains(), get_variable_names(), next(), options_contain(), unidentified_arguments(), unidentified_flags(), unidentified_nominuses(), unidentified_options(), unidentified_sections(), and unidentified_variables().

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 }
static STRING_VECTOR GETPOT_NAMESPACE::GetPot::_get_section_tree ( const std::string &  FullPath)
inlinestaticprivate

cuts a variable name into a tree of sub-sections. this is requested for recording requested sections when dealing with 'ufo' detection.

Definition at line 679 of file getpot.h.

Referenced by _record_argument_request(), and _record_variable_request().

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  }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:131
const std::string GETPOT_NAMESPACE::GetPot::_get_string ( std::istream &  istr)
inlineprivate

Definition at line 1401 of file getpot.h.

Referenced by _get_next_token().

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 }
const std::string GETPOT_NAMESPACE::GetPot::_get_until_closing_bracket ( std::istream &  istr)
inlineprivate

Definition at line 1427 of file getpot.h.

Referenced by _get_next_token().

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 }
const std::string GETPOT_NAMESPACE::GetPot::_get_until_closing_square_bracket ( std::istream &  istr)
inlineprivate

Definition at line 1460 of file getpot.h.

Referenced by _get_next_token().

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 }
const char * GETPOT_NAMESPACE::GetPot::_internal_managed_copy ( const std::string &  Arg) const
inlineprivate

some functions return a char pointer to a temporarily existing string this function adds them to our container

Definition at line 1683 of file getpot.h.

References _internal_string_container.

Referenced by direct_follow(), follow(), get_value_no_default(), next(), next_nominus(), and operator()().

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 }
std::set< const char *, ltstr > _internal_string_container
Definition: getpot.h:545
const char * GETPOT_NAMESPACE::GetPot::_match_starting_string ( const char *  StartString)
inlineprivate

support finding directly followed arguments

Definition at line 2035 of file getpot.h.

References argv, cursor, search_failed_f, and search_loop_f.

Referenced by direct_follow().

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 }
STRING_VECTOR argv
Definition: getpot.h:493
void GETPOT_NAMESPACE::GetPot::_parse_argument_vector ( const STRING_VECTOR ARGV)
inlineprivate

produce three basic data vectors:

  • argument vector
  • nominus vector
  • variable dictionary

Definition at line 1107 of file getpot.h.

References _comment_end, _comment_start, _DBE_expand_string(), _field_separator, _process_section_label(), _requested_arguments, _set_variable(), argv, idx_nominus, parse_input_file(), request_recording_f, section, and section_list.

Referenced by parse_command_line(), and parse_input_stream().

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 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:131
std::string _comment_start
Definition: getpot.h:513
STRING_VECTOR argv
Definition: getpot.h:493
std::vector< unsigned > idx_nominus
Definition: getpot.h:503
STRING_VECTOR section_list
Definition: getpot.h:488
std::string _DBE_expand_string(const std::string &str)
Definition: getpot.h:2696
std::string _field_separator
Definition: getpot.h:519
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
std::string _process_section_label(const std::string &Section, STRING_VECTOR &section_stack)
Definition: getpot.h:1488
std::string section
Definition: getpot.h:487
std::set< std::string > _requested_arguments
Definition: getpot.h:557
void _set_variable(const std::string &VarName, const std::string &Value, const bool Requested)
Definition: getpot.h:2478
std::string _comment_end
Definition: getpot.h:514
std::string GETPOT_NAMESPACE::GetPot::_process_section_label ( const std::string &  Section,
STRING_VECTOR section_stack 
)
inlineprivate

Definition at line 1488 of file getpot.h.

Referenced by _parse_argument_vector().

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 }
STRING_VECTOR GETPOT_NAMESPACE::GetPot::_read_in_stream ( std::istream &  istr)
inlineprivate

Definition at line 1210 of file getpot.h.

References _comment_start, _get_next_token(), and _skip_whitespace().

Referenced by parse_input_stream().

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 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:131
void _skip_whitespace(std::istream &istr)
Definition: getpot.h:1282
std::string _comment_start
Definition: getpot.h:513
const std::string _get_next_token(std::istream &istr)
Definition: getpot.h:1344
void GETPOT_NAMESPACE::GetPot::_record_argument_request ( const std::string &  Arg) const
inlineprivate

if an argument is requested record it and the 'tag' the section branch to which it belongs. Caution: both functions mark the sections as 'tagged'. These are "const" functions but they do modify the mutable requested* members

Definition at line 2432 of file getpot.h.

References _get_section_tree(), _requested_arguments, _requested_sections, request_recording_f, and section.

Referenced by argument_contains(), direct_follow(), next(), next_nominus(), next_nominus_string(), nominus_vector(), and search().

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 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:131
static STRING_VECTOR _get_section_tree(const std::string &FullPath)
Definition: getpot.h:679
std::string section
Definition: getpot.h:487
McOptionsValues::McOptionsValues(#ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS const SsOptionsValues *alternativePSsOptionsValues, const SsOptionsValues *alternativeQSsOptionsValues#endif if)(m_alternativeQSsOptionsValues=*alternativeQSsOptionsValues)
std::set< std::string > _requested_arguments
Definition: getpot.h:557
std::set< std::string > _requested_sections
Definition: getpot.h:559
void GETPOT_NAMESPACE::GetPot::_record_variable_request ( const std::string &  Arg) const
inlineprivate

Definition at line 2454 of file getpot.h.

References _get_section_tree(), _requested_sections, _requested_variables, request_recording_f, and section.

Referenced by _request_variable().

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 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:131
static STRING_VECTOR _get_section_tree(const std::string &FullPath)
Definition: getpot.h:679
std::string section
Definition: getpot.h:487
McOptionsValues::McOptionsValues(#ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS const SsOptionsValues *alternativePSsOptionsValues, const SsOptionsValues *alternativeQSsOptionsValues#endif if)(m_alternativeQSsOptionsValues=*alternativeQSsOptionsValues)
std::set< std::string > _requested_variables
Definition: getpot.h:558
std::set< std::string > _requested_sections
Definition: getpot.h:559
const GetPot::variable * GETPOT_NAMESPACE::GetPot::_request_variable ( const char *  VarName) const
inlineprivate

search (and record request) for a variable in 'variables' array

Definition at line 2599 of file getpot.h.

References _find_variable(), and _record_variable_request().

Referenced by _DBE_get_variable(), _set_variable(), get_value_no_default(), have_variable(), operator()(), and vector_variable_size().

2600 {
2601  // (*) record requested variable for later ufo detection
2602  this->_record_variable_request(VarName);
2603 
2604  return this->_find_variable(VarName);
2605 }
void _record_variable_request(const std::string &Arg) const
Definition: getpot.h:2454
const variable * _find_variable(const char *) const
Definition: getpot.h:2583
bool GETPOT_NAMESPACE::GetPot::_search_string_vector ( const STRING_VECTOR Vec,
const std::string &  Str 
) const
inlineprivate

search for a specific string

Definition at line 3359 of file getpot.h.

3360 {
3361  victorate(std::string, VecStr, itk)
3362  {
3363  if (*itk == Str)
3364  return true;
3365  }
3366  return false;
3367 }
void GETPOT_NAMESPACE::GetPot::_set_variable ( const std::string &  VarName,
const std::string &  Value,
const bool  Requested 
)
inlineprivate

helper functions set variable from inside GetPot (no prefix considered)

Definition at line 2478 of file getpot.h.

References _field_separator, _find_variable(), _request_variable(), overridden_vars, and variables.

Referenced by _parse_argument_vector(), and set().

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 }
const variable * _request_variable(const char *) const
Definition: getpot.h:2599
std::string _field_separator
Definition: getpot.h:519
std::vector< variable > variables
Definition: getpot.h:508
std::set< std::string > overridden_vars
Definition: getpot.h:497
const variable * _find_variable(const char *) const
Definition: getpot.h:2583
void GETPOT_NAMESPACE::GetPot::_skip_whitespace ( std::istream &  istr)
inlineprivate

helpers to parse input file create an argument vector based on data found in an input file, i.e.: 1) delete comments (in between '_comment_start' '_comment_end') 2) contract assignment expressions, such as my-variable = '007 J. B.' into my-variable='007 J. B.' 3) interprete sections like '[../my-section]' etc.

Definition at line 1282 of file getpot.h.

References _comment_end, and _comment_start.

Referenced by _read_in_stream().

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 }
std::string _comment_start
Definition: getpot.h:513
std::string _comment_end
Definition: getpot.h:514
void GETPOT_NAMESPACE::GetPot::absorb ( const GetPot Other)
inline

absorbing contents of another GetPot object

Definition at line 1064 of file getpot.h.

References _requested_arguments, _requested_sections, _requested_variables, argv, request_recording_f, and variables.

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 }
STRING_VECTOR argv
Definition: getpot.h:493
std::set< std::string > _requested_variables
Definition: getpot.h:558
std::set< std::string > _requested_arguments
Definition: getpot.h:557
std::vector< variable > variables
Definition: getpot.h:508
std::set< std::string > _requested_sections
Definition: getpot.h:559
bool GETPOT_NAMESPACE::GetPot::argument_contains ( unsigned  Idx,
const char *  FlagList 
) const
inline

Definition at line 2098 of file getpot.h.

References _check_flags(), _get_remaining_string(), _record_argument_request(), argv, and prefix.

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 }
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
Definition: getpot.h:1714
void _record_argument_request(const std::string &Arg) const
Definition: getpot.h:2432
STRING_VECTOR argv
Definition: getpot.h:493
std::string prefix
Definition: getpot.h:486
bool _check_flags(const std::string &Str, const char *FlagList) const
Definition: getpot.h:2133
void GETPOT_NAMESPACE::GetPot::clear_requests ( )
inline

for ufo detection: recording requested arguments, options etc.

Definition at line 1094 of file getpot.h.

References _requested_arguments, _requested_sections, and _requested_variables.

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 }
std::set< std::string > _requested_variables
Definition: getpot.h:558
std::set< std::string > _requested_arguments
Definition: getpot.h:557
std::set< std::string > _requested_sections
Definition: getpot.h:559
template<typename T >
T GETPOT_NAMESPACE::GetPot::direct_follow ( const T &  Default,
const char *  Option 
)
inline

directly followed arguments

Definition at line 2006 of file getpot.h.

References _convert_to_type(), _match_starting_string(), _record_argument_request(), argv, and cursor.

Referenced by direct_follow().

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 }
T _convert_to_type(const std::string &String, const T &Default) const
Definition: getpot.h:1545
void _record_argument_request(const std::string &Arg) const
Definition: getpot.h:2432
STRING_VECTOR argv
Definition: getpot.h:493
const char * _match_starting_string(const char *StartString)
Definition: getpot.h:2035
const char * GETPOT_NAMESPACE::GetPot::direct_follow ( const char *  Default,
const char *  Option 
)
inline

Definition at line 2024 of file getpot.h.

References _internal_managed_copy(), and direct_follow().

2025 {
2026  return _internal_managed_copy(direct_follow(std::string(Default), Option));
2027 }
const char * _internal_managed_copy(const std::string &Arg) const
Definition: getpot.h:1683
T direct_follow(const T &Default, const char *Option)
Definition: getpot.h:2006
void GETPOT_NAMESPACE::GetPot::disable_loop ( )
inline

enable/disable search for an option in loop

Definition at line 338 of file getpot.h.

References search_loop_f.

Referenced by init_multiple_occurrence().

338 { search_loop_f = false; }
void GETPOT_NAMESPACE::GetPot::disable_request_recording ( )
inline

Definition at line 208 of file getpot.h.

References request_recording_f.

208 { request_recording_f = false; }
void GETPOT_NAMESPACE::GetPot::enable_loop ( )
inline

Definition at line 339 of file getpot.h.

References search_loop_f.

339 { search_loop_f = true; }
void GETPOT_NAMESPACE::GetPot::enable_request_recording ( )
inline

Definition at line 209 of file getpot.h.

References request_recording_f.

209 { request_recording_f = true; }
template<typename T >
T GETPOT_NAMESPACE::GetPot::follow ( const T &  Default,
const char *  Option 
)
inline

search for option and get argument at cursor++

Definition at line 1924 of file getpot.h.

References next(), and search().

Referenced by follow().

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 }
T next(const T &Default)
Definition: getpot.h:1891
bool search(const char *option)
Definition: getpot.h:1741
const char * GETPOT_NAMESPACE::GetPot::follow ( const char *  Default,
const char *  Option 
)
inline

Definition at line 1936 of file getpot.h.

References _internal_managed_copy(), and follow().

1937 {
1938  return _internal_managed_copy(follow(std::string(Default), Option));
1939 }
const char * _internal_managed_copy(const std::string &Arg) const
Definition: getpot.h:1683
T follow(const T &Default, const char *Option)
Definition: getpot.h:1924
template<typename T >
T GETPOT_NAMESPACE::GetPot::follow ( const T &  Default,
unsigned  No,
const char *  Option,
  ... 
)
inline

search for one of the given options and get argument that follows it

const char * GETPOT_NAMESPACE::GetPot::follow ( const char *  Default,
unsigned  No,
const char *  Option,
  ... 
)
inline

Definition at line 1974 of file getpot.h.

References next(), and search().

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 }
T next(const T &Default)
Definition: getpot.h:1891
bool search(const char *option)
Definition: getpot.h:1741
template<typename T >
T GETPOT_NAMESPACE::GetPot::follow ( const T &  Default,
unsigned int  No,
const char *  P,
  ... 
)
inline

Definition at line 1947 of file getpot.h.

References next(), and search().

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 }
T next(const T &Default)
Definition: getpot.h:1891
bool search(const char *option)
Definition: getpot.h:1741
template<typename T >
T GETPOT_NAMESPACE::GetPot::get ( unsigned  Idx,
const T &  Default 
) const
inline
const char* GETPOT_NAMESPACE::GetPot::get ( unsigned  Idx,
const char *  Default 
) const
inline
template<typename T >
T GETPOT_NAMESPACE::GetPot::get ( unsigned int  Idx,
const T &  Default 
) const
inline

Definition at line 1861 of file getpot.h.

References _convert_to_type(), and argv.

1862 {
1863  if (Idx >= argv.size())
1864  return Default;
1865  return _convert_to_type(argv[Idx], Default);
1866 }
T _convert_to_type(const std::string &String, const T &Default) const
Definition: getpot.h:1545
STRING_VECTOR argv
Definition: getpot.h:493
std::set< std::string > GETPOT_NAMESPACE::GetPot::get_overridden_variables ( ) const
inline

Definition at line 2575 of file getpot.h.

References overridden_vars.

2576 {
2577  return overridden_vars;
2578 }
std::set< std::string > overridden_vars
Definition: getpot.h:497
std::set< std::string > GETPOT_NAMESPACE::GetPot::get_requested_arguments ( ) const
inline

Accessors for requested variables

Definition at line 3809 of file getpot.h.

References _requested_arguments.

3810 {
3811  return _requested_arguments;
3812 }
std::set< std::string > _requested_arguments
Definition: getpot.h:557
std::set< std::string > GETPOT_NAMESPACE::GetPot::get_requested_sections ( ) const
inline

Definition at line 3827 of file getpot.h.

References _requested_sections.

3828 {
3829  return _requested_sections;
3830 }
std::set< std::string > _requested_sections
Definition: getpot.h:559
std::set< std::string > GETPOT_NAMESPACE::GetPot::get_requested_variables ( ) const
inline

Definition at line 3818 of file getpot.h.

References _requested_variables.

3819 {
3820  return _requested_variables;
3821 }
std::set< std::string > _requested_variables
Definition: getpot.h:558
STRING_VECTOR GETPOT_NAMESPACE::GetPot::get_section_names ( ) const
inline

Definition at line 2567 of file getpot.h.

References section_list.

2568 {
2569  return section_list;
2570 }
STRING_VECTOR section_list
Definition: getpot.h:488
template<typename T >
T GETPOT_NAMESPACE::GetPot::get_value_no_default ( const char *  VarName,
const T &  Default 
) const
inline

access varibles, but error out if not present scalar values

Definition at line 2344 of file getpot.h.

References _convert_to_type_no_default(), _request_variable(), and GETPOT_NAMESPACE::GetPot::variable::original.

Referenced by get_value_no_default().

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 }
const variable * _request_variable(const char *) const
Definition: getpot.h:2599
T _convert_to_type_no_default(const char *VarName, const std::string &String, const T &Default) const
Definition: getpot.h:1610
template<typename T >
T GETPOT_NAMESPACE::GetPot::get_value_no_default ( const std::string &  VarName,
const T &  Default 
) const
inline

Definition at line 2360 of file getpot.h.

References get_value_no_default().

2361 {
2362  return get_value_no_default(VarName.c_str(),Default);
2363 }
T get_value_no_default(const char *VarName, const T &Default) const
Definition: getpot.h:2344
const char * GETPOT_NAMESPACE::GetPot::get_value_no_default ( const char *  VarName,
const char *  Default 
) const
inline

Definition at line 2368 of file getpot.h.

References _internal_managed_copy(), and get_value_no_default().

2369 {
2370  return _internal_managed_copy(get_value_no_default(VarName, std::string(Default)));
2371 }
T get_value_no_default(const char *VarName, const T &Default) const
Definition: getpot.h:2344
const char * _internal_managed_copy(const std::string &Arg) const
Definition: getpot.h:1683
const char * GETPOT_NAMESPACE::GetPot::get_value_no_default ( const std::string &  VarName,
const char *  Default 
) const
inline

Definition at line 2376 of file getpot.h.

References get_value_no_default().

2377 {
2378  return get_value_no_default(VarName.c_str(),Default);
2379 }
T get_value_no_default(const char *VarName, const T &Default) const
Definition: getpot.h:2344
template<typename T >
T GETPOT_NAMESPACE::GetPot::get_value_no_default ( const char *  VarName,
const T &  Default,
unsigned  Idx 
) const
inline

vectors

template<typename T >
T GETPOT_NAMESPACE::GetPot::get_value_no_default ( const std::string &  VarName,
const T &  Default,
unsigned  Idx 
) const
inline
const char* GETPOT_NAMESPACE::GetPot::get_value_no_default ( const char *  VarName,
const char *  Default,
unsigned  Idx 
) const
inline
const char* GETPOT_NAMESPACE::GetPot::get_value_no_default ( const std::string &  VarName,
const char *  Default,
unsigned  Idx 
) const
inline
template<typename T >
T GETPOT_NAMESPACE::GetPot::get_value_no_default ( const char *  VarName,
const T &  Default,
unsigned int  Idx 
) const
inline

Definition at line 2385 of file getpot.h.

References _convert_to_type_no_default(), _request_variable(), and GETPOT_NAMESPACE::GetPot::variable::get_element().

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 }
const variable * _request_variable(const char *) const
Definition: getpot.h:2599
T _convert_to_type_no_default(const char *VarName, const std::string &String, const T &Default) const
Definition: getpot.h:1610
template<typename T >
T GETPOT_NAMESPACE::GetPot::get_value_no_default ( const std::string &  VarName,
const T &  Default,
unsigned int  Idx 
) const
inline

Definition at line 2408 of file getpot.h.

References get_value_no_default().

2409 {
2410  return get_value_no_default(VarName.c_str(), Default, Idx);
2411 }
T get_value_no_default(const char *VarName, const T &Default) const
Definition: getpot.h:2344
STRING_VECTOR GETPOT_NAMESPACE::GetPot::get_variable_names ( ) const
inline

Definition at line 2551 of file getpot.h.

References _get_remaining_string(), prefix, and variables.

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 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:131
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
Definition: getpot.h:1714
std::string prefix
Definition: getpot.h:486
std::vector< variable > variables
Definition: getpot.h:508
bool GETPOT_NAMESPACE::GetPot::have_section ( const char *  section_name) const
inline

Check for a section name. When querying, the section_name can be of the form Section1 or Section1/

Section1/Section2 or Section1/Section2/

etc.

Definition at line 2233 of file getpot.h.

2234 {
2235  std::string s = std::string(section_name);
2236  return this->have_section(s);
2237 }
bool have_section(const char *section_name) const
Definition: getpot.h:2233
bool GETPOT_NAMESPACE::GetPot::have_section ( const std::string &  section_name) const
inline

Check for a section name. When querying, the section_name can be of the form Section1 or Section1/

Section1/Section2 or Section1/Section2/

etc.

Definition at line 2240 of file getpot.h.

References section_list.

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 }
STRING_VECTOR section_list
Definition: getpot.h:488
bool GETPOT_NAMESPACE::GetPot::have_variable ( const char *  VarName) const
inline

variables check for a variable

Definition at line 2214 of file getpot.h.

References _request_variable().

Referenced by have_variable().

2215 {
2216  const variable* sv = _request_variable(VarName);
2217 
2218  if (sv == 0)
2219  return false;
2220 
2221  return true;
2222 }
const variable * _request_variable(const char *) const
Definition: getpot.h:2599
bool GETPOT_NAMESPACE::GetPot::have_variable ( const std::string &  VarName) const
inline

Definition at line 2227 of file getpot.h.

References have_variable().

2228 {
2229  return have_variable(VarName.c_str());
2230 }
bool have_variable(const char *VarName) const
Definition: getpot.h:2214
void GETPOT_NAMESPACE::GetPot::init_multiple_occurrence ( )
inline

Definition at line 1839 of file getpot.h.

References disable_loop(), and reset_cursor().

1840 {
1841  disable_loop();
1842  reset_cursor();
1843 }
template<typename T >
T GETPOT_NAMESPACE::GetPot::next ( const T &  Default)
inline

get argument at cursor++

Definition at line 1891 of file getpot.h.

References _convert_to_type(), _get_remaining_string(), _record_argument_request(), argv, cursor, prefix, and search_failed_f.

Referenced by follow(), and next().

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 }
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
void _record_argument_request(const std::string &Arg) const
Definition: getpot.h:2432
STRING_VECTOR argv
Definition: getpot.h:493
std::string prefix
Definition: getpot.h:486
const char * GETPOT_NAMESPACE::GetPot::next ( const char *  Default)
inline

Definition at line 1913 of file getpot.h.

References _internal_managed_copy(), and next().

1914 {
1915  return _internal_managed_copy(next(std::string(Default)));
1916 }
const char * _internal_managed_copy(const std::string &Arg) const
Definition: getpot.h:1683
T next(const T &Default)
Definition: getpot.h:1891
const char * GETPOT_NAMESPACE::GetPot::next_nominus ( )
inline

Definition at line 2167 of file getpot.h.

References _internal_managed_copy(), _record_argument_request(), argv, idx_nominus, and nominus_cursor.

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 }
void _record_argument_request(const std::string &Arg) const
Definition: getpot.h:2432
STRING_VECTOR argv
Definition: getpot.h:493
const char * _internal_managed_copy(const std::string &Arg) const
Definition: getpot.h:1683
std::vector< unsigned > idx_nominus
Definition: getpot.h:503
std::string GETPOT_NAMESPACE::GetPot::next_nominus_string ( )
inline

Definition at line 2184 of file getpot.h.

References _record_argument_request(), argv, idx_nominus, and nominus_cursor.

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 }
void _record_argument_request(const std::string &Arg) const
Definition: getpot.h:2432
STRING_VECTOR argv
Definition: getpot.h:493
std::vector< unsigned > idx_nominus
Definition: getpot.h:503
unsigned GETPOT_NAMESPACE::GetPot::nominus_size ( ) const
inline

Definition at line 391 of file getpot.h.

References idx_nominus.

391 { return getpot_cast_int<unsigned>(idx_nominus.size()); }
std::vector< unsigned > idx_nominus
Definition: getpot.h:503
STRING_VECTOR GETPOT_NAMESPACE::GetPot::nominus_vector ( ) const
inline

Definition at line 2148 of file getpot.h.

References _record_argument_request(), argv, and idx_nominus.

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 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:131
void _record_argument_request(const std::string &Arg) const
Definition: getpot.h:2432
STRING_VECTOR argv
Definition: getpot.h:493
std::vector< unsigned > idx_nominus
Definition: getpot.h:503
template<typename T >
T GETPOT_NAMESPACE::GetPot::operator() ( const char *  VarName,
const T &  Default 
) const
inline

scalar values

Definition at line 2262 of file getpot.h.

References _convert_to_type(), _request_variable(), and GETPOT_NAMESPACE::GetPot::variable::original.

Referenced by operator()().

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 }
T _convert_to_type(const std::string &String, const T &Default) const
Definition: getpot.h:1545
const variable * _request_variable(const char *) const
Definition: getpot.h:2599
template<typename T >
T GETPOT_NAMESPACE::GetPot::operator() ( const std::string &  VarName,
const T &  Default 
) const
inline

Definition at line 2277 of file getpot.h.

References operator()().

2278 {
2279  return operator()(VarName.c_str(), Default);
2280 }
T operator()(const char *VarName, const T &Default) const
Definition: getpot.h:2262
const char * GETPOT_NAMESPACE::GetPot::operator() ( const char *  VarName,
const char *  Default 
) const
inline

Definition at line 2285 of file getpot.h.

References _internal_managed_copy().

2286 {
2287  return _internal_managed_copy(operator()(VarName, std::string(Default)));
2288 }
const char * _internal_managed_copy(const std::string &Arg) const
Definition: getpot.h:1683
const char * GETPOT_NAMESPACE::GetPot::operator() ( const std::string &  VarName,
const char *  Default 
) const
inline

Definition at line 2293 of file getpot.h.

References operator()().

2294 {
2295  return operator()(VarName.c_str(), Default);
2296 }
T operator()(const char *VarName, const T &Default) const
Definition: getpot.h:2262
template<typename T >
T GETPOT_NAMESPACE::GetPot::operator() ( const char *  VarName,
const T &  Default,
unsigned  Idx 
) const
inline

vectors

template<typename T >
T GETPOT_NAMESPACE::GetPot::operator() ( const std::string &  VarName,
const T &  Default,
unsigned  Idx 
) const
inline
const char* GETPOT_NAMESPACE::GetPot::operator() ( const char *  VarName,
const char *  Default,
unsigned  Idx 
) const
inline
const char* GETPOT_NAMESPACE::GetPot::operator() ( const std::string &  VarName,
const char *  Default,
unsigned  Idx 
) const
inline
template<typename T >
T GETPOT_NAMESPACE::GetPot::operator() ( const char *  VarName,
const T &  Default,
unsigned int  Idx 
) const
inline

Definition at line 2302 of file getpot.h.

References _convert_to_type(), _request_variable(), and GETPOT_NAMESPACE::GetPot::variable::get_element().

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 }
T _convert_to_type(const std::string &String, const T &Default) const
Definition: getpot.h:1545
const variable * _request_variable(const char *) const
Definition: getpot.h:2599
template<typename T >
T GETPOT_NAMESPACE::GetPot::operator() ( const std::string &  VarName,
const T &  Default,
unsigned int  Idx 
) const
inline

Definition at line 2319 of file getpot.h.

References operator()().

2320 {
2321  return operator()(VarName.c_str(), Default, Idx);
2322 }
T operator()(const char *VarName, const T &Default) const
Definition: getpot.h:2262
GetPot & GETPOT_NAMESPACE::GetPot::operator= ( const GetPot Other)
inline

Definition at line 1008 of file getpot.h.

References _comment_end, _comment_start, _field_separator, _internal_string_container, _requested_arguments, _requested_sections, _requested_variables, argv, cursor, idx_nominus, nominus_cursor, overridden_vars, prefix, request_recording_f, search_failed_f, search_loop_f, section, section_list, and variables.

Referenced by GETPOT_NAMESPACE::GetPot::variable::variable().

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;
1019  search_failed_f = Other.search_failed_f;
1020  nominus_cursor = Other.nominus_cursor;
1021  overridden_vars = Other.overridden_vars;
1022  idx_nominus = Other.idx_nominus;
1023  variables = Other.variables;
1024  _comment_start = Other._comment_start;
1025  _comment_end = Other._comment_end;
1026  _field_separator = Other._field_separator;
1027  // #if !defined(GETPOT_DISABLE_MUTEX)
1028  // _getpot_mtx = Other._getpot_mtx;
1029  // #endif
1030  _requested_arguments = Other._requested_arguments;
1031  _requested_variables = Other._requested_variables;
1032  _requested_sections = Other._requested_sections;
1033  request_recording_f = Other.request_recording_f;
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 }
std::set< const char *, ltstr > _internal_string_container
Definition: getpot.h:545
std::string _comment_start
Definition: getpot.h:513
STRING_VECTOR argv
Definition: getpot.h:493
std::vector< unsigned > idx_nominus
Definition: getpot.h:503
std::string prefix
Definition: getpot.h:486
STRING_VECTOR section_list
Definition: getpot.h:488
std::string _field_separator
Definition: getpot.h:519
std::string section
Definition: getpot.h:487
std::set< std::string > _requested_variables
Definition: getpot.h:558
std::set< std::string > _requested_arguments
Definition: getpot.h:557
std::vector< variable > variables
Definition: getpot.h:508
std::set< std::string > overridden_vars
Definition: getpot.h:497
std::string _comment_end
Definition: getpot.h:514
std::set< std::string > _requested_sections
Definition: getpot.h:559
const char * GETPOT_NAMESPACE::GetPot::operator[] ( unsigned  Idx) const
inline

direct access to command line arguments

Definition at line 1852 of file getpot.h.

References argv.

1853 {
1854  return idx<argv.size() ? argv[idx].c_str() : 0;
1855 }
STRING_VECTOR argv
Definition: getpot.h:493
bool GETPOT_NAMESPACE::GetPot::options_contain ( const char *  FlagList) const
inline

flags

Definition at line 2079 of file getpot.h.

References _check_flags(), _get_remaining_string(), argv, and prefix.

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 }
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
Definition: getpot.h:1714
STRING_VECTOR argv
Definition: getpot.h:493
std::string prefix
Definition: getpot.h:486
bool _check_flags(const std::string &Str, const char *FlagList) const
Definition: getpot.h:2133
void GETPOT_NAMESPACE::GetPot::parse_command_line ( const int  argc_,
const char *const *  argv_,
const char *  FieldSeparator = 0x0 
)
inline

Re-initialization methods

Definition at line 782 of file getpot.h.

References _basic_initialization(), _field_separator, and _parse_argument_vector().

Referenced by GetPot().

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 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:131
void _basic_initialization()
Definition: getpot.h:698
std::string _field_separator
Definition: getpot.h:519
void _parse_argument_vector(const STRING_VECTOR &ARGV)
Definition: getpot.h:1107
void GETPOT_NAMESPACE::GetPot::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") 
)
inline

Definition at line 875 of file getpot.h.

References parse_input_stream().

Referenced by _parse_argument_vector(), and GetPot().

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 }
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
void GETPOT_NAMESPACE::GetPot::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") 
)
inline

Definition at line 923 of file getpot.h.

References _basic_initialization(), _comment_end, _comment_start, _field_separator, _parse_argument_vector(), and _read_in_stream().

Referenced by GetPot(), and parse_input_file().

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 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:131
std::string _comment_start
Definition: getpot.h:513
void _basic_initialization()
Definition: getpot.h:698
std::string _field_separator
Definition: getpot.h:519
STRING_VECTOR _read_in_stream(std::istream &istr)
Definition: getpot.h:1210
void _parse_argument_vector(const STRING_VECTOR &ARGV)
Definition: getpot.h:1107
std::string _comment_end
Definition: getpot.h:514
int GETPOT_NAMESPACE::GetPot::print ( std::ostream &  out_stream = std::cout) const
inline

output Print everything

Definition at line 2614 of file getpot.h.

References argv.

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 }
STRING_VECTOR argv
Definition: getpot.h:493
int GETPOT_NAMESPACE::GetPot::print ( const char *  custom_prefix,
std::ostream &  out_stream = std::cout,
unsigned int  skip_count = 1 
) const
inline

Print everything after skipping skip_count arguments, with a custom prefix. skip_count defaults to 1 to handle the common "executable input_file" command line case.

Definition at line 2632 of file getpot.h.

References argv.

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 }
STRING_VECTOR argv
Definition: getpot.h:493
void GETPOT_NAMESPACE::GetPot::reset_cursor ( )
inline

reset cursor to position '1'

Definition at line 1830 of file getpot.h.

References cursor, and search_failed_f.

Referenced by init_multiple_occurrence().

1831 {
1832  search_failed_f = false;
1833  cursor = 0;
1834 }
void GETPOT_NAMESPACE::GetPot::reset_nominus_cursor ( )
inline

nominus arguments

Definition at line 2202 of file getpot.h.

References nominus_cursor.

2203 {
2204  nominus_cursor = -1;
2205 }
bool GETPOT_NAMESPACE::GetPot::search ( const char *  option)
inline

search for a certain option and set cursor to position

Definition at line 1741 of file getpot.h.

References _record_argument_request(), argv, cursor, prefix, search_failed_f, and search_loop_f.

Referenced by follow(), and search().

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 }
void _record_argument_request(const std::string &Arg) const
Definition: getpot.h:2432
STRING_VECTOR argv
Definition: getpot.h:493
std::string prefix
Definition: getpot.h:486
bool GETPOT_NAMESPACE::GetPot::search ( const std::string &  option)
inline

Definition at line 1732 of file getpot.h.

References search().

1733 {
1734  return search(Option.c_str());
1735 }
bool search(const char *option)
Definition: getpot.h:1741
bool GETPOT_NAMESPACE::GetPot::search ( unsigned  No,
const char *  P,
  ... 
)
inline

Definition at line 1784 of file getpot.h.

References _record_argument_request(), and search().

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 }
void _record_argument_request(const std::string &Arg) const
Definition: getpot.h:2432
bool search(const char *option)
Definition: getpot.h:1741
bool GETPOT_NAMESPACE::GetPot::search_failed ( ) const
inline

Definition at line 333 of file getpot.h.

References search_failed_f.

333 { return search_failed_f; }
template<typename T >
void GETPOT_NAMESPACE::GetPot::set ( const char *  VarName,
const T &  Value,
const bool  Requested = true 
)
inline

setting variables i) from outside of GetPot (considering prefix etc.) ii) from inside, use '_set_variable()' below

Definition at line 2497 of file getpot.h.

References _set_variable().

Referenced by set().

2498 {
2499  std::ostringstream string_value;
2500  string_value << Value;
2501  _set_variable(VarName, string_value.str().c_str(), Requested);
2502 }
void _set_variable(const std::string &VarName, const std::string &Value, const bool Requested)
Definition: getpot.h:2478
template<typename T >
void GETPOT_NAMESPACE::GetPot::set ( const std::string &  VarName,
const T &  Value,
const bool  Requested = true 
)
inline

Definition at line 2508 of file getpot.h.

References set().

2509 {
2510  set(VarName.c_str(), Value, Requested);
2511 }
void set(const char *VarName, const T &Value, const bool Requested=true)
Definition: getpot.h:2497
void GETPOT_NAMESPACE::GetPot::set ( const char *  VarName,
const char *  Value,
const bool  Requested = true 
)
inline

Definition at line 2516 of file getpot.h.

References _set_variable().

2517 {
2518  _set_variable(VarName, Value, Requested);
2519 }
void _set_variable(const std::string &VarName, const std::string &Value, const bool Requested)
Definition: getpot.h:2478
void GETPOT_NAMESPACE::GetPot::set ( const std::string &  VarName,
const char *  Value,
const bool  Requested = true 
)
inline

Definition at line 2524 of file getpot.h.

References set().

2525 {
2526  set(VarName.c_str(), Value, Requested);
2527 }
void set(const char *VarName, const T &Value, const bool Requested=true)
Definition: getpot.h:2497
void GETPOT_NAMESPACE::GetPot::set_prefix ( const char *  Prefix)
inline

cursor oriented functions

Definition at line 332 of file getpot.h.

References prefix.

332 { prefix = std::string(Prefix); }
std::string prefix
Definition: getpot.h:486
unsigned GETPOT_NAMESPACE::GetPot::size ( ) const
inline

Definition at line 1881 of file getpot.h.

References argv.

Referenced by _DBE_expand().

1882 {
1883  return getpot_cast_int<unsigned>(argv.size());
1884 }
STRING_VECTOR argv
Definition: getpot.h:493
STRING_VECTOR GETPOT_NAMESPACE::GetPot::unidentified_arguments ( unsigned  Number,
const char *  Known,
  ... 
) const
inline

unidentified flying objects

Definition at line 3372 of file getpot.h.

References unidentified_arguments().

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 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:131
STRING_VECTOR unidentified_arguments() const
Definition: getpot.h:3394
STRING_VECTOR GETPOT_NAMESPACE::GetPot::unidentified_arguments ( const std::set< std::string > &  Knowns) const
inline

Definition at line 3412 of file getpot.h.

References _get_remaining_string(), argv, and prefix.

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 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:131
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
Definition: getpot.h:1714
STRING_VECTOR argv
Definition: getpot.h:493
std::string prefix
Definition: getpot.h:486
STRING_VECTOR GETPOT_NAMESPACE::GetPot::unidentified_arguments ( const std::vector< std::string > &  Knowns) const
inline

Definition at line 3402 of file getpot.h.

References unidentified_arguments().

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 }
STRING_VECTOR unidentified_arguments() const
Definition: getpot.h:3394
STRING_VECTOR GETPOT_NAMESPACE::GetPot::unidentified_arguments ( ) const
inline

Definition at line 3394 of file getpot.h.

References _requested_arguments.

Referenced by unidentified_arguments(), and unidentified_options().

3395 {
3397 }
STRING_VECTOR unidentified_arguments() const
Definition: getpot.h:3394
std::set< std::string > _requested_arguments
Definition: getpot.h:557
std::string GETPOT_NAMESPACE::GetPot::unidentified_flags ( const char *  Known,
int  ArgumentNumber = -1 
) const
inline

Definition at line 3510 of file getpot.h.

References _get_remaining_string(), argv, and prefix.

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 }
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
Definition: getpot.h:1714
STRING_VECTOR argv
Definition: getpot.h:493
std::string prefix
Definition: getpot.h:486
STRING_VECTOR GETPOT_NAMESPACE::GetPot::unidentified_nominuses ( unsigned  Number,
const char *  Known,
  ... 
) const
inline

Definition at line 3707 of file getpot.h.

References unidentified_nominuses().

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 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:131
STRING_VECTOR unidentified_nominuses() const
Definition: getpot.h:3733
STRING_VECTOR GETPOT_NAMESPACE::GetPot::unidentified_nominuses ( const std::set< std::string > &  Knowns) const
inline

Definition at line 3758 of file getpot.h.

References _get_remaining_string(), argv, and prefix.

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 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:131
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
Definition: getpot.h:1714
STRING_VECTOR argv
Definition: getpot.h:493
std::string prefix
Definition: getpot.h:486
STRING_VECTOR GETPOT_NAMESPACE::GetPot::unidentified_nominuses ( const std::vector< std::string > &  Knowns) const
inline

Definition at line 3748 of file getpot.h.

References unidentified_nominuses().

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 }
STRING_VECTOR unidentified_nominuses() const
Definition: getpot.h:3733
STRING_VECTOR GETPOT_NAMESPACE::GetPot::unidentified_nominuses ( ) const
inline

Definition at line 3733 of file getpot.h.

References _requested_arguments.

Referenced by unidentified_nominuses().

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 }
STRING_VECTOR unidentified_nominuses() const
Definition: getpot.h:3733
std::set< std::string > _requested_arguments
Definition: getpot.h:557
STRING_VECTOR GETPOT_NAMESPACE::GetPot::unidentified_options ( unsigned  Number,
const char *  Known,
  ... 
) const
inline

Definition at line 3434 of file getpot.h.

References unidentified_options().

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 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:131
STRING_VECTOR unidentified_options() const
Definition: getpot.h:3456
STRING_VECTOR GETPOT_NAMESPACE::GetPot::unidentified_options ( const std::set< std::string > &  Knowns) const
inline

Definition at line 3480 of file getpot.h.

References _get_remaining_string(), argv, and prefix.

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 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:131
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
Definition: getpot.h:1714
STRING_VECTOR argv
Definition: getpot.h:493
std::string prefix
Definition: getpot.h:486
STRING_VECTOR GETPOT_NAMESPACE::GetPot::unidentified_options ( const std::vector< std::string > &  Knowns) const
inline

Definition at line 3470 of file getpot.h.

References unidentified_options().

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 }
STRING_VECTOR unidentified_options() const
Definition: getpot.h:3456
STRING_VECTOR GETPOT_NAMESPACE::GetPot::unidentified_options ( ) const
inline

Definition at line 3456 of file getpot.h.

References _requested_arguments, and unidentified_arguments().

Referenced by unidentified_options().

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 }
STRING_VECTOR unidentified_arguments() const
Definition: getpot.h:3394
std::set< std::string > _requested_arguments
Definition: getpot.h:557
STRING_VECTOR GETPOT_NAMESPACE::GetPot::unidentified_sections ( unsigned  Number,
const char *  Known,
  ... 
) const
inline

Definition at line 3635 of file getpot.h.

References unidentified_sections().

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 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:131
STRING_VECTOR unidentified_sections() const
Definition: getpot.h:3667
STRING_VECTOR GETPOT_NAMESPACE::GetPot::unidentified_sections ( const std::set< std::string > &  Knowns) const
inline

Definition at line 3685 of file getpot.h.

References _get_remaining_string(), prefix, and section_list.

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 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:131
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
Definition: getpot.h:1714
std::string prefix
Definition: getpot.h:486
STRING_VECTOR section_list
Definition: getpot.h:488
STRING_VECTOR GETPOT_NAMESPACE::GetPot::unidentified_sections ( const std::vector< std::string > &  Knowns) const
inline

Definition at line 3675 of file getpot.h.

References unidentified_sections().

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 }
STRING_VECTOR unidentified_sections() const
Definition: getpot.h:3667
STRING_VECTOR GETPOT_NAMESPACE::GetPot::unidentified_sections ( ) const
inline

Definition at line 3667 of file getpot.h.

References _requested_sections.

Referenced by unidentified_sections().

3668 {
3670 }
STRING_VECTOR unidentified_sections() const
Definition: getpot.h:3667
std::set< std::string > _requested_sections
Definition: getpot.h:559
STRING_VECTOR GETPOT_NAMESPACE::GetPot::unidentified_variables ( unsigned  Number,
const char *  Known,
  ... 
) const
inline

Definition at line 3574 of file getpot.h.

References unidentified_variables().

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 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:131
STRING_VECTOR unidentified_variables() const
Definition: getpot.h:3627
STRING_VECTOR GETPOT_NAMESPACE::GetPot::unidentified_variables ( const std::set< std::string > &  Knowns) const
inline

Definition at line 3606 of file getpot.h.

References _get_remaining_string(), prefix, and variables.

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 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:131
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
Definition: getpot.h:1714
std::string prefix
Definition: getpot.h:486
std::vector< variable > variables
Definition: getpot.h:508
STRING_VECTOR GETPOT_NAMESPACE::GetPot::unidentified_variables ( const std::vector< std::string > &  Knowns) const
inline

Definition at line 3596 of file getpot.h.

References unidentified_variables().

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 }
STRING_VECTOR unidentified_variables() const
Definition: getpot.h:3627
STRING_VECTOR GETPOT_NAMESPACE::GetPot::unidentified_variables ( ) const
inline

Definition at line 3627 of file getpot.h.

References _requested_variables.

Referenced by unidentified_variables().

3628 {
3630 }
STRING_VECTOR unidentified_variables() const
Definition: getpot.h:3627
std::set< std::string > _requested_variables
Definition: getpot.h:558
unsigned GETPOT_NAMESPACE::GetPot::vector_variable_size ( const char *  VarName) const
inline

Definition at line 2532 of file getpot.h.

References _request_variable(), and GETPOT_NAMESPACE::GetPot::variable::value.

Referenced by vector_variable_size().

2533 {
2534  const variable* sv = _request_variable(VarName);
2535  if (sv == 0)
2536  return 0;
2537  return (unsigned)(sv->value.size());
2538 }
const variable * _request_variable(const char *) const
Definition: getpot.h:2599
unsigned GETPOT_NAMESPACE::GetPot::vector_variable_size ( const std::string &  VarName) const
inline

Definition at line 2543 of file getpot.h.

References vector_variable_size().

2544 {
2545  return vector_variable_size(VarName.c_str());
2546 }
unsigned vector_variable_size(const char *VarName) const
Definition: getpot.h:2532

Member Data Documentation

std::string GETPOT_NAMESPACE::GetPot::_comment_end
private
std::string GETPOT_NAMESPACE::GetPot::_comment_start
private
std::string GETPOT_NAMESPACE::GetPot::_field_separator
private

field separator (separating elements of a vector)

Definition at line 519 of file getpot.h.

Referenced by _basic_initialization(), _parse_argument_vector(), _set_variable(), operator=(), parse_command_line(), and parse_input_stream().

std::set<const char*, ltstr> GETPOT_NAMESPACE::GetPot::_internal_string_container
mutableprivate

some functions return a char pointer to a string created on the fly. this container makes them 'available' until the getpot object is destroyed. user codes are recommended to instead request std::string values. We use char* here because c_str() results are only guaranteed to remain valid until a non-const string method is called

Definition at line 545 of file getpot.h.

Referenced by _internal_managed_copy(), GetPot(), operator=(), and ~GetPot().

std::set<std::string> GETPOT_NAMESPACE::GetPot::_requested_arguments
mutableprivate

keeping track about arguments that are requested, so that the UFO detection can be simplified

Definition at line 557 of file getpot.h.

Referenced by _parse_argument_vector(), _record_argument_request(), absorb(), clear_requests(), get_requested_arguments(), operator=(), unidentified_arguments(), unidentified_nominuses(), and unidentified_options().

std::set<std::string> GETPOT_NAMESPACE::GetPot::_requested_sections
mutableprivate
std::set<std::string> GETPOT_NAMESPACE::GetPot::_requested_variables
mutableprivate
unsigned GETPOT_NAMESPACE::GetPot::cursor
private
GETPOT_NAMESPACE::GetPot::GETPOT_MUTEX_DECLARE
private

we have some mutable non-thread-safe members, but we want to be able to call const member functions from multiple threads at once, so we'll wrap access to mutable objects in a mutex.

Definition at line 535 of file getpot.h.

std::vector<unsigned> GETPOT_NAMESPACE::GetPot::idx_nominus
private
int GETPOT_NAMESPACE::GetPot::nominus_cursor
private

nominus vector

Definition at line 502 of file getpot.h.

Referenced by _basic_initialization(), next_nominus(), next_nominus_string(), operator=(), and reset_nominus_cursor().

std::set<std::string> GETPOT_NAMESPACE::GetPot::overridden_vars
private

Definition at line 497 of file getpot.h.

Referenced by _set_variable(), get_overridden_variables(), and operator=().

bool GETPOT_NAMESPACE::GetPot::request_recording_f
private
bool GETPOT_NAMESPACE::GetPot::search_failed_f
private
bool GETPOT_NAMESPACE::GetPot::search_loop_f
private
std::string GETPOT_NAMESPACE::GetPot::section
private
STRING_VECTOR GETPOT_NAMESPACE::GetPot::section_list
private
std::vector<variable> GETPOT_NAMESPACE::GetPot::variables
private

variables (arguments of the form "variable=value")

Definition at line 508 of file getpot.h.

Referenced by _find_variable(), _set_variable(), absorb(), get_variable_names(), operator=(), and unidentified_variables().


The documentation for this class was generated from the following file:

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