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
 
STRING_VECTOR get_subsection_names (const std::string &section_name) 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 153 of file getpot.h.

Constructor & Destructor Documentation

GetPot::GetPot ( )
inline

constructors, destructor, assignment operator

Definition at line 743 of file getpot.h.

References _basic_initialization().

743  :
744  prefix(),
745  section(),
746  section_list(),
747  argv(),
748  cursor(),
749  search_loop_f(),
750  search_failed_f(),
751  nominus_cursor(),
752  idx_nominus(),
753  variables(),
754  _comment_start(),
755  _comment_end(),
757 #if !defined(GETPOT_DISABLE_MUTEX)
758  _getpot_mtx(),
759 #endif
765 {
767 }
std::set< std::string > _requested_arguments
Definition: getpot.h:579
std::vector< unsigned > idx_nominus
Definition: getpot.h:525
std::string prefix
Definition: getpot.h:508
bool search_failed_f
Definition: getpot.h:518
STRING_VECTOR section_list
Definition: getpot.h:510
void _basic_initialization()
Definition: getpot.h:720
bool request_recording_f
Definition: getpot.h:583
bool search_loop_f
Definition: getpot.h:517
std::set< std::string > _requested_sections
Definition: getpot.h:581
std::set< std::string > _requested_variables
Definition: getpot.h:580
unsigned cursor
Definition: getpot.h:516
int nominus_cursor
Definition: getpot.h:524
std::string section
Definition: getpot.h:509
std::string _comment_end
Definition: getpot.h:536
std::string _field_separator
Definition: getpot.h:541
std::vector< variable > variables
Definition: getpot.h:530
STRING_VECTOR argv
Definition: getpot.h:515
std::string _comment_start
Definition: getpot.h:535
std::set< const char *, ltstr > _internal_string_container
Definition: getpot.h:567
GetPot::GetPot ( const GetPot Other)
inline

Definition at line 976 of file getpot.h.

References _internal_string_container.

976  :
977  prefix(Other.prefix),
978  section(Other.section),
979  section_list(Other.section_list),
980  argv(Other.argv),
981  cursor(Other.cursor),
984  overridden_vars(),
986  idx_nominus(Other.idx_nominus),
987  variables(Other.variables),
989  _comment_end(Other._comment_end),
991  // #if !defined(GETPOT_DISABLE_MUTEX)
992  // _getpot_mtx(Other._getpot_mtx),
993  // #endif
999 {
1000  std::set<const char*,ltstr>::const_iterator it =
1001  Other._internal_string_container.begin();
1002 
1003  const std::set<const char*,ltstr>::const_iterator end =
1004  Other._internal_string_container.end();
1005 
1006  for (; it != end; ++it)
1007  {
1008  const char* otherstr = *it;
1009  char* newcopy = new char[strlen(otherstr)+1];
1010  strncpy(newcopy, otherstr, strlen(otherstr)+1);
1011  this->_internal_string_container.insert(newcopy);
1012  }
1013 }
std::set< std::string > _requested_arguments
Definition: getpot.h:579
std::vector< unsigned > idx_nominus
Definition: getpot.h:525
std::string prefix
Definition: getpot.h:508
bool search_failed_f
Definition: getpot.h:518
STRING_VECTOR section_list
Definition: getpot.h:510
bool request_recording_f
Definition: getpot.h:583
bool search_loop_f
Definition: getpot.h:517
std::set< std::string > _requested_sections
Definition: getpot.h:581
std::set< std::string > _requested_variables
Definition: getpot.h:580
unsigned cursor
Definition: getpot.h:516
int nominus_cursor
Definition: getpot.h:524
std::string section
Definition: getpot.h:509
std::string _comment_end
Definition: getpot.h:536
std::string _field_separator
Definition: getpot.h:541
std::vector< variable > variables
Definition: getpot.h:530
STRING_VECTOR argv
Definition: getpot.h:515
std::set< std::string > overridden_vars
Definition: getpot.h:519
std::string _comment_start
Definition: getpot.h:535
std::set< const char *, ltstr > _internal_string_container
Definition: getpot.h:567
GetPot::GetPot ( const int  argc_,
const char *const *  argv_,
const char *  FieldSeparator = 0x0 
)
inline

Definition at line 772 of file getpot.h.

References parse_command_line().

773  :
774  // leave 'char**' non-const to honor less capable compilers ...
775  prefix(),
776  section(),
777  section_list(),
778  argv(),
779  cursor(),
780  search_loop_f(),
781  search_failed_f(),
782  nominus_cursor(),
783  idx_nominus(),
784  variables(),
785  _comment_start(),
786  _comment_end(),
788 #if !defined(GETPOT_DISABLE_MUTEX)
789  _getpot_mtx(),
790 #endif
796 {
797  this->parse_command_line(argc_, argv_, FieldSeparator);
798 }
std::set< std::string > _requested_arguments
Definition: getpot.h:579
void parse_command_line(const int argc_, const char *const *argv_, const char *FieldSeparator=0x0)
Definition: getpot.h:804
std::vector< unsigned > idx_nominus
Definition: getpot.h:525
std::string prefix
Definition: getpot.h:508
bool search_failed_f
Definition: getpot.h:518
STRING_VECTOR section_list
Definition: getpot.h:510
bool request_recording_f
Definition: getpot.h:583
bool search_loop_f
Definition: getpot.h:517
std::set< std::string > _requested_sections
Definition: getpot.h:581
std::set< std::string > _requested_variables
Definition: getpot.h:580
unsigned cursor
Definition: getpot.h:516
int nominus_cursor
Definition: getpot.h:524
std::string section
Definition: getpot.h:509
std::string _comment_end
Definition: getpot.h:536
std::string _field_separator
Definition: getpot.h:541
std::vector< variable > variables
Definition: getpot.h:530
STRING_VECTOR argv
Definition: getpot.h:515
std::string _comment_start
Definition: getpot.h:535
std::set< const char *, ltstr > _internal_string_container
Definition: getpot.h:567
GetPot::GetPot ( const char *  FileName,
const char *  CommentStart = 0x0,
const char *  CommentEnd = 0x0,
const char *  FieldSeparator = 0x0 
)
inline

Definition at line 833 of file getpot.h.

References parse_input_file().

835  :
836  prefix(),
837  section(),
838  section_list(),
839  argv(),
840  cursor(),
841  search_loop_f(),
842  search_failed_f(),
843  nominus_cursor(),
844  idx_nominus(),
845  variables(),
846  _comment_start(),
847  _comment_end(),
849 #if !defined(GETPOT_DISABLE_MUTEX)
850  _getpot_mtx(),
851 #endif
857 {
858  const std::string& StrCommentStart = CommentStart ? CommentStart : std::string("#");
859  const std::string& StrCommentEnd = CommentEnd ? CommentEnd : std::string("\n");
860  const std::string& StrFieldSeparator = FieldSeparator ? FieldSeparator : std::string(" \t\n");
861  this->parse_input_file(FileName, StrCommentStart, StrCommentEnd, StrFieldSeparator);
862 }
void parse_input_file(const std::string &FileName, const std::string &CommentStart=std::string("#"), const std::string &CommentEnd=std::string("\n"), const std::string &FieldSeparator=std::string(" \t\n"))
Definition: getpot.h:897
std::set< std::string > _requested_arguments
Definition: getpot.h:579
std::vector< unsigned > idx_nominus
Definition: getpot.h:525
std::string prefix
Definition: getpot.h:508
bool search_failed_f
Definition: getpot.h:518
STRING_VECTOR section_list
Definition: getpot.h:510
bool request_recording_f
Definition: getpot.h:583
bool search_loop_f
Definition: getpot.h:517
std::set< std::string > _requested_sections
Definition: getpot.h:581
std::set< std::string > _requested_variables
Definition: getpot.h:580
unsigned cursor
Definition: getpot.h:516
int nominus_cursor
Definition: getpot.h:524
std::string section
Definition: getpot.h:509
std::string _comment_end
Definition: getpot.h:536
std::string _field_separator
Definition: getpot.h:541
std::vector< variable > variables
Definition: getpot.h:530
STRING_VECTOR argv
Definition: getpot.h:515
std::string _comment_start
Definition: getpot.h:535
std::set< const char *, ltstr > _internal_string_container
Definition: getpot.h:567
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 867 of file getpot.h.

References parse_input_file().

870  :
871  prefix(),
872  section(),
873  section_list(),
874  argv(),
875  cursor(),
876  search_loop_f(),
877  search_failed_f(),
878  nominus_cursor(),
879  idx_nominus(),
880  variables(),
881  _comment_start(),
882  _comment_end(),
884 #if !defined(GETPOT_DISABLE_MUTEX)
885  _getpot_mtx(),
886 #endif
892 {
893  this->parse_input_file(FileName, CommentStart, CommentEnd, FieldSeparator);
894 }
void parse_input_file(const std::string &FileName, const std::string &CommentStart=std::string("#"), const std::string &CommentEnd=std::string("\n"), const std::string &FieldSeparator=std::string(" \t\n"))
Definition: getpot.h:897
std::set< std::string > _requested_arguments
Definition: getpot.h:579
std::vector< unsigned > idx_nominus
Definition: getpot.h:525
std::string prefix
Definition: getpot.h:508
bool search_failed_f
Definition: getpot.h:518
STRING_VECTOR section_list
Definition: getpot.h:510
bool request_recording_f
Definition: getpot.h:583
bool search_loop_f
Definition: getpot.h:517
std::set< std::string > _requested_sections
Definition: getpot.h:581
std::set< std::string > _requested_variables
Definition: getpot.h:580
unsigned cursor
Definition: getpot.h:516
int nominus_cursor
Definition: getpot.h:524
std::string section
Definition: getpot.h:509
std::string _comment_end
Definition: getpot.h:536
std::string _field_separator
Definition: getpot.h:541
std::vector< variable > variables
Definition: getpot.h:530
STRING_VECTOR argv
Definition: getpot.h:515
std::string _comment_start
Definition: getpot.h:535
std::set< const char *, ltstr > _internal_string_container
Definition: getpot.h:567
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 912 of file getpot.h.

References parse_input_stream().

915  :
916  prefix(),
917  section(),
918  section_list(),
919  argv(),
920  cursor(),
921  search_loop_f(),
922  search_failed_f(),
923  nominus_cursor(),
924  idx_nominus(),
925  variables(),
926  _comment_start(),
927  _comment_end(),
929 #if !defined(GETPOT_DISABLE_MUTEX)
930  _getpot_mtx(),
931 #endif
937 {
938  this->parse_input_stream(FileStream,
939  std::string("ParsedFromStream"),// We don't have a filename here
940  CommentStart, CommentEnd, FieldSeparator);
941 }
std::set< std::string > _requested_arguments
Definition: getpot.h:579
std::vector< unsigned > idx_nominus
Definition: getpot.h:525
std::string prefix
Definition: getpot.h:508
bool search_failed_f
Definition: getpot.h:518
STRING_VECTOR section_list
Definition: getpot.h:510
bool request_recording_f
Definition: getpot.h:583
bool search_loop_f
Definition: getpot.h:517
std::set< std::string > _requested_sections
Definition: getpot.h:581
std::set< std::string > _requested_variables
Definition: getpot.h:580
void parse_input_stream(std::istream &FileStream, const std::string &FileName=std::string("ParsedFromStream"), const std::string &CommentStart=std::string("#"), const std::string &CommentEnd=std::string("\n"), const std::string &FieldSeparator=std::string(" \t\n"))
Definition: getpot.h:945
unsigned cursor
Definition: getpot.h:516
int nominus_cursor
Definition: getpot.h:524
std::string section
Definition: getpot.h:509
std::string _comment_end
Definition: getpot.h:536
std::string _field_separator
Definition: getpot.h:541
std::vector< variable > variables
Definition: getpot.h:530
STRING_VECTOR argv
Definition: getpot.h:515
std::string _comment_start
Definition: getpot.h:535
std::set< const char *, ltstr > _internal_string_container
Definition: getpot.h:567
GetPot::~GetPot ( )
inline

Definition at line 1018 of file getpot.h.

References _internal_string_container.

1019 {
1020  // may be some return strings had to be created, delete now !
1021  std::set<const char*, ltstr>::const_iterator it = _internal_string_container.begin();
1022  const std::set<const char*, ltstr>::const_iterator end = _internal_string_container.end();
1023  for (; it != end; ++it)
1024  delete [] *it;
1025 }
std::set< const char *, ltstr > _internal_string_container
Definition: getpot.h:567

Member Function Documentation

void GetPot::_basic_initialization ( )
inlineprivate

Definition at line 720 of file getpot.h.

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

721 {
722  cursor = 0;
723  nominus_cursor = -1;
724  search_failed_f = true;
725  search_loop_f = true;
726  prefix = "";
727  section = "";
728 
729  // automatic request recording for later ufo detection
730  request_recording_f = true;
731 
732  // comment start and end strings
733  _comment_start = std::string("#");
734  _comment_end = std::string("\n");
735 
736  // default: separate vector elements by whitespaces
737  _field_separator = " \t\n";
738 }
std::string prefix
Definition: getpot.h:508
bool search_failed_f
Definition: getpot.h:518
bool request_recording_f
Definition: getpot.h:583
bool search_loop_f
Definition: getpot.h:517
unsigned cursor
Definition: getpot.h:516
int nominus_cursor
Definition: getpot.h:524
std::string section
Definition: getpot.h:509
std::string _comment_end
Definition: getpot.h:536
std::string _field_separator
Definition: getpot.h:541
std::string _comment_start
Definition: getpot.h:535
bool GetPot::_check_flags ( const std::string &  Str,
const char *  FlagList 
) const
inlineprivate

support search for flags in a specific argument

Definition at line 2155 of file getpot.h.

Referenced by argument_contains(), and options_contain().

2156 {
2157  for (const char* p=FlagList; *p != '\0' ; p++)
2158  if (Str.find(*p) != std::string::npos)
2159  return true; // found something
2160  return false;
2161 }
template<typename T >
static std::string GetPot::_convert_from_type ( const T &  Value)
inlinestaticprivate

Definition at line 690 of file getpot.h.

Referenced by _DBE_expand().

691  {
692  std::ostringstream out_string;
693  out_string << Value;
694  return out_string.str();
695  }
template<typename T >
T GetPot::_convert_to_type ( const std::string &  String,
const T &  Default 
) const
inlineprivate

type conversion if possible

Definition at line 1567 of file getpot.h.

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

1568 {
1569  std::istringstream in_string(String);
1570  T retval;
1571  in_string >> retval;
1572  if (in_string.fail())
1573  retval = Default;
1574  return retval;
1575 }
std::string GetPot::_convert_to_type ( const std::string &  String,
const char *  Default 
) const
inlineprivate

Definition at line 1591 of file getpot.h.

1592 {
1593  return String;
1594 }
template<>
std::string GetPot::_convert_to_type ( const std::string &  String,
const std::string &   
) const
inline

Definition at line 1582 of file getpot.h.

1583 {
1584  return String;
1585 }
template<>
bool GetPot::_convert_to_type ( const std::string &  String,
const bool &  Default 
) const
inlineprivate

Definition at line 1601 of file getpot.h.

1602 {
1603  std::string newstring(String);
1604  //std::transform(newstring.begin(), newstring.end(), newstring.begin(), std::toupper);
1605  for (unsigned int i=0; i<newstring.length(); ++i)
1606  newstring[i] = getpot_cast_int<char>(toupper(newstring[i]));
1607 
1608  // "true"/"True"/"TRUE" should work
1609  if (newstring.find("TRUE")!=std::string::npos)
1610  return true;
1611 
1612  if (newstring.find("FALSE")!=std::string::npos)
1613  return false;
1614 
1615  // And if we don't find that, let's search for an integer and use C unsigned
1616  // int->bool conversion before giving up; i.e. a user could specify "0" for
1617  // false or "1" for true
1618  std::istringstream in_string(String);
1619  unsigned int retval;
1620  in_string >> retval;
1621  if (in_string.fail())
1622  return Default;
1623 
1624  return retval;
1625 }
template<typename T >
T GetPot::_convert_to_type_no_default ( const char *  VarName,
const std::string &  String,
const T &  Default 
) const
inlineprivate

Definition at line 1632 of file getpot.h.

References getpot_cerr, getpot_error, and libMesh::Quality::name().

Referenced by get_value_no_default().

1633 {
1634  std::istringstream in_string(String);
1635  T retval;
1636  in_string >> retval;
1637  if (in_string.fail())
1638  {
1639  getpot_cerr <<"ERROR: Input value for variable "<<VarName<<" is of the wrong type."<<std::endl;
1640  getpot_cerr <<" value = "<<String<<" expected type = "<<typeid(T).name()<<std::endl;
1641  getpot_error();
1642  }
1643  return retval;
1644 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
#define getpot_error()
Definition: getpot.h:78
#define getpot_cerr
Definition: getpot.h:77
std::string GetPot::_convert_to_type_no_default ( const char *  VarName,
const std::string &  String,
const char *  Default 
) const
inlineprivate

Definition at line 1660 of file getpot.h.

1661 {
1662  return String;
1663 }
template<>
std::string GetPot::_convert_to_type_no_default ( const char *  ,
const std::string &  String,
const std::string &   
) const
inline

Definition at line 1651 of file getpot.h.

1652 {
1653  return String;
1654 }
template<>
bool GetPot::_convert_to_type_no_default ( const char *  VarName,
const std::string &  String,
const bool &   
) const
inlineprivate

Definition at line 1670 of file getpot.h.

References getpot_cerr, getpot_error, and libMesh::Quality::name().

1671 {
1672  std::string newstring(String);
1673  //std::transform(newstring.begin(), newstring.end(), newstring.begin(), std::toupper);
1674  for (unsigned int i=0; i<newstring.length(); ++i)
1675  {
1676  newstring[i]=getpot_cast_int<char>(toupper(newstring[i]));
1677  }
1678 
1679  // "true"/"True"/"TRUE" should work
1680  if (newstring.find("TRUE")!=std::string::npos)
1681  return true;
1682 
1683  if (newstring.find("FALSE")!=std::string::npos)
1684  return false;
1685 
1686  // And if we don't find that, let's search for an integer and use C unsigned
1687  // int->bool conversion before giving up; i.e. a user could specify "0" for
1688  // false or "1" for true
1689  std::istringstream in_string(String);
1690  unsigned int retval;
1691  in_string >> retval;
1692  if (in_string.fail())
1693  {
1694  getpot_cerr <<"ERROR: Input value for variable "<<VarName<<" is of the wrong type."<<std::endl;
1695  getpot_cerr <<" value = "<<String<<" expected type = "<<typeid(bool).name()<<std::endl;
1696  getpot_error();
1697  }
1698 
1699  return retval;
1700 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
#define getpot_error()
Definition: getpot.h:78
#define getpot_cerr
Definition: getpot.h:77
std::string GetPot::_DBE_expand ( const std::string &  str)
inlineprivate

Definition at line 2926 of file getpot.h.

References _convert_from_type(), _convert_to_type(), _DBE_get_expr_list(), _DBE_get_variable(), getpot_cerr, getpot_error, std::max(), std::min(), GetPot::variable::name, GetPot::variable::original, libMesh::Utility::pow(), and size().

Referenced by _DBE_expand_string(), and _DBE_get_expr_list().

2927 {
2928  // ${: } pure text
2929  if (expr[0] == ':')
2930  return expr.substr(1);
2931 
2932  // ${& expr expr ... } text concatination
2933  else if (expr[0] == '&')
2934  {
2935  const STRING_VECTOR A = _DBE_get_expr_list(expr.substr(1), 1);
2936 
2937  STRING_VECTOR::const_iterator it = A.begin();
2938  std::string result = *it++;
2939  for (; it != A.end(); ++it) result += *it;
2940 
2941  return result;
2942  }
2943 
2944  // ${<-> expr expr expr} text replacement
2945  else if (expr.length() >= 3 && expr.substr(0, 3) == "<->")
2946  {
2947  STRING_VECTOR A = _DBE_get_expr_list(expr.substr(3), 3);
2948  size_t tmp = 0;
2949  const size_t L = A[1].length();
2950 
2951  while ((tmp = A[0].find(A[1])) != std::string::npos)
2952  A[0].replace(tmp, L, A[2]);
2953 
2954  return A[0];
2955  }
2956 
2957  // ${=func [expr...] } function evaluation
2958  else if (expr.length() >= 2 &&
2959  expr.substr(0, 1) == "=" &&
2960  expr.substr(0, 2) != "==")
2961  {
2962  size_t funcnamestart = expr.find_first_not_of(" \t", 1);
2963  if (funcnamestart != std::string::npos)
2964  {
2965  size_t funcnameend = expr.find_first_of(" \t",funcnamestart);
2966  std::string funcname = expr.substr(funcnamestart,
2967  funcnameend-funcnamestart);
2968  if (funcname == "log")
2969  {
2970  STRING_VECTOR A =
2971  _DBE_get_expr_list(expr.substr(funcnameend), 1);
2972  double arg = _convert_to_type(A[0], 0.0);
2973  return _convert_from_type(std::log(arg));
2974  }
2975  else if (funcname == "log10")
2976  {
2977  STRING_VECTOR A =
2978  _DBE_get_expr_list(expr.substr(funcnameend), 1);
2979  double arg = _convert_to_type(A[0], 0.0);
2980  return _convert_from_type(std::log10(arg));
2981  }
2982  else if (funcname == "exp")
2983  {
2984  STRING_VECTOR A =
2985  _DBE_get_expr_list(expr.substr(funcnameend), 1);
2986  double arg = _convert_to_type(A[0], 0.0);
2987  return _convert_from_type(std::exp(arg));
2988  }
2989  else if (funcname == "sin")
2990  {
2991  STRING_VECTOR A =
2992  _DBE_get_expr_list(expr.substr(funcnameend), 1);
2993  double arg = _convert_to_type(A[0], 0.0);
2994  return _convert_from_type(std::sin(arg));
2995  }
2996  else if (funcname == "cos")
2997  {
2998  STRING_VECTOR A =
2999  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3000  double arg = _convert_to_type(A[0], 0.0);
3001  return _convert_from_type(std::cos(arg));
3002  }
3003  else if (funcname == "tan")
3004  {
3005  STRING_VECTOR A =
3006  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3007  double arg = _convert_to_type(A[0], 0.0);
3008  return _convert_from_type(std::tan(arg));
3009  }
3010  else if (funcname == "asin")
3011  {
3012  STRING_VECTOR A =
3013  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3014  double arg = _convert_to_type(A[0], 0.0);
3015  return _convert_from_type(std::asin(arg));
3016  }
3017  else if (funcname == "acos")
3018  {
3019  STRING_VECTOR A =
3020  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3021  double arg = _convert_to_type(A[0], 0.0);
3022  return _convert_from_type(std::acos(arg));
3023  }
3024  else if (funcname == "atan")
3025  {
3026  STRING_VECTOR A =
3027  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3028  double arg = _convert_to_type(A[0], 0.0);
3029  return _convert_from_type(std::atan(arg));
3030  }
3031  else if (funcname == "atan2")
3032  {
3033  STRING_VECTOR A =
3034  _DBE_get_expr_list(expr.substr(funcnameend), 2);
3035  double arg1 = _convert_to_type(A[0], 0.0);
3036  double arg2 = _convert_to_type(A[1], 0.0);
3037  return _convert_from_type(std::atan2(arg1, arg2));
3038  }
3039  else if (funcname == "sinh")
3040  {
3041  STRING_VECTOR A =
3042  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3043  double arg = _convert_to_type(A[0], 0.0);
3044  return _convert_from_type(std::sinh(arg));
3045  }
3046  else if (funcname == "cosh")
3047  {
3048  STRING_VECTOR A =
3049  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3050  double arg = _convert_to_type(A[0], 0.0);
3051  return _convert_from_type(std::cosh(arg));
3052  }
3053  else if (funcname == "tanh")
3054  {
3055  STRING_VECTOR A =
3056  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3057  double arg = _convert_to_type(A[0], 0.0);
3058  return _convert_from_type(std::tanh(arg));
3059  }
3060 #ifdef HAVE_INVERSE_HYPERBOLIC_SINE
3061  else if (funcname == "asinh")
3062  {
3063  STRING_VECTOR A =
3064  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3065  double arg = _convert_to_type(A[0], 0.0);
3066  return _convert_from_type(std::asinh(arg));
3067  }
3068 #endif
3069 #ifdef HAVE_INVERSE_HYPERBOLIC_COSINE
3070  else if (funcname == "acosh")
3071  {
3072  STRING_VECTOR A =
3073  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3074  double arg = _convert_to_type(A[0], 0.0);
3075  return _convert_from_type(std::acosh(arg));
3076  }
3077 #endif
3078 #ifdef HAVE_INVERSE_HYPERBOLIC_TANGENT
3079  else if (funcname == "atanh")
3080  {
3081  STRING_VECTOR A =
3082  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3083  double arg = _convert_to_type(A[0], 0.0);
3084  return _convert_from_type(std::atanh(arg));
3085  }
3086 #endif
3087  else if (funcname == "sqrt")
3088  {
3089  STRING_VECTOR A =
3090  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3091  double arg = _convert_to_type(A[0], 0.0);
3092  return _convert_from_type(std::sqrt(arg));
3093  }
3094  else if (funcname == "abs")
3095  {
3096  STRING_VECTOR A =
3097  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3098  double arg = _convert_to_type(A[0], 0.0);
3099  return _convert_from_type(std::abs(arg));
3100  }
3101  else if (funcname == "max")
3102  {
3103  STRING_VECTOR A =
3104  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3105  STRING_VECTOR::const_iterator it = A.begin();
3106  double result = _convert_to_type(*it++, 0.0);
3107  for (; it != A.end(); ++it)
3108  result = std::max(result, _convert_to_type(*it, 0.0));
3109  return _convert_from_type(result);
3110  }
3111  else if (funcname == "min")
3112  {
3113  STRING_VECTOR A =
3114  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3115  STRING_VECTOR::const_iterator it = A.begin();
3116  double result = _convert_to_type(*it++, 0.0);
3117  for (; it != A.end(); ++it)
3118  result = std::min(result, _convert_to_type(*it, 0.0));
3119  return _convert_from_type(result);
3120  }
3121  else if (funcname == "ceil")
3122  {
3123  STRING_VECTOR A =
3124  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3125  double arg = _convert_to_type(A[0], 0.0);
3126  return _convert_from_type(std::ceil(arg));
3127  }
3128  else if (funcname == "floor")
3129  {
3130  STRING_VECTOR A =
3131  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3132  double arg = _convert_to_type(A[0], 0.0);
3133  return _convert_from_type(std::floor(arg));
3134  }
3135  else if (funcname == "fmod")
3136  {
3137  STRING_VECTOR A =
3138  _DBE_get_expr_list(expr.substr(funcnameend), 2);
3139  double arg1 = _convert_to_type(A[0], 0.0);
3140  double arg2 = _convert_to_type(A[1], 0.0);
3141  return _convert_from_type(std::fmod(arg1, arg2));
3142  }
3143  else if (funcname == "srand")
3144  {
3145  STRING_VECTOR A =
3146  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3147  unsigned int arg = _convert_to_type(A[0], 0u);
3148  std::srand(arg);
3149  return A[0];
3150  }
3151  // ${=rand range} with default range==RAND_MAX
3152  else if (funcname == "rand")
3153  {
3154  if (funcnameend >= expr.length() ||
3155  expr.find_first_not_of(" \t", funcnameend) == std::string::npos)
3156  return _convert_from_type(std::rand());
3157 
3158  STRING_VECTOR A =
3159  _DBE_get_expr_list(expr.substr(funcnameend), 1);
3160  unsigned int range = _convert_to_type(A[0],0u);
3161  if (!range)
3162  return _convert_from_type(0);
3163  const unsigned int x = (RAND_MAX + 1u) / range;
3164  const unsigned int y = x * range;
3165  unsigned int returnval;
3166  do
3167  {
3168  returnval = rand();
3169  } while (returnval >= y);
3170  return _convert_from_type(returnval / x);
3171  }
3172  else if (funcname == "time")
3173  return _convert_from_type(std::time(NULL));
3174  else
3175  {
3176  getpot_cerr << "ERROR: unrecognized function "
3177  << funcname << std::endl;
3178  getpot_error();
3179  }
3180  }
3181  }
3182 
3183  // ${+ ...}, ${- ...}, ${* ...}, ${/ ...} expressions
3184  else if (expr[0] == '+')
3185  {
3186  STRING_VECTOR A = _DBE_get_expr_list(expr.substr(1), 2);
3187  STRING_VECTOR::const_iterator it = A.begin();
3188  double result = _convert_to_type(*it++, 0.0);
3189  for (; it != A.end(); ++it)
3190  result += _convert_to_type(*it, 0.0);
3191 
3192  return _convert_from_type(result);
3193  }
3194  else if (expr[0] == '-')
3195  {
3196  STRING_VECTOR A = _DBE_get_expr_list(expr.substr(1), 2);
3197  STRING_VECTOR::const_iterator it = A.begin();
3198  double result = _convert_to_type(*it++, 0.0);
3199  for (; it != A.end(); ++it)
3200  result -= _convert_to_type(*it, 0.0);
3201 
3202  return _convert_from_type(result);
3203  }
3204  else if (expr[0] == '*')
3205  {
3206  STRING_VECTOR A = _DBE_get_expr_list(expr.substr(1), 2);
3207  STRING_VECTOR::const_iterator it = A.begin();
3208  double result = _convert_to_type(*it++, 0.0);
3209  for (; it != A.end(); ++it)
3210  result *= _convert_to_type(*it, 0.0);
3211 
3212  return _convert_from_type(result);
3213  }
3214  else if (expr[0] == '/')
3215  {
3216  STRING_VECTOR A = _DBE_get_expr_list(expr.substr(1), 2);
3217  STRING_VECTOR::const_iterator it = A.begin();
3218  double result = _convert_to_type(*it++, 0.0);
3219  if (result == 0)
3220  return "0.0";
3221 
3222  for (; it != A.end(); ++it)
3223  {
3224  const double Q = _convert_to_type(*it, 0.0);
3225  result /= Q;
3226  }
3227  return _convert_from_type(result);
3228  }
3229 
3230  // ${^ ... } power expressions
3231  else if (expr[0] == '^')
3232  {
3233  STRING_VECTOR A = _DBE_get_expr_list(expr.substr(1), 2);
3234  STRING_VECTOR::const_iterator it = A.begin();
3235  double result = _convert_to_type(*it++, 0.0);
3236  for (; it != A.end(); ++it)
3237  result = pow(result, _convert_to_type(*it, 0.0));
3238  return _convert_from_type(result);
3239  }
3240 
3241  // ${== } ${<= } ${>= } comparisons (return the number of the first 'match'
3242  else if (expr.length() >= 2 &&
3243  (expr.substr(0,2) == "==" || expr.substr(0,2) == ">=" ||
3244  expr.substr(0,2) == "<=" || expr[0] == '>' || expr[0] == '<'))
3245  {
3246  // differentiate between two and one sign operators
3247  unsigned op = 0;
3248  enum { EQ, GEQ, LEQ, GT, LT };
3249 
3250  if (expr.substr(0, 2) == "==")
3251  op = EQ;
3252 
3253  else if (expr.substr(0, 2) == ">=")
3254  op = GEQ;
3255 
3256  else if (expr.substr(0, 2) == "<=")
3257  op = LEQ;
3258 
3259  else if (expr[0] == '>')
3260  op = GT;
3261 
3262  else
3263  op = LT;
3264 
3265  STRING_VECTOR a;
3266  if (op == GT || op == LT)
3267  a = _DBE_get_expr_list(expr.substr(1), 2);
3268 
3269  else
3270  a = _DBE_get_expr_list(expr.substr(2), 2);
3271 
3272  std::string x_orig = a[0];
3273  double x = _convert_to_type(x_orig, 1e37);
3274  unsigned i = 1;
3275 
3276  STRING_VECTOR::const_iterator y_orig = a.begin();
3277  for (y_orig++; y_orig != a.end(); ++y_orig)
3278  {
3279  double y = _convert_to_type(*y_orig, 1e37);
3280 
3281  // set the strings as reference if one wasn't a number
3282  if (x == 1e37 || y == 1e37)
3283  {
3284  // it's a string comparison
3285  if ((op == EQ && x_orig == *y_orig) || (op == GEQ && x_orig >= *y_orig) ||
3286  (op == LEQ && x_orig <= *y_orig) || (op == GT && x_orig > *y_orig) ||
3287  (op == LT && x_orig < *y_orig))
3288  return _convert_from_type(i);
3289  }
3290  else
3291  {
3292  // it's a number comparison
3293  if ((op == EQ && x == y) || (op == GEQ && x >= y) ||
3294  (op == LEQ && x <= y) || (op == GT && x > y) ||
3295  (op == LT && x < y))
3296  return _convert_from_type(i);
3297  }
3298  i++;
3299  }
3300 
3301  // nothing fulfills the condition => return 0
3302  return "0";
3303  }
3304 
3305  // ${?? expr expr} select
3306  else if (expr.length() >= 2 && expr.substr(0, 2) == "??")
3307  {
3308  STRING_VECTOR a = _DBE_get_expr_list(expr.substr(2), 2);
3309  double x = _convert_to_type(a[0], 1e37);
3310 
3311  // last element is always the default argument
3312  if (x == 1e37 || x < 0 || x >= a.size() - 1)
3313  return a[a.size()-1];
3314 
3315  // round x to closest integer
3316  return a[int(x+0.5)];
3317  }
3318 
3319  // ${? expr expr expr} if then else conditions
3320  else if (expr[0] == '?')
3321  {
3322  STRING_VECTOR a = _DBE_get_expr_list(expr.substr(1), 2);
3323 
3324  if (_convert_to_type(a[0], 0.0) == 1.0)
3325  return a[1];
3326 
3327  else if (a.size() > 2)
3328  return a[2];
3329  }
3330  // ${! expr} maxro expansion
3331  else if (expr[0] == '!')
3332  {
3333  const GetPot::variable* Var = _DBE_get_variable(expr.substr(1));
3334  // error
3335  if (Var->name == "")
3336  return std::string(Var->original);
3337 
3338  const STRING_VECTOR A = _DBE_get_expr_list(Var->original, 2);
3339  return A[0];
3340  }
3341  // ${@: } - string subscription
3342  else if (expr.length() >= 2 && expr.substr(0,2) == "@:")
3343  {
3344  const STRING_VECTOR A = _DBE_get_expr_list(expr.substr(2), 2);
3345  double x = _convert_to_type(A[1], 1e37);
3346 
3347  // last element is always the default argument
3348  if (x == 1e37 || x < 0 || x >= A[0].size() - 1)
3349  return "<<1st index out of range>>";
3350 
3351  if (A.size() > 2)
3352  {
3353  double y = _convert_to_type(A[2], 1e37);
3354  if (y != 1e37 && y > 0 && y <= A[0].size() - 1 && y > x)
3355  return A[0].substr(int(x+0.5), int(y+1.5) - int(x+0.5));
3356 
3357  else if (y == -1)
3358  return A[0].substr(int(x+0.5));
3359 
3360  return "<<2nd index out of range>>";
3361  }
3362  else
3363  {
3364  char* tmp = new char[2];
3365  tmp[0] = A[0][int(x+0.5)]; tmp[1] = '\0';
3366  std::string result(tmp);
3367  delete [] tmp;
3368  return result;
3369  }
3370  }
3371  // ${@ } - vector subscription
3372  else if (expr[0] == '@')
3373  {
3374  STRING_VECTOR A = _DBE_get_expr_list(expr.substr(1), 2);
3375  const GetPot::variable* Var = _DBE_get_variable(A[0]);
3376  // error
3377  if (Var->name == "")
3378  {
3379  // make a copy of the string if an error occured
3380  // (since the error variable is a static variable inside get_variable())
3381  return std::string(Var->original);
3382  }
3383 
3384  double x = _convert_to_type(A[1], 1e37);
3385 
3386  // last element is always the default argument
3387  if (x == 1e37 || x < 0 || x >= Var->value.size())
3388  return "<<1st index out of range>>";
3389 
3390  if (A.size() > 2)
3391  {
3392  double y = _convert_to_type(A[2], 1e37);
3393  int begin = int(x+0.5);
3394  int end = 0;
3395  if (y != 1e37 && y > 0 && y <= Var->value.size() && y > x)
3396  end = int(y+1.5);
3397  else if (y == -1)
3398  end = int(Var->value.size());
3399  else
3400  return "<<2nd index out of range>>";
3401 
3402  std::string result = *(Var->get_element(begin));
3403  for (int i = begin+1; i < end; i++)
3404  result += std::string(" ") + *(Var->get_element(i));
3405  return result;
3406  }
3407  else
3408  return *(Var->get_element(int(x+0.5)));
3409  }
3410 
3411  const STRING_VECTOR A = _DBE_get_expr_list(expr, 1);
3412  const GetPot::variable* B = _DBE_get_variable(A[0]);
3413 
3414  // make a copy of the string if an error occured
3415  // (since the error variable is a static variable inside get_variable())
3416  if (B->name == "")
3417  return std::string(B->original);
3418 
3419  // (psuggs@pobox.com mentioned to me the warning MSVC++6.0 produces
3420  // with: else return B->original (thanks))
3421  return B->original;
3422 }
#define getpot_error()
Definition: getpot.h:78
#define getpot_cerr
Definition: getpot.h:77
std::string name
Definition: getpot.h:500
long double max(long double a, double b)
T pow(const T &x)
Definition: utility.h:194
unsigned size() const
Definition: getpot.h:1903
std::string original
Definition: getpot.h:502
STRING_VECTOR _DBE_get_expr_list(const std::string &str, const unsigned ExpectedNumber)
Definition: getpot.h:2801
const GetPot::variable * _DBE_get_variable(const std::string &str)
Definition: getpot.h:2892
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
static std::string _convert_from_type(const T &Value)
Definition: getpot.h:690
T _convert_to_type(const std::string &String, const T &Default) const
Definition: getpot.h:1567
long double min(long double a, double b)
std::string GetPot::_DBE_expand_string ( const std::string &  str)
inlineprivate

dollar bracket expressions

Definition at line 2768 of file getpot.h.

References _DBE_expand().

Referenced by _parse_argument_vector().

2769 {
2770  // Parses for closing operators '${ }' and expands them letting
2771  // white spaces and other letters as they are.
2772  std::string new_string = "";
2773  unsigned open_brackets = 0;
2774  unsigned first = 0;
2775  for (unsigned i = 0; i<str.size(); i++)
2776  {
2777  if (i < str.size() - 2 && str.substr(i, 2) == "${")
2778  {
2779  if (open_brackets == 0)
2780  first = i+2;
2781  open_brackets++;
2782  }
2783  else if (str[i] == '}' && open_brackets > 0)
2784  {
2785  open_brackets -= 1;
2786  if (open_brackets == 0)
2787  {
2788  const std::string Replacement = _DBE_expand(str.substr(first, i - first));
2789  new_string += Replacement;
2790  }
2791  }
2792  else if (open_brackets == 0)
2793  new_string += str[i];
2794  }
2795  return new_string;
2796 }
std::string _DBE_expand(const std::string &str)
Definition: getpot.h:2926
STRING_VECTOR GetPot::_DBE_get_expr_list ( const std::string &  str,
const unsigned  ExpectedNumber 
)
inlineprivate

Definition at line 2801 of file getpot.h.

References _DBE_expand().

Referenced by _DBE_expand().

2802 {
2803  // ensures that the resulting vector has the expected number
2804  // of arguments, but they may contain an error message
2805  std::string str = str_;
2806  // Separates expressions by non-bracketed whitespaces, expands them
2807  // and puts them into a list.
2808 
2809  unsigned i=0;
2810  // (1) eat initial whitespaces
2811  for (; i < str.size(); i++)
2812  if (!isspace(str[i]))
2813  break;
2814 
2815  STRING_VECTOR expr_list;
2816  unsigned open_brackets = 0;
2817  std::vector<unsigned> start_idx;
2818  unsigned start_new_string = i;
2819  unsigned l = (unsigned)(str.size());
2820 
2821  // (2) search for ${ } expressions ...
2822  while (i < l)
2823  {
2824  const char letter = str[i];
2825  // whitespace -> end of expression
2826  if (isspace(letter) && open_brackets == 0)
2827  {
2828  expr_list.push_back(str.substr(start_new_string, i - start_new_string));
2829  bool no_breakout_f = true;
2830  for (i++; i < l ; i++)
2831  {
2832  if (!isspace(str[i]))
2833  {
2834  no_breakout_f = false;
2835  start_new_string = i;
2836  break;
2837  }
2838  }
2839 
2840  if (no_breakout_f)
2841  {
2842  // end of expression list
2843  if (expr_list.size() < ExpectedNumber)
2844  {
2845  const std::string pre_tmp("<< ${ }: missing arguments>>");
2846  STRING_VECTOR tmp(ExpectedNumber - expr_list.size(), pre_tmp);
2847  expr_list.insert(expr_list.end(), tmp.begin(), tmp.end());
2848  }
2849  return expr_list;
2850  }
2851  }
2852 
2853  // dollar-bracket expression
2854  if (str.length() >= i+2 && str.substr(i, 2) == "${")
2855  {
2856  open_brackets++;
2857  start_idx.push_back(i+2);
2858  }
2859 
2860  else if (letter == '}' && open_brackets > 0)
2861  {
2862  int start = start_idx[start_idx.size()-1];
2863  start_idx.pop_back();
2864  const std::string Replacement = _DBE_expand(str.substr(start, i-start));
2865  if (start - 3 < (int)0)
2866  str = Replacement + str.substr(i+1);
2867  else
2868  str = str.substr(0, start-2) + Replacement + str.substr(i+1);
2869  l = (int)(str.size());
2870  i = start + (int)(Replacement.size()) - 3;
2871  open_brackets--;
2872  }
2873  i++;
2874  }
2875 
2876  // end of expression list
2877  expr_list.push_back(str.substr(start_new_string, i-start_new_string));
2878 
2879  if (expr_list.size() < ExpectedNumber)
2880  {
2881  const std::string pre_tmp("<< ${ }: missing arguments>>");
2882  STRING_VECTOR tmp(ExpectedNumber - expr_list.size(), pre_tmp);
2883  expr_list.insert(expr_list.end(), tmp.begin(), tmp.end());
2884  }
2885 
2886  return expr_list;
2887 }
std::string _DBE_expand(const std::string &str)
Definition: getpot.h:2926
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
const GetPot::variable * GetPot::_DBE_get_variable ( const std::string &  str)
inlineprivate

Definition at line 2892 of file getpot.h.

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

Referenced by _DBE_expand().

2893 {
2894  static GetPot::variable ev;
2895  std::string secure_Prefix = prefix;
2896 
2897  prefix = section;
2898  // (1) first search in currently active section
2899  const GetPot::variable* var = _request_variable(VarName.c_str());
2900  if (var != 0)
2901  {
2902  prefix = secure_Prefix;
2903  return var;
2904  }
2905 
2906  // (2) search in root name space
2907  prefix = "";
2908  var = _request_variable(VarName.c_str());
2909  if (var != 0)
2910  {
2911  prefix = secure_Prefix;
2912  return var;
2913  }
2914 
2915  prefix = secure_Prefix;
2916 
2917  // error occured => variable name == ""
2918  ev.original = "<<${ } variable '";
2919  ev.original += VarName + "' undefined>>";
2920  return &ev;
2921 }
std::string prefix
Definition: getpot.h:508
const variable * _request_variable(const char *) const
Definition: getpot.h:2671
std::string original
Definition: getpot.h:502
std::string section
Definition: getpot.h:509
const GetPot::variable * GetPot::_find_variable ( const char *  VarName) const
inlineprivate

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

Definition at line 2655 of file getpot.h.

References prefix, and variables.

Referenced by _request_variable(), and _set_variable().

2656 {
2657  const std::string Name = prefix + VarName;
2658 
2659  std::vector<variable>::const_iterator it = variables.begin();
2660  for (; it != variables.end(); ++it)
2661  {
2662  if ((*it).name == Name)
2663  return &(*it);
2664  }
2665  return 0;
2666 }
std::string prefix
Definition: getpot.h:508
std::vector< variable > variables
Definition: getpot.h:530
const std::string GetPot::_get_next_token ( std::istream &  istr)
inlineprivate

Definition at line 1366 of file getpot.h.

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

Referenced by _read_in_stream().

1367 {
1368  // get next concatenates string token. consider quotes that embrace
1369  // whitespaces
1370  std::string token;
1371  int tmp = 0;
1372  while (true)
1373  {
1374  int last_letter = tmp;
1375  tmp = istr.get();
1376 
1377  if (tmp == '=')
1378  {
1379  // Always break at '='.
1380  // This separates '=' at the beginning of a word into its own word.
1381  token += getpot_cast_int<char>(tmp);
1382  return token;
1383  }
1384 
1385  else if (tmp == EOF || ((tmp == ' ' || tmp == '\t' || tmp == '\n') && last_letter != '\\'))
1386  return token;
1387 
1388  else if (tmp == '\'' && last_letter != '\\')
1389  {
1390  // QUOTES: un-backslashed quotes => it's a string
1391  token += _get_string(istr);
1392  continue;
1393  }
1394 
1395  else if (tmp == '{' && last_letter == '$')
1396  {
1397  token += '{' + _get_until_closing_bracket(istr);
1398  continue;
1399  }
1400 
1401  else if (tmp == '[')
1402  {
1403  token += '[' + _get_until_closing_square_bracket(istr);
1404  continue;
1405  }
1406 
1407  else if (tmp == '$' && last_letter == '\\')
1408  {
1409  token += getpot_cast_int<char>(tmp); tmp = 0; // so that last_letter will become = 0, not '$';
1410  continue;
1411  }
1412 
1413  else if (tmp == '\\' && last_letter != '\\')
1414  continue; // don't append un-backslashed backslashes
1415 
1416  token += getpot_cast_int<char>(tmp);
1417  }
1418 }
const std::string _get_until_closing_square_bracket(std::istream &istr)
Definition: getpot.h:1482
const std::string _get_until_closing_bracket(std::istream &istr)
Definition: getpot.h:1449
const std::string _get_string(std::istream &istr)
Definition: getpot.h:1423
const std::string GetPot::_get_remaining_string ( const std::string &  String,
const std::string &  Start 
) const
inlineprivate

prefix extraction

Definition at line 1736 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().

1737 {
1738  if (Start == "")
1739  return String;
1740 
1741  // note: java.lang.String: substring(a,b) = from a to b-1
1742  // C++ string: substr(a,b) = from a to a + b
1743  if (String.find(Start) == 0)
1744  return String.substr(Start.length());
1745 
1746  else
1747  return "";
1748 }
static STRING_VECTOR 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 701 of file getpot.h.

Referenced by _record_argument_request(), and _record_variable_request().

702  {
703  STRING_VECTOR result;
704  for (std::size_t pos = 0; pos != FullPath.size(); ++pos)
705  {
706  if (FullPath[pos] == '/')
707  result.push_back(FullPath.substr(0,pos));
708  }
709 
710  return result;
711  }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
const std::string GetPot::_get_string ( std::istream &  istr)
inlineprivate

Definition at line 1423 of file getpot.h.

Referenced by _get_next_token().

1424 {
1425  // parse input until next matching '
1426  std::string str;
1427  int tmp = 0;
1428  while (true)
1429  {
1430  int last_letter = tmp;
1431  tmp = istr.get();
1432  if (tmp == EOF)
1433  return str;
1434 
1435  // un-backslashed quotes => it's the end of the string
1436  else if (tmp == '\'' && last_letter != '\\')
1437  return str;
1438 
1439  else if (tmp == '\\' && last_letter != '\\')
1440  continue; // don't append
1441 
1442  str += getpot_cast_int<char>(tmp);
1443  }
1444 }
const std::string GetPot::_get_until_closing_bracket ( std::istream &  istr)
inlineprivate

Definition at line 1449 of file getpot.h.

Referenced by _get_next_token().

1450 {
1451  // parse input until next matching }
1452  std::string str = "";
1453  int tmp = 0;
1454  int brackets = 1;
1455  while (true)
1456  {
1457  int last_letter = tmp;
1458  tmp = istr.get();
1459  if (tmp == EOF)
1460  return str;
1461 
1462  else if (tmp == '{' && last_letter == '$')
1463  brackets += 1;
1464 
1465  else if (tmp == '}')
1466  {
1467  brackets -= 1;
1468  // un-backslashed brackets => it's the end of the string
1469  if (brackets == 0)
1470  return str + '}';
1471 
1472  else if (tmp == '\\' && last_letter != '\\')
1473  continue; // do not append an unbackslashed backslash
1474  }
1475  str += getpot_cast_int<char>(tmp);
1476  }
1477 }
const std::string GetPot::_get_until_closing_square_bracket ( std::istream &  istr)
inlineprivate

Definition at line 1482 of file getpot.h.

Referenced by _get_next_token().

1483 {
1484  // parse input until next matching ]
1485  std::string str = "";
1486  int brackets = 1;
1487  while (true)
1488  {
1489  int tmp = istr.get();
1490  if (tmp == EOF)
1491  return str;
1492 
1493  else if (tmp == '[')
1494  brackets += 1;
1495 
1496  else if (tmp == ']')
1497  {
1498  brackets -= 1;
1499  if (brackets == 0)
1500  return str + ']';
1501  }
1502 
1503  str += getpot_cast_int<char>(tmp);
1504  }
1505 }
const char * 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 1705 of file getpot.h.

References _internal_string_container, and SCOPED_MUTEX.

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

1706 {
1707  const char* arg = Arg.c_str();
1708 
1709  // Get a lock before touching anything mutable
1710  SCOPED_MUTEX;
1711 
1712  // See if there's already an identical string saved
1713  std::set<const char*,ltstr>::const_iterator it =
1714  _internal_string_container.find(arg);
1715 
1716  // If so, return it
1717  if (it != _internal_string_container.end())
1718  return *it;
1719 
1720  // Otherwise, create a new one
1721  char* newcopy = new char[strlen(arg)+1];
1722  strncpy(newcopy, arg, strlen(arg)+1);
1723  _internal_string_container.insert(newcopy);
1724  return newcopy;
1725 }
#define SCOPED_MUTEX
Definition: getpot.h:70
std::set< const char *, ltstr > _internal_string_container
Definition: getpot.h:567
const char * GetPot::_match_starting_string ( const char *  StartString)
inlineprivate

support finding directly followed arguments

Definition at line 2057 of file getpot.h.

References argv, cursor, search_failed_f, and search_loop_f.

Referenced by direct_follow().

2058 {
2059  const unsigned N =
2060  getpot_cast_int<unsigned>(strlen(StartString));
2061  unsigned OldCursor = cursor;
2062 
2063  if (OldCursor >= argv.size())
2064  OldCursor = getpot_cast_int<unsigned>(argv.size() - 1);
2065  search_failed_f = true;
2066 
2067  // (*) first loop from cursor position until end
2068  for (unsigned c = cursor; c < argv.size(); c++)
2069  {
2070  if (strncmp(StartString, argv[c].c_str(), N) == 0)
2071  {
2072  cursor = c;
2073  search_failed_f = false;
2074  return &(argv[c].c_str()[N]);
2075  }
2076  }
2077 
2078  if (!search_loop_f)
2079  return NULL;
2080 
2081  // (*) second loop from 0 to old cursor position
2082  for (unsigned c = 1; c < OldCursor; c++)
2083  {
2084  if (strncmp(StartString, argv[c].c_str(), N) == 0)
2085  {
2086  cursor = c;
2087  search_failed_f = false;
2088  return &(argv[c].c_str()[N]);
2089  }
2090  }
2091  return 0;
2092 }
bool search_failed_f
Definition: getpot.h:518
bool search_loop_f
Definition: getpot.h:517
unsigned cursor
Definition: getpot.h:516
STRING_VECTOR argv
Definition: getpot.h:515
void GetPot::_parse_argument_vector ( const STRING_VECTOR ARGV)
inlineprivate

produce three basic data vectors:

  • argument vector
  • nominus vector
  • variable dictionary

Definition at line 1129 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, SCOPED_MUTEX, section, and section_list.

Referenced by parse_command_line(), and parse_input_stream().

1130 {
1131  if (ARGV.empty())
1132  return;
1133 
1134  // build internal databases:
1135  // 1) array with no-minus arguments (usually used as filenames)
1136  // 2) variable assignments:
1137  // 'variable name' '=' number | string
1138  STRING_VECTOR section_stack;
1139  STRING_VECTOR::const_iterator it = ARGV.begin();
1140 
1141 
1142  section = "";
1143 
1144  // -- do not parse the first argument, so that this parsing source
1145  // name is not interpreted a s a nominus or so. If we already
1146  // have parsed arguments, don't bother adding another parsing
1147  // source name
1148  if (argv.empty())
1149  argv.push_back(*it);
1150  ++it;
1151 
1152  // -- loop over remaining arguments
1153  for (; it != ARGV.end(); ++it)
1154  {
1155  std::string arg = *it;
1156 
1157  if (arg.length() == 0)
1158  continue;
1159 
1160  // -- [section] labels and [include file] directives
1161  if (arg.length() > 1 && arg[0] == '[' && arg[arg.length()-1] == ']')
1162  {
1163 
1164  // Is this an include file directive?
1165  std::size_t include_pos = arg.find("include ", 1);
1166  if (include_pos != std::string::npos)
1167  {
1168 
1169  const std::string includefile =
1170  _DBE_expand_string(arg.substr(9, arg.length()-9-include_pos));
1171 
1172  this->parse_input_file
1173  (includefile, _comment_start, _comment_end, _field_separator);
1174  }
1175 
1176  else
1177  {
1178  // (*) sections are considered 'requested arguments'
1179  if (request_recording_f)
1180  {
1181  // Get a lock before touching anything mutable
1182  SCOPED_MUTEX;
1183 
1184  _requested_arguments.insert(arg);
1185  }
1186 
1187  const std::string Name = _DBE_expand_string(arg.substr(1, arg.length()-2));
1188  section = _process_section_label(Name, section_stack);
1189  // new section --> append to list of sections
1190  if (find(section_list.begin(), section_list.end(), section) == section_list.end())
1191  if (section.length() != 0) section_list.push_back(section);
1192  argv.push_back(arg);
1193  }
1194  }
1195  else
1196  {
1197  arg = section + _DBE_expand_string(arg);
1198  argv.push_back(arg);
1199  }
1200 
1201  // -- separate array for nominus arguments
1202  if (arg[0] != '-')
1203  idx_nominus.push_back(getpot_cast_int<unsigned>(argv.size()-1));
1204 
1205  // -- variables: does arg contain a '=' operator ?
1206  const std::size_t equals_pos = arg.find_first_of('=');
1207  if (equals_pos != std::string::npos)
1208  {
1209  // (*) record for later ufo detection
1210  // arguments carriying variables are always treated as 'requested' arguments.
1211  // unrequested variables have to be detected with the ufo-variable
1212  // detection routine.
1213  if (request_recording_f)
1214  {
1215  // Get a lock before touching anything mutable
1216  SCOPED_MUTEX;
1217 
1218  _requested_arguments.insert(arg);
1219  }
1220 
1221  // => arg (from start to '=') = Name of variable
1222  // (from '=' to end) = value of variable
1223  _set_variable(arg.substr(0,equals_pos),
1224  arg.substr(equals_pos+1), false);
1225  }
1226  }
1227 }
std::string _DBE_expand_string(const std::string &str)
Definition: getpot.h:2768
void parse_input_file(const std::string &FileName, const std::string &CommentStart=std::string("#"), const std::string &CommentEnd=std::string("\n"), const std::string &FieldSeparator=std::string(" \t\n"))
Definition: getpot.h:897
std::set< std::string > _requested_arguments
Definition: getpot.h:579
std::vector< unsigned > idx_nominus
Definition: getpot.h:525
std::string _process_section_label(const std::string &Section, STRING_VECTOR &section_stack)
Definition: getpot.h:1510
STRING_VECTOR section_list
Definition: getpot.h:510
bool request_recording_f
Definition: getpot.h:583
std::string section
Definition: getpot.h:509
void _set_variable(const std::string &VarName, const std::string &Value, const bool Requested)
Definition: getpot.h:2500
std::string _comment_end
Definition: getpot.h:536
#define SCOPED_MUTEX
Definition: getpot.h:70
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
std::string _field_separator
Definition: getpot.h:541
STRING_VECTOR argv
Definition: getpot.h:515
std::string _comment_start
Definition: getpot.h:535
std::string GetPot::_process_section_label ( const std::string &  Section,
STRING_VECTOR section_stack 
)
inlineprivate

Definition at line 1510 of file getpot.h.

References victorate.

Referenced by _parse_argument_vector().

1512 {
1513  std::string sname = Section;
1514  // 1) subsection of actual section ('./' prefix)
1515  if (sname.length() >= 2 && sname.substr(0, 2) == "./")
1516  sname = sname.substr(2);
1517 
1518  // 2) subsection of parent section ('../' prefix)
1519  else if (sname.length() >= 3 && sname.substr(0, 3) == "../")
1520  {
1521  do
1522  {
1523  if (section_stack.end() != section_stack.begin())
1524  section_stack.pop_back();
1525  sname = sname.substr(3);
1526  } while (sname.substr(0, 3) == "../");
1527  }
1528 
1529  // 3) subsection of the root-section
1530  else
1531  // [] => back to root section
1532  section_stack.erase(section_stack.begin(), section_stack.end());
1533 
1534  if (sname != "")
1535  {
1536  // parse section name for 'slashes'
1537  unsigned i=0;
1538  while (i < sname.length())
1539  {
1540  if (sname[i] == '/')
1541  {
1542  section_stack.push_back(sname.substr(0,i));
1543  if (i+1 < sname.length())
1544  sname = sname.substr(i+1);
1545  i = 0;
1546  }
1547  else
1548  i++;
1549  }
1550  section_stack.push_back(sname);
1551  }
1552 
1553  std::string section_label = "";
1554  if (!section_stack.empty())
1555  {
1556  victorate(std::string, section_stack, it)
1557  section_label += *it + "/";
1558  }
1559  return section_label;
1560 }
#define victorate(TYPE, VARIABLE, ITERATOR)
Definition: getpot.h:134
STRING_VECTOR GetPot::_read_in_stream ( std::istream &  istr)
inlineprivate

Definition at line 1232 of file getpot.h.

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

Referenced by parse_input_stream().

1233 {
1234  STRING_VECTOR brute_tokens;
1235  while (istr)
1236  {
1237  _skip_whitespace(istr);
1238  const std::string Token = _get_next_token(istr);
1239  // Allow 'keyword =' to parse with an empty string as value.
1240  // Only break at EOF.
1241  // if (Token.length() == 0 || Token[0] == EOF) break;
1242  if (Token[0] == EOF)
1243  break;
1244  brute_tokens.push_back(Token);
1245  }
1246 
1247  // -- reduce expressions of token1'='token2 to a single
1248  // string 'token1=token2'
1249  // -- copy everything into 'argv'
1250  // -- arguments preceded by something like '[' name ']' (section)
1251  // produce a second copy of each argument with a prefix '[name]argument'
1252  unsigned i1 = 0;
1253  unsigned i2 = 1;
1254  unsigned i3 = 2;
1255 
1256  STRING_VECTOR arglist;
1257  while (i1 < brute_tokens.size())
1258  {
1259  // 1) concatenate 'abcdef' '=' 'efgasdef' to 'abcdef=efgasdef'
1260  // note: java.lang.String: substring(a,b) = from a to b-1
1261  // C++ string: substr(a,b) = from a to a + b
1262  std::string result;
1263  if (i2 < brute_tokens.size() && brute_tokens[i2] == "=")
1264  {
1265  if (i3 >= brute_tokens.size())
1266  result = brute_tokens[i1] + brute_tokens[i2];
1267  else
1268  result = brute_tokens[i1] + brute_tokens[i2] + brute_tokens[i3];
1269  i1 = i3+1; i2 = i3+2; i3 = i3+3;
1270  }
1271  else if (i2 < brute_tokens.size() &&
1272  brute_tokens[i2].length() > 0 &&
1273  brute_tokens[i2][0] == '=')
1274  {
1275  // This case should not be hit if '=' at the beginning of a word
1276  // is always separated into its own word
1277  result = brute_tokens[i1] + brute_tokens[i2];
1278  i1 = i3; i2 = i3+1; i3 = i3+2;
1279  }
1280  else if (i2 < brute_tokens.size() && brute_tokens[i1][brute_tokens[i1].size()-1] == '=')
1281  {
1282  result = brute_tokens[i1] + brute_tokens[i2];
1283  i1 = i3; i2 = i3+1; i3 = i3+2;
1284  }
1285  else
1286  {
1287  result = brute_tokens[i1];
1288  i1=i2; i2=i3; i3++;
1289  }
1290 
1291  // Now strip out any comment
1292  size_t comment_start_loc = result.find(_comment_start, 0);
1293  if (comment_start_loc != std::string::npos)
1294  result = result.substr(0, comment_start_loc);
1295 
1296  arglist.push_back(result);
1297  }
1298  return arglist;
1299 }
const std::string _get_next_token(std::istream &istr)
Definition: getpot.h:1366
void _skip_whitespace(std::istream &istr)
Definition: getpot.h:1304
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
std::string _comment_start
Definition: getpot.h:535
void 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 2454 of file getpot.h.

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

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

2455 {
2456  if (!request_recording_f)
2457  return;
2458 
2459  // Get a lock before touching anything mutable
2460  SCOPED_MUTEX;
2461 
2462  // (*) record requested variable for later ufo detection
2463  _requested_arguments.insert(Name);
2464 
2465  // (*) record considered section for ufo detection
2466  STRING_VECTOR STree = _get_section_tree(Name);
2467  victorate(std::string, STree, it)
2468  if (_requested_sections.find(*it) == _requested_sections.end())
2469  if (section.length() != 0)
2470  _requested_sections.insert(*it);
2471 }
std::set< std::string > _requested_arguments
Definition: getpot.h:579
#define victorate(TYPE, VARIABLE, ITERATOR)
Definition: getpot.h:134
bool request_recording_f
Definition: getpot.h:583
std::set< std::string > _requested_sections
Definition: getpot.h:581
std::string section
Definition: getpot.h:509
#define SCOPED_MUTEX
Definition: getpot.h:70
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
static STRING_VECTOR _get_section_tree(const std::string &FullPath)
Definition: getpot.h:701
void GetPot::_record_variable_request ( const std::string &  Arg) const
inlineprivate

Definition at line 2476 of file getpot.h.

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

Referenced by _request_variable().

2477 {
2478  if (!request_recording_f)
2479  return;
2480 
2481  // Get a lock before touching anything mutable
2482  SCOPED_MUTEX;
2483 
2484  // (*) record requested variable for later ufo detection
2485  _requested_variables.insert(Name);
2486 
2487  // (*) record considered section for ufo detection
2488  STRING_VECTOR STree = _get_section_tree(Name);
2489  victorate(std::string, STree, it)
2490  if (_requested_sections.find(*it) == _requested_sections.end())
2491  if (section.length() != 0)
2492  _requested_sections.insert(*it);
2493 }
#define victorate(TYPE, VARIABLE, ITERATOR)
Definition: getpot.h:134
bool request_recording_f
Definition: getpot.h:583
std::set< std::string > _requested_sections
Definition: getpot.h:581
std::set< std::string > _requested_variables
Definition: getpot.h:580
std::string section
Definition: getpot.h:509
#define SCOPED_MUTEX
Definition: getpot.h:70
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
static STRING_VECTOR _get_section_tree(const std::string &FullPath)
Definition: getpot.h:701
const GetPot::variable * GetPot::_request_variable ( const char *  VarName) const
inlineprivate

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

Definition at line 2671 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().

2672 {
2673  // (*) record requested variable for later ufo detection
2674  this->_record_variable_request(VarName);
2675 
2676  return this->_find_variable(VarName);
2677 }
void _record_variable_request(const std::string &Arg) const
Definition: getpot.h:2476
const variable * _find_variable(const char *) const
Definition: getpot.h:2655
bool GetPot::_search_string_vector ( const STRING_VECTOR Vec,
const std::string &  Str 
) const
inlineprivate

search for a specific string

Definition at line 3431 of file getpot.h.

References victorate.

3432 {
3433  victorate(std::string, VecStr, itk)
3434  {
3435  if (*itk == Str)
3436  return true;
3437  }
3438  return false;
3439 }
#define victorate(TYPE, VARIABLE, ITERATOR)
Definition: getpot.h:134
void 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 2500 of file getpot.h.

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

Referenced by _parse_argument_vector(), and set().

2502 {
2503  const GetPot::variable* Var = Requested ?
2504  _request_variable(VarName.c_str()) :
2505  _find_variable(VarName.c_str());
2506  if (Var == 0)
2507  variables.push_back(variable(VarName.c_str(), Value.c_str(), _field_separator.c_str()));
2508  else
2509  {
2510  overridden_vars.insert(VarName.c_str());
2511  (const_cast<GetPot::variable*>(Var))->take(Value.c_str(), _field_separator.c_str());
2512  }
2513 }
const variable * _request_variable(const char *) const
Definition: getpot.h:2671
const variable * _find_variable(const char *) const
Definition: getpot.h:2655
std::string _field_separator
Definition: getpot.h:541
std::vector< variable > variables
Definition: getpot.h:530
std::set< std::string > overridden_vars
Definition: getpot.h:519
void 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 1304 of file getpot.h.

References _comment_end, and _comment_start.

Referenced by _read_in_stream().

1305 {
1306  // find next non-whitespace while deleting comments
1307  int tmp = istr.get();
1308  do {
1309  // -- search a non whitespace
1310  while (isspace(tmp))
1311  {
1312  tmp = istr.get();
1313  if (!istr)
1314  return;
1315  }
1316 
1317  // -- look if characters match the comment starter string
1318  for (unsigned i=0; i<_comment_start.length() ; i++)
1319  {
1320  if (tmp != _comment_start[i])
1321  {
1322  // -- one step more backwards, since 'tmp' already at non-whitespace
1323  istr.unget();
1324  return;
1325  }
1326 
1327  // RHS: Why is this here? It breaks on empty comments
1328  // tmp = istr.get();
1329  // if (!istr) { istr.unget(); return; }
1330  }
1331  // 'tmp' contains last character of _comment_starter
1332 
1333  // -- comment starter found -> search for comment ender
1334  unsigned match_no=0;
1335  while (true)
1336  {
1337  tmp = istr.get();
1338  if (!istr)
1339  {
1340  istr.unget();
1341  return;
1342  }
1343 
1344  if (tmp == _comment_end[match_no])
1345  {
1346  match_no++;
1347  if (match_no == _comment_end.length())
1348  {
1349  istr.unget();
1350  break; // shuffle more whitespace, end of comment found
1351  }
1352  }
1353  else
1354  match_no = 0;
1355  }
1356 
1357  tmp = istr.get();
1358 
1359  } while (istr);
1360  istr.unget();
1361 }
std::string _comment_end
Definition: getpot.h:536
std::string _comment_start
Definition: getpot.h:535
void GetPot::absorb ( const GetPot Other)
inline

absorbing contents of another GetPot object

Definition at line 1086 of file getpot.h.

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

1087 {
1088  if (&Other == this)
1089  return;
1090 
1091  // variables that are not influenced by absorption:
1092  // _comment_start
1093  // _comment_end
1094  // cursor
1095  // nominus_cursor
1096  // search_failed
1097  // idx_nominus
1098  // search_loop_f
1099  argv = Other.argv;
1100  variables = Other.variables;
1101 
1102  if (request_recording_f)
1103  {
1104  // Get a lock before touching anything mutable
1105  SCOPED_MUTEX;
1106 
1107  _requested_arguments.insert(Other._requested_arguments.begin(), Other._requested_arguments.end());
1108  _requested_variables.insert(Other._requested_variables.begin(), Other._requested_variables.end());
1109  _requested_sections.insert(Other._requested_sections.begin(), Other._requested_sections.end());
1110  }
1111 }
std::set< std::string > _requested_arguments
Definition: getpot.h:579
bool request_recording_f
Definition: getpot.h:583
std::set< std::string > _requested_sections
Definition: getpot.h:581
std::set< std::string > _requested_variables
Definition: getpot.h:580
#define SCOPED_MUTEX
Definition: getpot.h:70
std::vector< variable > variables
Definition: getpot.h:530
STRING_VECTOR argv
Definition: getpot.h:515
bool GetPot::argument_contains ( unsigned  Idx,
const char *  FlagList 
) const
inline

Definition at line 2120 of file getpot.h.

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

2121 {
2122  if (Idx >= argv.size())
2123  return false;
2124 
2125  // (*) record requested of argument for later ufo-detection
2126  // an argument that is checked for flags is considered to be 'requested'
2128 
2129  if (prefix == "")
2130  // search argument for any flag in flag list
2131  return _check_flags(argv[Idx], FlagList);
2132 
2133  // if a prefix is set, then the argument index is the index
2134  // inside the 'namespace'
2135  // => only check list of arguments that start with prefix
2136  unsigned no_matches = 0;
2137  for (unsigned i=0; i<argv.size(); i++)
2138  {
2139  const std::string Remain = _get_remaining_string(argv[i], prefix);
2140  if (Remain != "")
2141  {
2142  no_matches += 1;
2143  if (no_matches == Idx)
2144  return _check_flags(Remain, FlagList);
2145  }
2146  }
2147 
2148  // no argument in this namespace
2149  return false;
2150 }
std::string prefix
Definition: getpot.h:508
void _record_argument_request(const std::string &Arg) const
Definition: getpot.h:2454
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
Definition: getpot.h:1736
bool _check_flags(const std::string &Str, const char *FlagList) const
Definition: getpot.h:2155
STRING_VECTOR argv
Definition: getpot.h:515
void GetPot::clear_requests ( )
inline

for ufo detection: recording requested arguments, options etc.

Definition at line 1116 of file getpot.h.

References _requested_arguments, _requested_sections, _requested_variables, and SCOPED_MUTEX.

1117 {
1118  // Get a lock before touching anything mutable
1119  SCOPED_MUTEX;
1120 
1121  _requested_arguments.clear();
1122  _requested_variables.clear();
1123  _requested_sections.clear();
1124 }
std::set< std::string > _requested_arguments
Definition: getpot.h:579
std::set< std::string > _requested_sections
Definition: getpot.h:581
std::set< std::string > _requested_variables
Definition: getpot.h:580
#define SCOPED_MUTEX
Definition: getpot.h:70
template<typename T >
T GetPot::direct_follow ( const T &  Default,
const char *  Option 
)
inline

directly followed arguments

Definition at line 2028 of file getpot.h.

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

Referenced by direct_follow().

2029 {
2030  const char* FollowStr = _match_starting_string(Option);
2031 
2032  // (*) record requested of argument for later ufo-detection
2033  _record_argument_request(std::string(Option) + FollowStr);
2034 
2035  if (FollowStr == 0)
2036  return Default;
2037 
2038  if (++cursor >= argv.size())
2039  cursor = getpot_cast_int<unsigned>(argv.size());
2040  return _convert_to_type(FollowStr, Default);
2041 }
const char * _match_starting_string(const char *StartString)
Definition: getpot.h:2057
void _record_argument_request(const std::string &Arg) const
Definition: getpot.h:2454
unsigned cursor
Definition: getpot.h:516
T _convert_to_type(const std::string &String, const T &Default) const
Definition: getpot.h:1567
STRING_VECTOR argv
Definition: getpot.h:515
const char * GetPot::direct_follow ( const char *  Default,
const char *  Option 
)
inline

Definition at line 2046 of file getpot.h.

References _internal_managed_copy(), and direct_follow().

2047 {
2048  return _internal_managed_copy(direct_follow(std::string(Default), Option));
2049 }
T direct_follow(const T &Default, const char *Option)
Definition: getpot.h:2028
const char * _internal_managed_copy(const std::string &Arg) const
Definition: getpot.h:1705
void GetPot::disable_loop ( )
inline

enable/disable search for an option in loop

Definition at line 360 of file getpot.h.

Referenced by init_multiple_occurrence().

360 { search_loop_f = false; }
bool search_loop_f
Definition: getpot.h:517
void GetPot::disable_request_recording ( )
inline

Definition at line 209 of file getpot.h.

209 { request_recording_f = false; }
bool request_recording_f
Definition: getpot.h:583
void GetPot::enable_loop ( )
inline

Definition at line 361 of file getpot.h.

361 { search_loop_f = true; }
bool search_loop_f
Definition: getpot.h:517
void GetPot::enable_request_recording ( )
inline

Definition at line 210 of file getpot.h.

210 { request_recording_f = true; }
bool request_recording_f
Definition: getpot.h:583
template<typename T >
T GetPot::follow ( const T &  Default,
const char *  Option 
)
inline

search for option and get argument at cursor++

Definition at line 1946 of file getpot.h.

References next(), and search().

Referenced by follow().

1947 {
1948  // (*) record requested of argument is entirely handled in 'search()' and 'next()'
1949  if (search(Option) == false)
1950  return Default;
1951 
1952  return next(Default);
1953 }
bool search(const char *option)
Definition: getpot.h:1763
T next(const T &Default)
Definition: getpot.h:1913
const char * GetPot::follow ( const char *  Default,
const char *  Option 
)
inline

Definition at line 1958 of file getpot.h.

References _internal_managed_copy(), and follow().

1959 {
1960  return _internal_managed_copy(follow(std::string(Default), Option));
1961 }
T follow(const T &Default, const char *Option)
Definition: getpot.h:1946
const char * _internal_managed_copy(const std::string &Arg) const
Definition: getpot.h:1705
template<typename T >
T 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::follow ( const char *  Default,
unsigned  No,
const char *  Option,
  ... 
)
inline

Definition at line 1996 of file getpot.h.

References next(), and search().

1997 {
1998  // (*) record requested of argument is entirely handled in 'search()' and 'next()'
1999  if (No == 0)
2000  return Default;
2001 
2002  if (search(P) == true)
2003  return next(Default);
2004 
2005  va_list ap;
2006  va_start(ap, P);
2007  for (unsigned i=1; i<No; i++)
2008  {
2009  char* Opt = va_arg(ap, char *);
2010  if (search(Opt) == true)
2011  {
2012  va_end(ap);
2013  return next(Default);
2014  }
2015  }
2016  va_end(ap);
2017  return Default;
2018 }
bool search(const char *option)
Definition: getpot.h:1763
T next(const T &Default)
Definition: getpot.h:1913
template<typename T >
T GetPot::follow ( const T &  Default,
unsigned int  No,
const char *  P,
  ... 
)
inline

Definition at line 1969 of file getpot.h.

References next(), and search().

1970 {
1971  // (*) record requested of argument is entirely handled in 'search()' and 'next()'
1972  if (No == 0)
1973  return Default;
1974 
1975  if (search(P) == true)
1976  return next(Default);
1977 
1978  va_list ap;
1979  va_start(ap, P);
1980  for (unsigned i=1; i<No; i++)
1981  {
1982  char* Opt = va_arg(ap, char *);
1983  if (search(Opt) == true)
1984  {
1985  va_end(ap);
1986  return next(Default);
1987  }
1988  }
1989  va_end(ap);
1990  return Default;
1991 }
bool search(const char *option)
Definition: getpot.h:1763
T next(const T &Default)
Definition: getpot.h:1913
template<typename T >
T GetPot::get ( unsigned  Idx,
const T &  Default 
) const
inline
const char* GetPot::get ( unsigned  Idx,
const char *  Default 
) const
inline
template<typename T >
T GetPot::get ( unsigned int  Idx,
const T &  Default 
) const
inline

Definition at line 1883 of file getpot.h.

References _convert_to_type(), and argv.

1884 {
1885  if (Idx >= argv.size())
1886  return Default;
1887  return _convert_to_type(argv[Idx], Default);
1888 }
T _convert_to_type(const std::string &String, const T &Default) const
Definition: getpot.h:1567
STRING_VECTOR argv
Definition: getpot.h:515
std::set< std::string > GetPot::get_overridden_variables ( ) const
inline

Definition at line 2647 of file getpot.h.

References overridden_vars.

2648 {
2649  return overridden_vars;
2650 }
std::set< std::string > overridden_vars
Definition: getpot.h:519
std::set< std::string > GetPot::get_requested_arguments ( ) const
inline

Accessors for requested variables

Definition at line 3881 of file getpot.h.

References _requested_arguments.

3882 {
3883  return _requested_arguments;
3884 }
std::set< std::string > _requested_arguments
Definition: getpot.h:579
std::set< std::string > GetPot::get_requested_sections ( ) const
inline

Definition at line 3899 of file getpot.h.

References _requested_sections.

3900 {
3901  return _requested_sections;
3902 }
std::set< std::string > _requested_sections
Definition: getpot.h:581
std::set< std::string > GetPot::get_requested_variables ( ) const
inline

Definition at line 3890 of file getpot.h.

References _requested_variables.

3891 {
3892  return _requested_variables;
3893 }
std::set< std::string > _requested_variables
Definition: getpot.h:580
STRING_VECTOR GetPot::get_section_names ( ) const
inline

Definition at line 2589 of file getpot.h.

References section_list.

2590 {
2591  return section_list;
2592 }
STRING_VECTOR section_list
Definition: getpot.h:510
STRING_VECTOR GetPot::get_subsection_names ( const std::string &  section_name) const
inline

Definition at line 2597 of file getpot.h.

References section_list.

2598 {
2599  // GetPot functions should understand user-provided section names
2600  // either with or without a trailing slash.
2601  const std::string full_prefix =
2602  *prefix.rbegin() == '/' ? prefix : prefix + '/';
2603 
2604  const std::size_t full_prefix_len = full_prefix.size();
2605 
2606  // Subsections-of-subsections are in the section_list, so we'll be
2607  // adding subsections multiple times. Using std::set as an
2608  // intermediate data structure helps us check for duplicates with
2609  // O(N log N) rather than O(N^2) cost.
2610  std::set<std::string> subsections;
2611 
2612  STRING_VECTOR returnval;
2613 
2614  for (STRING_VECTOR::const_iterator it = section_list.begin();
2615  it != section_list.end(); ++it)
2616  {
2617  const std::string & section_name = *it;
2618 
2619  // If this section name begins with the prefix
2620  if (section_name.compare(0, full_prefix_len, full_prefix) == 0)
2621  {
2622  const std::size_t next_slash_len =
2623  section_name.find('/', full_prefix_len);
2624 
2625  const std::string subsection_name =
2626  section_name.substr(full_prefix_len,
2627  next_slash_len - full_prefix_len);
2628 
2629  // If there is a subsection, and if this is the first time
2630  // we've seen it, add the prefix-less, postfix-less
2631  // subsection name.
2632  if (!subsection_name.empty() &&
2633  !subsections.count(subsection_name))
2634  {
2635  returnval.push_back(subsection_name);
2636  subsections.insert(subsection_name);
2637  }
2638  }
2639  }
2640 
2641  return returnval;
2642 }
std::string prefix
Definition: getpot.h:508
STRING_VECTOR section_list
Definition: getpot.h:510
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
template<typename T >
T 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 2366 of file getpot.h.

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

Referenced by get_value_no_default().

2367 {
2368  // (*) recording of requested variables happens in '_request_variable()'
2369  const variable* sv = _request_variable(VarName);
2370  if (sv == 0)
2371  {
2372  getpot_cerr << "ERROR: cannot find variable "<<VarName<<std::endl;
2373  getpot_error();
2374  }
2375  return _convert_to_type_no_default(VarName, sv->original, Default);
2376 }
#define getpot_error()
Definition: getpot.h:78
#define getpot_cerr
Definition: getpot.h:77
T _convert_to_type_no_default(const char *VarName, const std::string &String, const T &Default) const
Definition: getpot.h:1632
const variable * _request_variable(const char *) const
Definition: getpot.h:2671
template<typename T >
T GetPot::get_value_no_default ( const std::string &  VarName,
const T &  Default 
) const
inline

Definition at line 2382 of file getpot.h.

References get_value_no_default().

2383 {
2384  return get_value_no_default(VarName.c_str(),Default);
2385 }
T get_value_no_default(const char *VarName, const T &Default) const
Definition: getpot.h:2366
const char * GetPot::get_value_no_default ( const char *  VarName,
const char *  Default 
) const
inline

Definition at line 2390 of file getpot.h.

References _internal_managed_copy(), and get_value_no_default().

2391 {
2392  return _internal_managed_copy(get_value_no_default(VarName, std::string(Default)));
2393 }
T get_value_no_default(const char *VarName, const T &Default) const
Definition: getpot.h:2366
const char * _internal_managed_copy(const std::string &Arg) const
Definition: getpot.h:1705
const char * GetPot::get_value_no_default ( const std::string &  VarName,
const char *  Default 
) const
inline

Definition at line 2398 of file getpot.h.

References get_value_no_default().

2399 {
2400  return get_value_no_default(VarName.c_str(),Default);
2401 }
T get_value_no_default(const char *VarName, const T &Default) const
Definition: getpot.h:2366
template<typename T >
T GetPot::get_value_no_default ( const char *  VarName,
const T &  Default,
unsigned  Idx 
) const
inline

vectors

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

Definition at line 2407 of file getpot.h.

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

2408 {
2409  // (*) recording of requested variables happens in '_request_variable()'
2410  const variable* sv = _request_variable(VarName);
2411  if (sv == 0)
2412  {
2413  getpot_cerr << "ERROR: cannot find variable "<<VarName<<std::endl;
2414  getpot_error();
2415  }
2416 
2417  const std::string* element = sv->get_element(Idx);
2418  if (element == 0)
2419  {
2420  getpot_cerr << "ERROR: cannot find index "<<Idx<<" of variable "<<VarName<<std::endl;
2421  getpot_error();
2422  }
2423  return _convert_to_type_no_default(VarName, *element, Default);
2424 }
#define getpot_error()
Definition: getpot.h:78
#define getpot_cerr
Definition: getpot.h:77
T _convert_to_type_no_default(const char *VarName, const std::string &String, const T &Default) const
Definition: getpot.h:1632
const variable * _request_variable(const char *) const
Definition: getpot.h:2671
template<typename T >
T GetPot::get_value_no_default ( const std::string &  VarName,
const T &  Default,
unsigned int  Idx 
) const
inline

Definition at line 2430 of file getpot.h.

References get_value_no_default().

2431 {
2432  return get_value_no_default(VarName.c_str(), Default, Idx);
2433 }
T get_value_no_default(const char *VarName, const T &Default) const
Definition: getpot.h:2366
STRING_VECTOR GetPot::get_variable_names ( ) const
inline

Definition at line 2573 of file getpot.h.

References _get_remaining_string(), prefix, and variables.

2574 {
2575  STRING_VECTOR result;
2576  std::vector<GetPot::variable>::const_iterator it = variables.begin();
2577  for (; it != variables.end(); ++it)
2578  {
2579  const std::string Tmp = _get_remaining_string((*it).name, prefix);
2580  if (Tmp != "")
2581  result.push_back(Tmp);
2582  }
2583  return result;
2584 }
std::string prefix
Definition: getpot.h:508
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
Definition: getpot.h:1736
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
std::vector< variable > variables
Definition: getpot.h:530
bool 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 2255 of file getpot.h.

2256 {
2257  std::string s = std::string(section_name);
2258  return this->have_section(s);
2259 }
bool have_section(const char *section_name) const
Definition: getpot.h:2255
bool 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 2262 of file getpot.h.

References section_list.

2263 {
2264  const char slash('/');
2265 
2266  std::string::const_reverse_iterator it = section_name.rbegin();
2267 
2268  bool found_section = false;
2269 
2270  // Check if section_name ends with a "/". If not, append it for the search since
2271  // the section names are stored with a "/" at the end.
2272  if( (*it) != slash )
2273  // We need to use a linear search because we can't sort section_list
2274  // without violating some assumptions. See libMesh #481 for more discussion.
2275  found_section = ( std::find(section_list.begin(), section_list.end(), section_name+slash) != section_list.end() );
2276  else
2277  found_section = ( std::find(section_list.begin(), section_list.end(), section_name) != section_list.end() );
2278 
2279  return found_section;
2280 }
STRING_VECTOR section_list
Definition: getpot.h:510
bool GetPot::have_variable ( const char *  VarName) const
inline

variables check for a variable

Definition at line 2236 of file getpot.h.

References _request_variable().

Referenced by have_variable().

2237 {
2238  const variable* sv = _request_variable(VarName);
2239 
2240  if (sv == 0)
2241  return false;
2242 
2243  return true;
2244 }
const variable * _request_variable(const char *) const
Definition: getpot.h:2671
bool GetPot::have_variable ( const std::string &  VarName) const
inline

Definition at line 2249 of file getpot.h.

References have_variable().

2250 {
2251  return have_variable(VarName.c_str());
2252 }
bool have_variable(const char *VarName) const
Definition: getpot.h:2236
void GetPot::init_multiple_occurrence ( )
inline

Definition at line 1861 of file getpot.h.

References disable_loop(), and reset_cursor().

1862 {
1863  disable_loop();
1864  reset_cursor();
1865 }
void reset_cursor()
Definition: getpot.h:1852
void disable_loop()
Definition: getpot.h:360
template<typename T >
T GetPot::next ( const T &  Default)
inline

get argument at cursor++

Definition at line 1913 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().

1914 {
1915  if (search_failed_f)
1916  return Default;
1917  cursor++;
1918  if (cursor >= argv.size())
1919  {
1920  cursor = getpot_cast_int<unsigned>(argv.size());
1921  return Default;
1922  }
1923 
1924  // (*) record requested argument for later ufo detection
1926 
1927  const std::string Remain = _get_remaining_string(argv[cursor], prefix);
1928 
1929  return Remain != "" ? _convert_to_type(Remain, Default) : Default;
1930 }
std::string prefix
Definition: getpot.h:508
void _record_argument_request(const std::string &Arg) const
Definition: getpot.h:2454
bool search_failed_f
Definition: getpot.h:518
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
Definition: getpot.h:1736
unsigned cursor
Definition: getpot.h:516
T _convert_to_type(const std::string &String, const T &Default) const
Definition: getpot.h:1567
STRING_VECTOR argv
Definition: getpot.h:515
const char * GetPot::next ( const char *  Default)
inline

Definition at line 1935 of file getpot.h.

References _internal_managed_copy(), and next().

1936 {
1937  return _internal_managed_copy(next(std::string(Default)));
1938 }
const char * _internal_managed_copy(const std::string &Arg) const
Definition: getpot.h:1705
T next(const T &Default)
Definition: getpot.h:1913
const char * GetPot::next_nominus ( )
inline

Definition at line 2189 of file getpot.h.

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

2190 {
2191  if (nominus_cursor < int(idx_nominus.size()) - 1)
2192  {
2193  const std::string Tmp = argv[idx_nominus[++nominus_cursor]];
2194 
2195  // (*) record for later ufo-detection
2197 
2198  return _internal_managed_copy(Tmp);
2199  }
2200 
2201  return 0;
2202 }
std::vector< unsigned > idx_nominus
Definition: getpot.h:525
void _record_argument_request(const std::string &Arg) const
Definition: getpot.h:2454
int nominus_cursor
Definition: getpot.h:524
const char * _internal_managed_copy(const std::string &Arg) const
Definition: getpot.h:1705
STRING_VECTOR argv
Definition: getpot.h:515
std::string GetPot::next_nominus_string ( )
inline

Definition at line 2206 of file getpot.h.

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

2207 {
2208  if (nominus_cursor < int(idx_nominus.size()) - 1)
2209  {
2210  const std::string Tmp = argv[idx_nominus[++nominus_cursor]];
2211 
2212  // (*) record for later ufo-detection
2214 
2215  return Tmp;
2216  }
2217 
2218  return "";
2219 }
std::vector< unsigned > idx_nominus
Definition: getpot.h:525
void _record_argument_request(const std::string &Arg) const
Definition: getpot.h:2454
int nominus_cursor
Definition: getpot.h:524
STRING_VECTOR argv
Definition: getpot.h:515
unsigned GetPot::nominus_size ( ) const
inline

Definition at line 413 of file getpot.h.

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

Definition at line 2170 of file getpot.h.

References _record_argument_request(), argv, and idx_nominus.

2171 {
2172  STRING_VECTOR nv;
2173  std::vector<unsigned>::const_iterator it = idx_nominus.begin();
2174  for (; it != idx_nominus.end(); ++it)
2175  {
2176  nv.push_back(argv[*it]);
2177 
2178  // (*) record for later ufo-detection
2179  // when a nominus vector is requested, the entire set of nominus arguments are
2180  // tagged as 'requested'
2182  }
2183  return nv;
2184 }
std::vector< unsigned > idx_nominus
Definition: getpot.h:525
void _record_argument_request(const std::string &Arg) const
Definition: getpot.h:2454
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
STRING_VECTOR argv
Definition: getpot.h:515
template<typename T >
T GetPot::operator() ( const char *  VarName,
const T &  Default 
) const
inline

scalar values

Definition at line 2284 of file getpot.h.

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

Referenced by operator()().

2285 {
2286  // (*) recording of requested variables happens in '_request_variable()'
2287  const variable* sv = _request_variable(VarName);
2288 
2289  if (sv == 0)
2290  return Default;
2291 
2292  return _convert_to_type(sv->original, Default);
2293 }
const variable * _request_variable(const char *) const
Definition: getpot.h:2671
T _convert_to_type(const std::string &String, const T &Default) const
Definition: getpot.h:1567
template<typename T >
T GetPot::operator() ( const std::string &  VarName,
const T &  Default 
) const
inline

Definition at line 2299 of file getpot.h.

References operator()().

2300 {
2301  return operator()(VarName.c_str(), Default);
2302 }
T operator()(const char *VarName, const T &Default) const
Definition: getpot.h:2284
const char * GetPot::operator() ( const char *  VarName,
const char *  Default 
) const
inline

Definition at line 2307 of file getpot.h.

References _internal_managed_copy().

2308 {
2309  return _internal_managed_copy(operator()(VarName, std::string(Default)));
2310 }
const char * _internal_managed_copy(const std::string &Arg) const
Definition: getpot.h:1705
const char * GetPot::operator() ( const std::string &  VarName,
const char *  Default 
) const
inline

Definition at line 2315 of file getpot.h.

References operator()().

2316 {
2317  return operator()(VarName.c_str(), Default);
2318 }
T operator()(const char *VarName, const T &Default) const
Definition: getpot.h:2284
template<typename T >
T GetPot::operator() ( const char *  VarName,
const T &  Default,
unsigned  Idx 
) const
inline

vectors

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

Definition at line 2324 of file getpot.h.

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

2325 {
2326  // (*) recording of requested variables happens in '_request_variable()'
2327  const variable* sv = _request_variable(VarName);
2328  if (sv == 0)
2329  return Default;
2330 
2331  const std::string* element = sv->get_element(Idx);
2332  if (element == 0)
2333  return Default;
2334  return _convert_to_type(*element, Default);
2335 }
const variable * _request_variable(const char *) const
Definition: getpot.h:2671
T _convert_to_type(const std::string &String, const T &Default) const
Definition: getpot.h:1567
template<typename T >
T GetPot::operator() ( const std::string &  VarName,
const T &  Default,
unsigned int  Idx 
) const
inline

Definition at line 2341 of file getpot.h.

References operator()().

2342 {
2343  return operator()(VarName.c_str(), Default, Idx);
2344 }
T operator()(const char *VarName, const T &Default) const
Definition: getpot.h:2284
GetPot & GetPot::operator= ( const GetPot Other)
inline

Definition at line 1030 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::variable::variable().

1031 {
1032  if (&Other == this)
1033  return *this;
1034 
1035  prefix = Other.prefix;
1036  section = Other.section;
1037  section_list = Other.section_list;
1038  argv = Other.argv;
1039  cursor = Other.cursor;
1040  search_loop_f = Other.search_loop_f;
1044  idx_nominus = Other.idx_nominus;
1045  variables = Other.variables;
1047  _comment_end = Other._comment_end;
1049  // #if !defined(GETPOT_DISABLE_MUTEX)
1050  // _getpot_mtx = Other._getpot_mtx;
1051  // #endif
1056 
1057  std::set<const char*, ltstr>::const_iterator my_it =
1059  const std::set<const char*, ltstr>::const_iterator my_end =
1061 
1062  for (; my_it != my_end; ++my_it)
1063  delete [] *my_it;
1064 
1066 
1067  std::set<const char*,ltstr>::const_iterator it =
1068  Other._internal_string_container.begin();
1069  const std::set<const char*,ltstr>::const_iterator end =
1070  Other._internal_string_container.end();
1071 
1072  for (; it != end; ++it)
1073  {
1074  const char* otherstr = *it;
1075  char* newcopy = new char[strlen(otherstr)+1];
1076  strncpy(newcopy, otherstr, strlen(otherstr)+1);
1077  this->_internal_string_container.insert(newcopy);
1078  }
1079 
1080  return *this;
1081 }
std::set< std::string > _requested_arguments
Definition: getpot.h:579
std::vector< unsigned > idx_nominus
Definition: getpot.h:525
std::string prefix
Definition: getpot.h:508
bool search_failed_f
Definition: getpot.h:518
STRING_VECTOR section_list
Definition: getpot.h:510
bool request_recording_f
Definition: getpot.h:583
bool search_loop_f
Definition: getpot.h:517
std::set< std::string > _requested_sections
Definition: getpot.h:581
std::set< std::string > _requested_variables
Definition: getpot.h:580
unsigned cursor
Definition: getpot.h:516
int nominus_cursor
Definition: getpot.h:524
std::string section
Definition: getpot.h:509
std::string _comment_end
Definition: getpot.h:536
std::string _field_separator
Definition: getpot.h:541
std::vector< variable > variables
Definition: getpot.h:530
STRING_VECTOR argv
Definition: getpot.h:515
std::set< std::string > overridden_vars
Definition: getpot.h:519
std::string _comment_start
Definition: getpot.h:535
std::set< const char *, ltstr > _internal_string_container
Definition: getpot.h:567
const char * GetPot::operator[] ( unsigned  Idx) const
inline

direct access to command line arguments

Definition at line 1874 of file getpot.h.

References argv, and libMesh::MeshTools::Generation::Private::idx().

1875 {
1876  return idx<argv.size() ? argv[idx].c_str() : 0;
1877 }
STRING_VECTOR argv
Definition: getpot.h:515
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
bool GetPot::options_contain ( const char *  FlagList) const
inline

flags

Definition at line 2101 of file getpot.h.

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

2102 {
2103  // go through all arguments that start with a '-' (but not '--')
2104  std::string str;
2105  STRING_VECTOR::const_iterator it = argv.begin();
2106  for (; it != argv.end(); ++it)
2107  {
2108  str = _get_remaining_string(*it, prefix);
2109 
2110  if (str.length() >= 2 && str[0] == '-' && str[1] != '-')
2111  if (_check_flags(str, FlagList))
2112  return true;
2113  }
2114  return false;
2115 }
std::string prefix
Definition: getpot.h:508
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
Definition: getpot.h:1736
bool _check_flags(const std::string &Str, const char *FlagList) const
Definition: getpot.h:2155
STRING_VECTOR argv
Definition: getpot.h:515
void GetPot::parse_command_line ( const int  argc_,
const char *const *  argv_,
const char *  FieldSeparator = 0x0 
)
inline

Re-initialization methods

Definition at line 804 of file getpot.h.

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

Referenced by GetPot().

806 {
808 
809  // if specified -> overwrite default string
810  if (FieldSeparator)
811  _field_separator = std::string(FieldSeparator);
812 
813  // -- make an internal copy of the argument list:
814  STRING_VECTOR _apriori_argv;
815  // -- for the sake of clarity: we do want to include the first
816  // argument of the first parsing source in the argument vector!
817  // it will not be a nominus argument, though. This gives us a
818  // minimum vector size of one which facilitates error checking
819  // in many functions. Also the user will be able to retrieve
820  // the name of his application or input file by "get[0]"
821  _apriori_argv.push_back(std::string(argv_[0]));
822  for (int i=1; i<argc_; i++)
823  {
824  std::string tmp(argv_[i]); // recall the problem with temporaries,
825  _apriori_argv.push_back(tmp); // reference counting in arguement lists ...
826  }
827  _parse_argument_vector(_apriori_argv);
828 }
void _basic_initialization()
Definition: getpot.h:720
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
std::string _field_separator
Definition: getpot.h:541
void _parse_argument_vector(const STRING_VECTOR &ARGV)
Definition: getpot.h:1129
void 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 897 of file getpot.h.

References getpot_file_error, and parse_input_stream().

Referenced by _parse_argument_vector(), and GetPot().

901 {
902  std::ifstream input(FileName.c_str());
903 
904  if (!input)
905  getpot_file_error(FileName);
906 
907  this->parse_input_stream(input,FileName,CommentStart,CommentEnd,FieldSeparator);
908 }
void parse_input_stream(std::istream &FileStream, const std::string &FileName=std::string("ParsedFromStream"), const std::string &CommentStart=std::string("#"), const std::string &CommentEnd=std::string("\n"), const std::string &FieldSeparator=std::string(" \t\n"))
Definition: getpot.h:945
#define getpot_file_error(filename)
Definition: getpot.h:79
void 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 945 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().

950 {
952 
953  // overwrite default strings
954  _comment_start = std::string(CommentStart);
955  _comment_end = std::string(CommentEnd);
956  _field_separator = FieldSeparator;
957 
958  STRING_VECTOR _apriori_argv;
959  // -- the first element of the argument vector stores the name of
960  // the first parsing source; however, this element is not
961  // parsed for variable assignments or nominuses.
962  //
963  // Regardless, we don't add more than one name to the argument
964  // vector. In this case, we're parsing from a stream, so we'll
965  // hardcode the "filename" to "ParsedFromStream"
966  _apriori_argv.push_back(FileName);
967 
968  STRING_VECTOR args = _read_in_stream(FileStream);
969  _apriori_argv.insert(_apriori_argv.begin()+1, args.begin(), args.end());
970  _parse_argument_vector(_apriori_argv);
971 }
void _basic_initialization()
Definition: getpot.h:720
STRING_VECTOR _read_in_stream(std::istream &istr)
Definition: getpot.h:1232
std::string _comment_end
Definition: getpot.h:536
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
std::string _field_separator
Definition: getpot.h:541
void _parse_argument_vector(const STRING_VECTOR &ARGV)
Definition: getpot.h:1129
std::string _comment_start
Definition: getpot.h:535
int GetPot::print ( std::ostream &  out_stream = std::cout) const
inline

output Print everything

Definition at line 2686 of file getpot.h.

References argv.

2687 {
2688  out_stream << "argc = " << argv.size() << std::endl;
2689  STRING_VECTOR::const_iterator it = argv.begin();
2690  for (; it != argv.end(); ++it)
2691  out_stream << *it << std::endl;
2692  out_stream << std::endl;
2693  return 1;
2694 }
STRING_VECTOR argv
Definition: getpot.h:515
int 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 2704 of file getpot.h.

References argv.

2705 {
2706  STRING_VECTOR::const_iterator it = argv.begin();
2707  it += skip_count;
2708  for (; it != argv.end(); ++it)
2709  {
2710  out_stream << custom_prefix;
2711  out_stream << *it << std::endl;
2712  }
2713  out_stream << std::endl;
2714  return 1;
2715 }
STRING_VECTOR argv
Definition: getpot.h:515
void GetPot::reset_cursor ( )
inline

reset cursor to position '1'

Definition at line 1852 of file getpot.h.

References cursor, and search_failed_f.

Referenced by init_multiple_occurrence().

1853 {
1854  search_failed_f = false;
1855  cursor = 0;
1856 }
bool search_failed_f
Definition: getpot.h:518
unsigned cursor
Definition: getpot.h:516
void GetPot::reset_nominus_cursor ( )
inline

nominus arguments

Definition at line 2224 of file getpot.h.

References nominus_cursor.

2225 {
2226  nominus_cursor = -1;
2227 }
int nominus_cursor
Definition: getpot.h:524
bool GetPot::search ( const char *  option)
inline

search for a certain option and set cursor to position

Definition at line 1763 of file getpot.h.

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

Referenced by follow(), and search().

1764 {
1765  unsigned OldCursor = cursor;
1766  const std::string SearchTerm = prefix + Option;
1767 
1768  // (*) record requested arguments for later ufo detection
1769  _record_argument_request(SearchTerm);
1770 
1771  if (OldCursor >= argv.size())
1772  OldCursor = getpot_cast_int<unsigned>(argv.size() - 1);
1773  search_failed_f = true;
1774 
1775  // (*) first loop from cursor position until end
1776  for (unsigned c = cursor; c < argv.size(); c++)
1777  {
1778  if (argv[c] == SearchTerm)
1779  {
1780  cursor = c;
1781  search_failed_f = false;
1782  return true;
1783  }
1784  }
1785  if (!search_loop_f)
1786  return false;
1787 
1788  // (*) second loop from 0 to old cursor position
1789  for (unsigned c = 1; c <= OldCursor; c++)
1790  {
1791  if (argv[c] == SearchTerm)
1792  {
1793  cursor = c;
1794  search_failed_f = false;
1795  return true;
1796  }
1797  }
1798 
1799  // in case nothing is found the cursor stays where it was
1800  return false;
1801 }
std::string prefix
Definition: getpot.h:508
void _record_argument_request(const std::string &Arg) const
Definition: getpot.h:2454
bool search_failed_f
Definition: getpot.h:518
bool search_loop_f
Definition: getpot.h:517
unsigned cursor
Definition: getpot.h:516
STRING_VECTOR argv
Definition: getpot.h:515
bool GetPot::search ( const std::string &  option)
inline

Definition at line 1754 of file getpot.h.

References search().

1755 {
1756  return search(Option.c_str());
1757 }
bool search(const char *option)
Definition: getpot.h:1763
bool GetPot::search ( unsigned  No,
const char *  P,
  ... 
)
inline

Definition at line 1806 of file getpot.h.

References _record_argument_request(), and search().

1807 {
1808  // (*) recording the requested arguments happens in subroutine 'search'
1809  if (No == 0)
1810  return false;
1811 
1812  // search for the first argument
1813  if (search(P) == true)
1814  return true;
1815 
1816  // start interpreting variable argument list
1817  va_list ap;
1818  va_start(ap, P);
1819  unsigned i = 1;
1820  for (; i < No; i++)
1821  {
1822  char* Opt = va_arg(ap, char *);
1823  // (*) search records itself for later ufo detection
1824  if (search(Opt) == true)
1825  break;
1826  }
1827 
1828  if (i < No)
1829  {
1830  i++;
1831  // loop was left before end of array --> hit but
1832  // make sure that the rest of the search terms is marked
1833  // as requested.
1834  for (; i < No; i++)
1835  {
1836  char* Opt = va_arg(ap, char *);
1837  // (*) record requested arguments for later ufo detection
1839  }
1840  va_end(ap);
1841  return true;
1842  }
1843 
1844  va_end(ap);
1845  // loop was left normally --> no hit
1846  return false;
1847 }
void _record_argument_request(const std::string &Arg) const
Definition: getpot.h:2454
bool search(const char *option)
Definition: getpot.h:1763
bool GetPot::search_failed ( ) const
inline

Definition at line 355 of file getpot.h.

355 { return search_failed_f; }
bool search_failed_f
Definition: getpot.h:518
template<typename T >
void 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 2519 of file getpot.h.

References _set_variable().

Referenced by set().

2520 {
2521  std::ostringstream string_value;
2522  string_value << Value;
2523  _set_variable(VarName, string_value.str().c_str(), Requested);
2524 }
void _set_variable(const std::string &VarName, const std::string &Value, const bool Requested)
Definition: getpot.h:2500
template<typename T >
void GetPot::set ( const std::string &  VarName,
const T &  Value,
const bool  Requested = true 
)
inline

Definition at line 2530 of file getpot.h.

References set().

2531 {
2532  set(VarName.c_str(), Value, Requested);
2533 }
void set(const char *VarName, const T &Value, const bool Requested=true)
Definition: getpot.h:2519
void GetPot::set ( const char *  VarName,
const char *  Value,
const bool  Requested = true 
)
inline

Definition at line 2538 of file getpot.h.

References _set_variable().

2539 {
2540  _set_variable(VarName, Value, Requested);
2541 }
void _set_variable(const std::string &VarName, const std::string &Value, const bool Requested)
Definition: getpot.h:2500
void GetPot::set ( const std::string &  VarName,
const char *  Value,
const bool  Requested = true 
)
inline

Definition at line 2546 of file getpot.h.

References set().

2547 {
2548  set(VarName.c_str(), Value, Requested);
2549 }
void set(const char *VarName, const T &Value, const bool Requested=true)
Definition: getpot.h:2519
void GetPot::set_prefix ( const char *  Prefix)
inline

cursor oriented functions

Definition at line 354 of file getpot.h.

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

Definition at line 1903 of file getpot.h.

References argv.

Referenced by _DBE_expand().

1904 {
1905  return getpot_cast_int<unsigned>(argv.size());
1906 }
STRING_VECTOR argv
Definition: getpot.h:515
STRING_VECTOR GetPot::unidentified_arguments ( unsigned  Number,
const char *  Known,
  ... 
) const
inline

unidentified flying objects

Definition at line 3444 of file getpot.h.

References unidentified_arguments().

3446 {
3447  std::set<std::string> known_arguments;
3448 
3449  // (1) create a vector of known arguments
3450  if (Number == 0)
3451  return STRING_VECTOR();
3452 
3453  va_list ap;
3454  va_start(ap, KnownArgument1);
3455  known_arguments.insert(std::string(KnownArgument1));
3456  for (unsigned i=1; i<Number; i++)
3457  known_arguments.insert(std::string(va_arg(ap, char *)));
3458  va_end(ap);
3459 
3460  return unidentified_arguments(known_arguments);
3461 }
STRING_VECTOR unidentified_arguments() const
Definition: getpot.h:3466
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
STRING_VECTOR GetPot::unidentified_arguments ( const std::set< std::string > &  Knowns) const
inline

Definition at line 3484 of file getpot.h.

References _get_remaining_string(), argv, and prefix.

3485 {
3486  STRING_VECTOR ufos;
3487  STRING_VECTOR::const_iterator it = argv.begin();
3488  ++it; // forget about argv[0] (application or filename)
3489  for (; it != argv.end(); ++it)
3490  {
3491  // -- argument belongs to prefixed section ?
3492  const std::string arg = _get_remaining_string(*it, prefix);
3493  if (arg == "")
3494  continue;
3495 
3496  // -- check if in list
3497  if (Knowns.find(arg) == Knowns.end())
3498  ufos.push_back(*it);
3499  }
3500  return ufos;
3501 }
std::string prefix
Definition: getpot.h:508
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
Definition: getpot.h:1736
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
STRING_VECTOR argv
Definition: getpot.h:515
STRING_VECTOR GetPot::unidentified_arguments ( const std::vector< std::string > &  Knowns) const
inline

Definition at line 3474 of file getpot.h.

References unidentified_arguments().

3475 {
3476  // We use set for efficiency, but want to support vector inputs for
3477  // backwards compatibility.
3478  return unidentified_arguments(std::set<std::string> (Knowns.begin(), Knowns.end()));
3479 }
STRING_VECTOR unidentified_arguments() const
Definition: getpot.h:3466
STRING_VECTOR GetPot::unidentified_arguments ( ) const
inline

Definition at line 3466 of file getpot.h.

References _requested_arguments.

Referenced by unidentified_arguments(), and unidentified_options().

3467 {
3469 }
std::set< std::string > _requested_arguments
Definition: getpot.h:579
STRING_VECTOR unidentified_arguments() const
Definition: getpot.h:3466
std::string GetPot::unidentified_flags ( const char *  Known,
int  ArgumentNumber = -1 
) const
inline

Definition at line 3582 of file getpot.h.

References _get_remaining_string(), argv, and prefix.

3583 {
3584  std::string ufos;
3585  // STRING_VECTOR known_arguments;
3586  std::string KFL(KnownFlagList);
3587 
3588  // (2) iteration over '-' arguments (options)
3589  if (ArgumentNumber == -1)
3590  {
3591  STRING_VECTOR::const_iterator it = argv.begin();
3592  ++it; // forget about argv[0] (application or filename)
3593  for (; it != argv.end(); ++it)
3594  {
3595  // -- argument belongs to prefixed section ?
3596  const std::string arg = _get_remaining_string(*it, prefix);
3597  if (arg == "") continue;
3598 
3599  // -- does arguments start with '-' (but not '--')
3600  if (arg.length() < 2)
3601  continue;
3602 
3603  else if (arg[0] != '-')
3604  continue;
3605 
3606  else if (arg[1] == '-')
3607  continue;
3608 
3609  // -- check out if flags inside option are contained in KnownFlagList
3610  const char* p=arg.c_str();
3611  p++; // skip starting minus
3612  for (; *p != '\0' ; p++)
3613  if (KFL.find(*p) == std::string::npos) ufos += *p;
3614  }
3615  }
3616  // (1) check specific argument
3617  else
3618  {
3619  // -- only check arguments that start with prefix
3620  int no_matches = 0;
3621  for (unsigned i=1; i<argv.size(); i++)
3622  {
3623  const std::string Remain = _get_remaining_string(argv[i], prefix);
3624  if (Remain != "")
3625  {
3626  no_matches++;
3627  if (no_matches == ArgumentNumber)
3628  {
3629  // -- the right argument number inside the section is found
3630  // => check it for flags
3631  const char* p = Remain.c_str();
3632  p++; // skip starting minus
3633  for (; *p != '\0' ; p++)
3634  if (KFL.find(*p) == std::string::npos) ufos += *p;
3635  return ufos;
3636  }
3637  }
3638  }
3639  }
3640  return ufos;
3641 }
std::string prefix
Definition: getpot.h:508
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
Definition: getpot.h:1736
STRING_VECTOR argv
Definition: getpot.h:515
STRING_VECTOR GetPot::unidentified_nominuses ( unsigned  Number,
const char *  Known,
  ... 
) const
inline

Definition at line 3779 of file getpot.h.

References unidentified_nominuses().

3780 {
3781  std::set<std::string> known_nominuses;
3782 
3783  // create vector of known arguments
3784  if (Number == 0)
3785  return STRING_VECTOR();
3786 
3787  va_list ap;
3788  va_start(ap, Known);
3789  known_nominuses.insert(std::string(Known));
3790  for (unsigned i=1; i<Number; i++)
3791  {
3792  std::string tmp = std::string(va_arg(ap, char *));
3793  if (tmp.length() == 0)
3794  continue;
3795  known_nominuses.insert(tmp);
3796  }
3797  va_end(ap);
3798 
3799  return unidentified_nominuses(known_nominuses);
3800 }
STRING_VECTOR unidentified_nominuses() const
Definition: getpot.h:3805
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
STRING_VECTOR GetPot::unidentified_nominuses ( const std::set< std::string > &  Knowns) const
inline

Definition at line 3830 of file getpot.h.

References _get_remaining_string(), argv, and prefix.

3831 {
3832  STRING_VECTOR ufos;
3833 
3834  // (2) iterate over all arguments
3835  STRING_VECTOR::const_iterator it = argv.begin();
3836  ++it; // forget about argv[0] (application or filename)
3837  for (; it != argv.end(); ++it)
3838  {
3839  // -- check if nominus part of prefix
3840  const std::string arg = _get_remaining_string(*it, prefix);
3841  if (arg == "")
3842  continue;
3843 
3844  if (arg.length() < 1)
3845  continue;
3846 
3847  // option ? --> not a nomius
3848  if (arg[0] == '-')
3849  continue;
3850 
3851  // section ? --> not a real nominus
3852  if (arg[0] == '[' && arg[arg.length()-1] == ']')
3853  continue;
3854 
3855  // variable definition ? --> not a real nominus
3856  bool continue_f = false;
3857  for (unsigned i=0; i<arg.length() ; i++)
3858  if (arg[i] == '=')
3859  {
3860  continue_f = true;
3861  break;
3862  }
3863 
3864  if (continue_f)
3865  continue;
3866 
3867  // real nominuses are compared with the given list
3868  if (Knowns.find(arg) == Knowns.end())
3869  ufos.push_back(*it);
3870  }
3871  return ufos;
3872 }
std::string prefix
Definition: getpot.h:508
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
Definition: getpot.h:1736
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
STRING_VECTOR argv
Definition: getpot.h:515
STRING_VECTOR GetPot::unidentified_nominuses ( const std::vector< std::string > &  Knowns) const
inline

Definition at line 3820 of file getpot.h.

References unidentified_nominuses().

3821 {
3822  // We use set for efficiency, but want to support vector inputs for
3823  // backwards compatibility.
3824  return unidentified_nominuses(std::set<std::string> (Knowns.begin(), Knowns.end()));
3825 }
STRING_VECTOR unidentified_nominuses() const
Definition: getpot.h:3805
STRING_VECTOR GetPot::unidentified_nominuses ( ) const
inline

Definition at line 3805 of file getpot.h.

References _requested_arguments.

Referenced by unidentified_nominuses().

3806 {
3807  // -- every nominus is an argument.
3808  // -- the set of requested arguments contains the set of requested nominuss.
3809  // -- IF the set of requested arguments contains unrequested nominuss,
3810  // THEN they were requested as 'follow' and 'next' arguments and not as real nominuses.
3811  //
3812  // => it is not necessary to separate requested nominus from the list
3813 
3815 }
std::set< std::string > _requested_arguments
Definition: getpot.h:579
STRING_VECTOR unidentified_nominuses() const
Definition: getpot.h:3805
STRING_VECTOR GetPot::unidentified_options ( unsigned  Number,
const char *  Known,
  ... 
) const
inline

Definition at line 3506 of file getpot.h.

References unidentified_options().

3508 {
3509  std::set<std::string> known_options;
3510 
3511  // (1) create a vector of known arguments
3512  if (Number == 0)
3513  return STRING_VECTOR();
3514 
3515  va_list ap;
3516  va_start(ap, KnownOption1);
3517  known_options.insert(std::string(KnownOption1));
3518  for (unsigned i=1; i<Number; i++)
3519  known_options.insert(std::string(va_arg(ap, char *)));
3520  va_end(ap);
3521 
3522  return unidentified_options(known_options);
3523 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
STRING_VECTOR unidentified_options() const
Definition: getpot.h:3528
STRING_VECTOR GetPot::unidentified_options ( const std::set< std::string > &  Knowns) const
inline

Definition at line 3552 of file getpot.h.

References _get_remaining_string(), argv, and prefix.

3553 {
3554  STRING_VECTOR ufos;
3555  STRING_VECTOR::const_iterator it = argv.begin();
3556  ++it; // forget about argv[0] (application or filename)
3557  for (; it != argv.end(); ++it)
3558  {
3559  // -- argument belongs to prefixed section ?
3560  const std::string arg = _get_remaining_string(*it, prefix);
3561  if (arg == "")
3562  continue;
3563 
3564  // is argument really an option (starting with '-') ?
3565  if (arg.length() < 1 || arg[0] != '-')
3566  continue;
3567 
3568  if (Knowns.find(arg) == Knowns.end())
3569  ufos.push_back(*it);
3570  }
3571 
3572  return ufos;
3573 }
std::string prefix
Definition: getpot.h:508
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
Definition: getpot.h:1736
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
STRING_VECTOR argv
Definition: getpot.h:515
STRING_VECTOR GetPot::unidentified_options ( const std::vector< std::string > &  Knowns) const
inline

Definition at line 3542 of file getpot.h.

References unidentified_options().

3543 {
3544  // We use set for efficiency, but want to support vector inputs for
3545  // backwards compatibility.
3546  return unidentified_options(std::set<std::string> (Knowns.begin(), Knowns.end()));
3547 }
STRING_VECTOR unidentified_options() const
Definition: getpot.h:3528
STRING_VECTOR GetPot::unidentified_options ( ) const
inline

Definition at line 3528 of file getpot.h.

References _requested_arguments, and unidentified_arguments().

Referenced by unidentified_options().

3529 {
3530  // -- every option is an argument.
3531  // -- the set of requested arguments contains the set of requested options.
3532  // -- IF the set of requested arguments contains unrequested options,
3533  // THEN they were requested as 'follow' and 'next' arguments and not as real options.
3534  //
3535  // => it is not necessary to separate requested options from the list
3537 }
std::set< std::string > _requested_arguments
Definition: getpot.h:579
STRING_VECTOR unidentified_arguments() const
Definition: getpot.h:3466
STRING_VECTOR GetPot::unidentified_sections ( unsigned  Number,
const char *  Known,
  ... 
) const
inline

Definition at line 3707 of file getpot.h.

References unidentified_sections().

3709 {
3710  std::set<std::string> known_sections;
3711 
3712  // (1) create a vector of known arguments
3713  if (Number == 0)
3714  return STRING_VECTOR();
3715 
3716  va_list ap;
3717  va_start(ap, KnownSection1);
3718  known_sections.insert(std::string(KnownSection1));
3719  for (unsigned i=1; i<Number; i++)
3720  {
3721  std::string tmp = std::string(va_arg(ap, char *));
3722 
3723  if (tmp.length() == 0)
3724  continue;
3725 
3726  if (tmp[tmp.length()-1] != '/')
3727  tmp += '/';
3728 
3729  known_sections.insert(tmp);
3730  }
3731  va_end(ap);
3732 
3733  return unidentified_sections(known_sections);
3734 }
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
STRING_VECTOR unidentified_sections() const
Definition: getpot.h:3739
STRING_VECTOR GetPot::unidentified_sections ( const std::set< std::string > &  Knowns) const
inline

Definition at line 3757 of file getpot.h.

References _get_remaining_string(), prefix, section_list, and victorate.

3758 {
3759  STRING_VECTOR ufos;
3760 
3761  victorate(std::string, section_list, it)
3762  {
3763  // -- check if section conform to prefix
3764  const std::string sec_name = _get_remaining_string(*it, prefix);
3765  if (sec_name == "")
3766  continue;
3767 
3768  // -- check if section is known
3769  if (Knowns.find(sec_name) == Knowns.end())
3770  ufos.push_back(*it);
3771  }
3772 
3773  return ufos;
3774 }
#define victorate(TYPE, VARIABLE, ITERATOR)
Definition: getpot.h:134
std::string prefix
Definition: getpot.h:508
STRING_VECTOR section_list
Definition: getpot.h:510
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
Definition: getpot.h:1736
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
STRING_VECTOR GetPot::unidentified_sections ( const std::vector< std::string > &  Knowns) const
inline

Definition at line 3747 of file getpot.h.

References unidentified_sections().

3748 {
3749  // We use set for efficiency, but want to support vector inputs for
3750  // backwards compatibility.
3751  return unidentified_sections(std::set<std::string> (Knowns.begin(), Knowns.end()));
3752 }
STRING_VECTOR unidentified_sections() const
Definition: getpot.h:3739
STRING_VECTOR GetPot::unidentified_sections ( ) const
inline

Definition at line 3739 of file getpot.h.

References _requested_sections.

Referenced by unidentified_sections().

3740 {
3742 }
std::set< std::string > _requested_sections
Definition: getpot.h:581
STRING_VECTOR unidentified_sections() const
Definition: getpot.h:3739
STRING_VECTOR GetPot::unidentified_variables ( unsigned  Number,
const char *  Known,
  ... 
) const
inline

Definition at line 3646 of file getpot.h.

References unidentified_variables().

3648 {
3649  std::set<std::string> known_variables;
3650 
3651  // create vector of known arguments
3652  if (Number == 0)
3653  return STRING_VECTOR();
3654 
3655  va_list ap;
3656  va_start(ap, KnownVariable1);
3657  known_variables.insert(std::string(KnownVariable1));
3658  for (unsigned i=1; i<Number; i++)
3659  known_variables.insert(std::string(va_arg(ap, char *)));
3660  va_end(ap);
3661 
3662  return unidentified_variables(known_variables);
3663 }
STRING_VECTOR unidentified_variables() const
Definition: getpot.h:3699
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
STRING_VECTOR GetPot::unidentified_variables ( const std::set< std::string > &  Knowns) const
inline

Definition at line 3678 of file getpot.h.

References _get_remaining_string(), prefix, variables, and victorate.

3679 {
3680  STRING_VECTOR ufos;
3681 
3683  {
3684  // -- check if variable has specific prefix
3685  const std::string var_name = _get_remaining_string((*it).name, prefix);
3686  if (var_name == "")
3687  continue;
3688 
3689  // -- check if variable is known
3690  if (Knowns.find(var_name) == Knowns.end())
3691  ufos.push_back((*it).name);
3692  }
3693  return ufos;
3694 }
#define victorate(TYPE, VARIABLE, ITERATOR)
Definition: getpot.h:134
std::string prefix
Definition: getpot.h:508
const std::string _get_remaining_string(const std::string &String, const std::string &Start) const
Definition: getpot.h:1736
std::vector< std::string > STRING_VECTOR
Definition: getpot.h:132
std::vector< variable > variables
Definition: getpot.h:530
STRING_VECTOR GetPot::unidentified_variables ( const std::vector< std::string > &  Knowns) const
inline

Definition at line 3668 of file getpot.h.

References unidentified_variables().

3669 {
3670  // We use set for efficiency, but want to support vector inputs for
3671  // backwards compatibility.
3672  return unidentified_variables(std::set<std::string> (Knowns.begin(), Knowns.end()));
3673 }
STRING_VECTOR unidentified_variables() const
Definition: getpot.h:3699
STRING_VECTOR GetPot::unidentified_variables ( ) const
inline

Definition at line 3699 of file getpot.h.

References _requested_variables.

Referenced by unidentified_variables().

3700 {
3702 }
std::set< std::string > _requested_variables
Definition: getpot.h:580
STRING_VECTOR unidentified_variables() const
Definition: getpot.h:3699
unsigned GetPot::vector_variable_size ( const char *  VarName) const
inline

Definition at line 2554 of file getpot.h.

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

Referenced by vector_variable_size().

2555 {
2556  const variable* sv = _request_variable(VarName);
2557  if (sv == 0)
2558  return 0;
2559  return (unsigned)(sv->value.size());
2560 }
const variable * _request_variable(const char *) const
Definition: getpot.h:2671
unsigned GetPot::vector_variable_size ( const std::string &  VarName) const
inline

Definition at line 2565 of file getpot.h.

References vector_variable_size().

2566 {
2567  return vector_variable_size(VarName.c_str());
2568 }
unsigned vector_variable_size(const char *VarName) const
Definition: getpot.h:2554

Member Data Documentation

std::string GetPot::_comment_end
private

Definition at line 536 of file getpot.h.

Referenced by _parse_argument_vector(), _skip_whitespace(), operator=(), and parse_input_stream().

std::string GetPot::_comment_start
private

comment delimiters

Definition at line 535 of file getpot.h.

Referenced by _parse_argument_vector(), _read_in_stream(), _skip_whitespace(), operator=(), and parse_input_stream().

std::string GetPot::_field_separator
private

field separator (separating elements of a vector)

Definition at line 541 of file getpot.h.

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

std::set<const char*, ltstr> 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 567 of file getpot.h.

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

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

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

Definition at line 579 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::_requested_sections
mutableprivate
std::set<std::string> GetPot::_requested_variables
mutableprivate
unsigned GetPot::cursor
private

Definition at line 516 of file getpot.h.

Referenced by _match_starting_string(), direct_follow(), next(), operator=(), reset_cursor(), and search().

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 557 of file getpot.h.

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

nominus vector

Definition at line 524 of file getpot.h.

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

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

Definition at line 519 of file getpot.h.

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

bool GetPot::request_recording_f
private
bool GetPot::search_failed_f
private

Definition at line 518 of file getpot.h.

Referenced by _match_starting_string(), next(), operator=(), reset_cursor(), and search().

bool GetPot::search_loop_f
private

Definition at line 517 of file getpot.h.

Referenced by _match_starting_string(), operator=(), and search().

std::string GetPot::section
private
std::vector<variable> GetPot::variables
private

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

Definition at line 530 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: