Poster of Linux kernelThe best gift for a Linux geek
GetPot

GetPot

Section: C Library Functions (3) Updated: Thu Apr 7 2011
Local index Up
 

NAME

GetPot -  

SYNOPSIS


#include <getpot.h>  

Classes


struct variable
 

Public Member Functions


GetPot ()

GetPot (const GetPot &)

GetPot (int argc_, char **argv_)

GetPot (const char *FileName)

GetPot (const std::string &FileName)

~GetPot ()

GetPot & operator= (const GetPot &)

void parse_command_line (int argc_, char **argv_)

void parse_input_file (const std::string &FileName)

void parse_input_file (const char *FileName)

const char * operator[] (unsigned Idx) const

int get (unsigned Idx, int Default) const

double get (unsigned Idx, double 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 operator() (const char *VarName, bool Default) const

int operator() (const char *VarName, int Default) const

double operator() (const char *VarName, double Default) const

long double operator() (const char *VarName, long double Default) const

const char * operator() (const char *VarName, const char *Default) const

std::string operator() (const char *VarName, const std::string &Default) const

int operator() (const char *VarName, int Default, unsigned Idx) const

double operator() (const char *VarName, double Default, unsigned Idx) const

const char * operator() (const char *VarName, const char *Default, unsigned Idx) const

unsigned vector_variable_size (const char *VarName) const

std::vector< std::string > get_variable_names () const

std::vector< std::string > get_section_names () const

void set_prefix (const char *Prefix)

void set_prefix (const std::string &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,...)

int next (int Default)

double next (double Default)

const char * next (const char *Default)

std::string next (const std::string &Default)

int follow (int Default, const char *Option)

double follow (double Default, const char *Option)

const char * follow (const char *Default, const char *Option)

int follow (int Default, unsigned No, const char *Option,...)

double follow (double Default, unsigned No, const char *Option,...)

const char * follow (const char *Default, unsigned No, const char *Option,...)

int direct_follow (int Default, const char *Option)

double direct_follow (double Default, const char *Option)

const char * direct_follow (const char *Default, const char *Option)

void reset_nominus_cursor ()

std::vector< std::string > nominus_vector () const

unsigned nominus_size () const

const char * next_nominus ()

std::vector< std::string > unidentified_arguments (const std::vector< std::string > &Knowns) const

std::vector< std::string > unidentified_options (const std::vector< std::string > &Knowns) const

std::vector< std::string > unidentified_variables (const std::vector< std::string > &Knowns) const

std::vector< std::string > unidentified_sections (const std::vector< std::string > &Knowns) const

std::vector< std::string > unidentified_nominuses (const std::vector< std::string > &Knowns) const

std::string unidentified_flags (const char *Known, int ArgumentNumber) const

std::vector< std::string > unidentified_arguments (unsigned Number, const char *Known,...) const

std::vector< std::string > unidentified_options (unsigned Number, const char *Known,...) const

std::vector< std::string > unidentified_variables (unsigned Number, const char *Known,...) const

std::vector< std::string > unidentified_sections (unsigned Number, const char *Known,...) const

std::vector< std::string > unidentified_nominuses (unsigned Number, const char *Known,...) const

int print () const
 

Private Member Functions


void __basic_initialization ()

void __parse_argument_vector (const std::vector< std::string > &ARGV)

const variable * __find_variable (const char *) const

const char * __match_starting_string (const char *StartString)

bool __check_flags (const std::string &Str, const char *FlagList) const

int __convert_to_type (const std::string &String, int Default) const

double __convert_to_type (const std::string &String, double Default) const

long double __convert_to_type (const std::string &String, long double Default) const

bool __convert_to_type (const std::string &String, bool Default) const

const std::string __get_remaining_string (const std::string &String, const std::string &Start) const

bool __search_string_vector (const std::vector< std::string > &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)

std::vector< std::string > __read_in_stream (std::istream &istr)

std::vector< std::string > __read_in_file (const char *FileName)

std::string __process_section_label (const std::string &Section, std::vector< std::string > &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)

std::vector< std::string > __DBE_get_expr_list (const std::string &str, const unsigned ExpectedNumber)

std::string __double2string (double Value) const

std::string __int2string (const int &Value) const
 

Private Attributes


std::string prefix

std::string section

std::vector< std::string > section_list

std::vector< std::string > argv

unsigned cursor

bool search_loop_f

bool search_failed_f

int nominus_cursor

std::vector< unsigned > idx_nominus

std::vector< variable > variables
 

Detailed Description

Definition at line 59 of file getpot.h.  

Constructor & Destructor Documentation

 

GetPot::GetPot () [inline]

Definition at line 309 of file getpot.h.

References __basic_initialization().

{
  __basic_initialization();
}
 

GetPot::GetPot (const GetPot &Other) [inline]

Definition at line 341 of file getpot.h.

References operator=().

{
  GetPot::operator=(Other);
}
 

GetPot::GetPot (intargc_, char **argv_) [inline]

Definition at line 317 of file getpot.h.

References parse_command_line().

{
  parse_command_line (argc_, argv_);
}
 

GetPot::GetPot (const char *FileName) [inline]

Definition at line 325 of file getpot.h.

References parse_input_file().

{
  parse_input_file (FileName);
}
 

GetPot::GetPot (const std::string &FileName) [inline]

Definition at line 333 of file getpot.h.

References parse_input_file().

{
  parse_input_file (FileName);
}
 

GetPot::~GetPot () [inline]

Definition at line 349 of file getpot.h.

{
}
 

Member Function Documentation

 

void GetPot::__basic_initialization () [inline, private]

Definition at line 299 of file getpot.h.

References cursor, nominus_cursor, prefix, search_failed_f, search_loop_f, and section.

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

{
  cursor = 0;              nominus_cursor = -1;
  search_failed_f = true;  search_loop_f = true;
  prefix = '';             section = '';      
}
 

bool GetPot::__check_flags (const std::string &Str, const char *FlagList) const [inline, private]

Definition at line 1156 of file getpot.h.

Referenced by argument_contains(), and options_contain().

{
  for(const char* p=FlagList; *p != ' ' ; p++)
    if( Str.find(*p) != std::string::npos ) return true; // found something
  return false;
}
 

int GetPot::__convert_to_type (const std::string &String, intDefault) const [inline, private]

Definition at line 721 of file getpot.h.

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

{
  int tmp;
  if( std::sscanf(String.c_str(),'%i', &tmp) != 1 ) return Default;
  return tmp;    
}
 

double GetPot::__convert_to_type (const std::string &String, doubleDefault) const [inline, private]

Definition at line 699 of file getpot.h.

{
  double tmp;
  if( std::sscanf(String.c_str(),'%lf', &tmp) != 1 ) return Default;
  return tmp;
}
 

long double GetPot::__convert_to_type (const std::string &String, long doubleDefault) const [inline, private]

Definition at line 710 of file getpot.h.

{
  long double tmp;
  if( std::sscanf(String.c_str(),'%Lf', &tmp) != 1 ) return Default;
  return tmp;
}
 

bool GetPot::__convert_to_type (const std::string &String, boolDefault) const [inline, private]

Definition at line 731 of file getpot.h.

{
  std::string newstring(String);
  //std::transform(newstring.begin(), newstring.end(), newstring.begin(), std::toupper);
  for (unsigned int i=0; i<newstring.length(); ++i)
  {
    newstring[i]=toupper(newstring[i]);
  }
  
  if (newstring.find('TRUE')!=std::string::npos)  return true;
  if (newstring.find('FALSE')!=std::string::npos) return false;
  return Default;
}
 

std::string GetPot::__DBE_expand (const std::string &str) [inline, private]

Definition at line 1543 of file getpot.h.

References __convert_to_type(), __DBE_get_expr_list(), __DBE_get_variable(), __double2string(), __int2string(), GetPot::variable::name, GetPot::variable::original, Utility::pow(), and size().

Referenced by __DBE_expand_string(), and __DBE_get_expr_list().

{
  // ${: } pure text
  if( expr[0] == ':' )
    return expr.substr(1);

  // ${& expr expr ... } text concatination
  else if( expr[0] == '&' ) {
    const std::vector<std::string> A = __DBE_get_expr_list(expr.substr(1), 1);

    std::vector<std::string>::const_iterator it = A.begin();
    std::string result = *it++;
    for(; it != A.end(); it++) result += *it;

    return result;
  }

  // ${<-> expr expr expr} text replacement
  else if( expr.length() >= 3 && expr.substr(0, 3) == '<->' ) {
    std::vector<std::string> A = __DBE_get_expr_list(expr.substr(3), 3);
    std::string::size_type tmp = 0;
    const std::string::size_type L = A[1].length();
    while( (tmp = A[0].find(A[1])) != std::string::npos ) {
      A[0].replace(tmp, L, A[2]);
    }
    return A[0];
  }
  // ${+ ...}, ${- ...}, ${* ...}, ${/ ...} expressions
  else if( expr[0] == '+' ) {
    std::vector<std::string> A = __DBE_get_expr_list(expr.substr(1), 2);
    std::vector<std::string>::const_iterator it = A.begin();
    double result = __convert_to_type(*it++, 0.0);
    for(; it != A.end(); it++)
      result += __convert_to_type(*it, 0.0);

    return __double2string(result);
  }
  else if( expr[0] == '-' ) {
    std::vector<std::string> A = __DBE_get_expr_list(expr.substr(1), 2);
    std::vector<std::string>::const_iterator it = A.begin();
    double result = __convert_to_type(*it++, 0.0);
    for(; it != A.end(); it++)
      result -= __convert_to_type(*it, 0.0);

    return __double2string(result);
  }
  else if( expr[0] == '*' ) {
    std::vector<std::string> A = __DBE_get_expr_list(expr.substr(1), 2);
    std::vector<std::string>::const_iterator it = A.begin();
    double result = __convert_to_type(*it++, 0.0);
    for(; it != A.end(); it++)
      result *= __convert_to_type(*it, 0.0);

    return __double2string(result);
  }
  else if( expr[0] == '/' ) {
    std::vector<std::string> A = __DBE_get_expr_list(expr.substr(1), 2);
    std::vector<std::string>::const_iterator it = A.begin();
    double result = __convert_to_type(*it++, 0.0);
    if( result == 0 ) return '0.0';
    for(; it != A.end(); it++) {
      const double Q = __convert_to_type(*it, 0.0);
      if( Q == 0.0 ) return '0.0';          
      result /= Q;
    }
    return __double2string(result);
  }

  // ${^ ... } power expressions
  else if( expr[0] == '^' ) {
    std::vector<std::string> A = __DBE_get_expr_list(expr.substr(1), 2);
    std::vector<std::string>::const_iterator it = A.begin();
    double result = __convert_to_type(*it++, 0.0);
    for(; it != A.end(); it++)
      result = pow(result, __convert_to_type(*it, 0.0));
    return __double2string(result);
  }

  // ${==  } ${<=  } ${>= } comparisons (return the number of the first 'match'
  else if( expr.length() >= 2 && 
      ( expr.substr(0,2) == '==' || expr.substr(0,2) == '>=' || 
        expr.substr(0,2) == '<=' || expr[0] == '>'           || expr[0] == '<')) {
    // differentiate between two and one sign operators
    unsigned op = 0;
    enum { EQ, GEQ, LEQ, GT, LT };
    if      ( expr.substr(0, 2) == '==' ) op = EQ;
    else if ( expr.substr(0, 2) == '>=' ) op = GEQ;
    else if ( expr.substr(0, 2) == '<=' ) op = LEQ;
    else if ( expr[0] == '>' )            op = GT;
    else    /*                     '<' */ op = LT;

    std::vector<std::string> a;
    if ( op == GT || op == LT ) a = __DBE_get_expr_list(expr.substr(1), 2);
    else                        a = __DBE_get_expr_list(expr.substr(2), 2);

    std::string   x_orig = a[0];          
    double   x = __convert_to_type(x_orig, 1e37);
    unsigned i = 1;

    std::vector<std::string>::const_iterator y_orig = a.begin();
    for(y_orig++; y_orig != a.end(); y_orig++) { 
      double y = __convert_to_type(*y_orig, 1e37);

      // set the strings as reference if one wasn't a number
      if ( x == 1e37 || y == 1e37 ) {
        // it's a string comparison
        if( (op == EQ  && x_orig == *y_orig) || (op == GEQ && x_orig >= *y_orig) ||
            (op == LEQ && x_orig <= *y_orig) || (op == GT  && x_orig >  *y_orig) ||
            (op == LT  && x_orig <  *y_orig) )
          return __int2string(i);
      }
      else {
        // it's a number comparison
        if( (op == EQ  && x == y) || (op == GEQ && x >= y) ||
            (op == LEQ && x <= y) || (op == GT  && x >  y) || 
            (op == LT  && x <  y) )
          return __int2string(i);
      }
      i++;
    }

    // nothing fulfills the condition => return 0
    return '0';
  }
  // ${?? expr expr} select 
  else if( expr.length() >= 2 && expr.substr(0, 2) == '??' ) {
    std::vector<std::string> a = __DBE_get_expr_list(expr.substr(2), 2);
    double x = __convert_to_type(a[0], 1e37);
    // last element is always the default argument
    if( x == 1e37 || x < 0 || x >= a.size() - 1 ) return a[a.size()-1];

    // round x to closest integer
    return a[int(x+0.5)];
  }
  // ${? expr expr expr} if then else conditions
  else if( expr[0] == '?' ) {
    std::vector<std::string> a = __DBE_get_expr_list(expr.substr(1), 2);
    if( __convert_to_type(a[0], 0.0) == 1.0 ) return a[1];
    else if( a.size() > 2 )     return a[2];
  }
  // ${! expr} maxro expansion 
  else if( expr[0] == '!' ) {
    const GetPot::variable* Var = __DBE_get_variable(expr.substr(1));
    // error
    if( Var->name == '' ) return std::string(Var->original);

    const std::vector<std::string> A = __DBE_get_expr_list(Var->original, 2);
    return A[0];
  }
  // ${@: } - string subscription
  else if( expr.length() >= 2 && expr.substr(0,2) == '@:' ) {
    const std::vector<std::string> A = __DBE_get_expr_list(expr.substr(2), 2);
    double x = __convert_to_type(A[1], 1e37);

    // last element is always the default argument
    if( x == 1e37 || x < 0 || x >= A[0].size() - 1)
      return '<<1st index out of range>>';

    if( A.size() > 2 ) {
      double y = __convert_to_type(A[2], 1e37);
      if ( y != 1e37 && y > 0 && y <= A[0].size() - 1 && y > x )
        return A[0].substr(int(x+0.5), int(y+1.5) - int(x+0.5));
      else if( y == -1 )
        return A[0].substr(int(x+0.5));
      return '<<2nd index out of range>>';
    }
    else {
      char* tmp = new char[2];
      tmp[0] = A[0][int(x+0.5)]; tmp[1] = ' ';
      std::string result(tmp);
      delete [] tmp;
      return result;
    }
  }
  // ${@ } - vector subscription
  else if( expr[0] == '@' ) {
    std::vector<std::string>          A   = __DBE_get_expr_list(expr.substr(1), 2);
    const GetPot::variable* Var = __DBE_get_variable(A[0]);
    // error
    if( Var->name == '' ) {    
      // make a copy of the string if an error occured
      // (since the error variable is a static variable inside get_variable())
      return std::string(Var->original);
    }

    double x = __convert_to_type(A[1], 1e37);

    // last element is always the default argument
    if (x == 1e37 || x < 0 || x >= Var->value.size() )
      return '<<1st index out of range>>';

    if ( A.size() > 2) {
      double y = __convert_to_type(A[2], 1e37);
      int    begin = int(x+0.5);
      int    end = 0;
      if ( y != 1e37 && y > 0 && y <= Var->value.size() && y > x)
        end = int(y+1.5);
      else if( y == -1 )
        end = Var->value.size();
      else
        return '<<2nd index out of range>>';                

      std::string result = *(Var->get_element(begin));
      for(int i = begin+1; i < end; i++) 
        result += std::string(' ') + *(Var->get_element(i));
      return result;
    }
    else
      return *(Var->get_element(int(x+0.5)));
  }

  const std::vector<std::string>    A = __DBE_get_expr_list(expr, 1);
  const GetPot::variable* B = __DBE_get_variable(A[0]);

  // make a copy of the string if an error occured
  // (since the error variable is a static variable inside get_variable())
  if( B->name == '' )
    return std::string(B->original);
  
  //else

  return B->original;
}
 

std::string GetPot::__DBE_expand_string (const std::string &str) [inline, private]

Definition at line 1412 of file getpot.h.

References __DBE_expand().

Referenced by __parse_argument_vector().

{
  // Parses for closing operators '${ }' and expands them letting
  // white spaces and other letters as they are.
  std::string   new_string = '';
  unsigned open_brackets = 0;
  unsigned first = 0;
  for(unsigned i = 0;  i<str.size(); i++) {
    if( i < str.size() - 2 && str.substr(i, 2) == '${' ) {
      if( open_brackets == 0 ) first = i+2;
      open_brackets++;
    }
    else if( str[i] == '}' && open_brackets > 0) {
      open_brackets -= 1;
      if( open_brackets == 0 ) {
        const std::string Replacement = __DBE_expand(str.substr(first, i - first));
        new_string += Replacement;
      }
    }
    else if( open_brackets == 0 )
      new_string += str[i];
  }
  return new_string;
}
 

std::vector< std::string > GetPot::__DBE_get_expr_list (const std::string &str, const unsignedExpectedNumber) [inline, private]

Definition at line 1440 of file getpot.h.

References __DBE_expand().

Referenced by __DBE_expand().

{
  std::string str = str_;
  // Separates expressions by non-bracketed whitespaces, expands them
  // and puts them into a list.

  unsigned i=0;
  // (1) eat initial whitespaces
  for(; i < str.size(); i++)
    if( ! isspace(str[i]) ) break;

  std::vector<std::string>   expr_list;
  unsigned         open_brackets = 0;
  std::vector<unsigned> start_idx;
  unsigned         start_new_string = i;
  unsigned         l = str.size();

  // (2) search for ${ } expressions ...
  while( i < l ) {
    const char letter = str[i];
    // whitespace -> end of expression
    if( isspace(letter) && open_brackets == 0) {
      expr_list.push_back(str.substr(start_new_string, i - start_new_string));
      bool no_breakout_f = true;
      for(i++; i < l ; i++) {
        if( ! isspace(str[i]) ) 
        { no_breakout_f = false; start_new_string = i; break; }
      }
      if( no_breakout_f ) {
        // end of expression list
        if( expr_list.size() < ExpectedNumber ) {
          const std::string   pre_tmp('<< ${ }: missing arguments>>');
          std::vector<std::string> tmp(ExpectedNumber - expr_list.size(), pre_tmp); 
          expr_list.insert(expr_list.end(), tmp.begin(), tmp.end());
        }
        return expr_list;
      }
    }

    // dollar-bracket expression
    if( str.length() >= i+2 && str.substr(i, 2) == '${' ) {
      open_brackets++;
      start_idx.push_back(i+2);
    }
    else if( letter == '}' && open_brackets > 0) {
      unsigned start = start_idx[start_idx.size()-1];
      start_idx.pop_back();
      const std::string Replacement = __DBE_expand(str.substr(start, i-start));
      if( start  < 3)
        str = Replacement + str.substr(i+1);
      else
        str = str.substr(0, start-2) + Replacement + str.substr(i+1);
      l = str.size();              
      i = start + Replacement.size() - 3;
      open_brackets--;
    }
    i++;
  }

  // end of expression list
  expr_list.push_back(str.substr(start_new_string, i-start_new_string));

  if( expr_list.size() < ExpectedNumber ) {
    const std::string   pre_tmp('<< ${ }: missing arguments>>');
    std::vector<std::string> tmp(ExpectedNumber - expr_list.size(), pre_tmp); 
    expr_list.insert(expr_list.end(), tmp.begin(), tmp.end());
  }

  return expr_list;
}
 

const GetPot::variable * GetPot::__DBE_get_variable (const std::string &str) [inline, private]

Definition at line 1516 of file getpot.h.

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

Referenced by __DBE_expand().

{
  static GetPot::variable ev;
  std::string secure_Prefix = prefix;

  prefix = section;
  // (1) first search in currently active section
  const GetPot::variable* var = __find_variable(VarName.c_str());
  if( var != 0 ) { prefix = secure_Prefix; return var; }

  // (2) search in root name space
  prefix = '';
  var = __find_variable(VarName.c_str());
  if( var != 0 ) { prefix = secure_Prefix; return var; }

  prefix = secure_Prefix;

  // error occured => variable name == ''
  char* tmp = new char[VarName.length() + 25];
  std::sprintf(tmp, '<<${ } variable '%s' undefined>>', VarName.c_str());
  ev.name = '';
  ev.original = std::string(tmp);
  delete [] tmp;
  return &ev;
}
 

std::string GetPot::__double2string (doubleValue) const [inline, private]

Definition at line 277 of file getpot.h.

Referenced by __DBE_expand().

                                                 { 
    char* tmp = new char[128];
    std::sprintf(tmp, '%e', Value);
    std::string result(tmp);
    delete [] tmp;
    return result;
  }
 

const GetPot::variable * GetPot::__find_variable (const char *Name) const [inline, private]

Definition at line 1335 of file getpot.h.

References Quality::name(), prefix, and variables.

Referenced by __DBE_get_variable(), __parse_argument_vector(), have_variable(), operator()(), and vector_variable_size().

{
  std::string name = prefix + Name;
  for(std::vector<variable>::const_iterator it = variables.begin();
      it != variables.end();
      it++)
    if( (*it).name == name ) return &(*it);
  return 0;
}
 

const std::string GetPot::__get_next_token (std::istream &istr) [inline, private]

Definition at line 564 of file getpot.h.

References __get_string(), and __get_until_closing_bracket().

Referenced by __read_in_stream().

{
  std::string token;
  int    tmp = 0; 
  int    last_letter = 0;
  while(1+1 == 2) {
    last_letter = tmp; tmp = istr.get();
    if( tmp == EOF 
        || ((tmp == ' ' || tmp == '	' || tmp == ') && last_letter != '\') ) {
      return token;
    }
    else if( tmp == ''' && last_letter != '\' ) {
      // QUOTES: un-backslashed quotes => it's a string
      token += __get_string(istr);
      continue;
    }
    else if( tmp == '{' && last_letter == '$') {
      token += '{' + __get_until_closing_bracket(istr);
      continue;
    }
    else if( tmp == '$' && last_letter == '\') {
      token += tmp; tmp = 0;  //  so that last_letter will become = 0, not '$';
      continue;
    }
    else if( tmp == '\' && last_letter != '\') 
      continue;              // don't append un-backslashed backslashes
    token += tmp;
  }

  return token;
}
 

const std::string GetPot::__get_remaining_string (const std::string &String, const std::string &Start) const [inline, private]

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

{
  if( Start == '' ) return String;
  // note: java.lang.String: substring(a,b) = from a to b-1
  //        C++ string:      substr(a,b)    = from a to a + b
  if( String.find(Start) == 0 ) return String.substr(Start.length());
  else                          return '';
}
 

const std::string GetPot::__get_string (std::istream &istr) [inline, private]

Definition at line 601 of file getpot.h.

Referenced by __get_next_token().

{
  std::string str;
  int    tmp = 0;
  int    last_letter = 0;
  while(1 + 1 == 2) {
    last_letter = tmp; tmp = istr.get();
    if( tmp == EOF)  return str;
    // un-backslashed quotes => it's the end of the string
    else if( tmp == ''' && last_letter != '\')  return str;
    else if( tmp == '\' && last_letter != '\')  continue; // don't append 

    str += tmp;
  }

  return str;
}
 

const std::string GetPot::__get_until_closing_bracket (std::istream &istr) [inline, private]

Definition at line 623 of file getpot.h.

Referenced by __get_next_token().

{
  std::string str = ''; 
  int    tmp = 0;
  int    last_letter = 0;
  int    brackets = 1;
  while(1 + 1 == 2) {
    last_letter = tmp; tmp = istr.get();
    if( tmp == EOF) return str;
    else if( tmp == '{' && last_letter == '$') brackets += 1;
    else if( tmp == '}') {
      brackets -= 1;
      // un-backslashed brackets => it's the end of the string
      if( brackets == 0) return str + '}';
      else if( tmp == '\' && last_letter != '\') 
        continue;  // do not append an unbackslashed backslash
    }
    str += tmp;
  }

  return str;
}
 

std::string GetPot::__int2string (const int &Value) const [inline, private]

Definition at line 284 of file getpot.h.

Referenced by __DBE_expand().

                                                  { 
    char* tmp = new char[128];
    std::sprintf(tmp, '%i', Value);
    std::string result(tmp);
    delete [] tmp;
    return result;
  }
 

const char * GetPot::__match_starting_string (const char *StartString) [inline, private]

Definition at line 1077 of file getpot.h.

References argv, cursor, search_failed_f, and search_loop_f.

Referenced by direct_follow().

{
  const unsigned N = std::strlen(StartString);
  unsigned OldCursor = cursor;
  if( OldCursor >= argv.size() ) OldCursor = argv.size() - 1;
  search_failed_f = true;

  // (*) first loop from cursor position until end
  unsigned c = cursor;
  for(; c < argv.size(); c++) {
    if( std::strncmp(StartString, argv[c].c_str(), N) == 0)
    { cursor = c; search_failed_f = false; return &(argv[c].c_str()[N]); }
  }

  if( ! search_loop_f ) return false;

  // (*) second loop from 0 to old cursor position
  for(c = 1; c < OldCursor; c++) {
    if( std::strncmp(StartString, argv[c].c_str(), N) == 0)
    { cursor = c; search_failed_f = false; return &(argv[c].c_str()[N]); }
  }
  return 0;
}
 

void GetPot::__parse_argument_vector (const std::vector< std::string > &ARGV) [inline, private]

Definition at line 419 of file getpot.h.

References __DBE_expand_string(), __find_variable(), __process_section_label(), argv, idx_nominus, section, section_list, and variables.

Referenced by parse_command_line(), and parse_input_file().

{
  // build internal databases:
  //   1) array with no-minus arguments (usually used as filenames)
  //   2) variable assignments:
  //             'variable name' '=' number | string
  section = '';
  std::vector<std::string>  section_stack;
  unsigned i=0;
  std::vector<std::string>::const_iterator it     = ARGV.begin();
  std::vector<std::string>::const_iterator it_end = ARGV.end();
  argv.push_back(*it);
  
  for(++it; it != it_end; ++it, i++) {
    std::string arg = *it;
    if( arg.length() == 0 ) continue;

    // -- [section] labels
    if( (arg.length() > 1) &&
        (arg[0] == '[' )   &&
        (arg[arg.length()-1] == ']') ) {
      const std::string Name = __DBE_expand_string(arg.substr(1, arg.length()-2));
      section = __process_section_label(Name, section_stack);
      // new section --> append to list of sections
      if( std::find(section_list.begin(), section_list.end(), section) == section_list.end() )
        if( section.length() != 0 ) section_list.push_back(section);
      argv.push_back(arg);
    }
    else {
      arg = section + __DBE_expand_string(arg);
      argv.push_back(arg);
    }

    // -- separate array for nominus arguments
    if( arg[0] != '-' ) idx_nominus.push_back(unsigned(i));

    // -- variables: does arg contain a '=' operator ?
    for(const char* p = arg.c_str(); *p ; p++) {
      if( *p == '=' ) {
        // set terminating 'zero' to treat first part as single string
        // => arg (from start to 'p') = Name of variable
        //    p+1     (until terminating zero) = value of variable
        char* o = (char*)p++;
        *o = ' ';
        const GetPot::variable* Var = __find_variable(arg.c_str());
        
        if( Var == 0 )
          variables.push_back(variable(arg.c_str(), p)); 
        else
          ((GetPot::variable*)Var)->take(p);
        
        *o = '=';
        break;
      }
    }
  }
}
 

std::string GetPot::__process_section_label (const std::string &Section, std::vector< std::string > &section_stack) [inline, private]

Definition at line 650 of file getpot.h.

Referenced by __parse_argument_vector().

{
  std::string sname = Section;
  //  1) subsection of actual section ('./' prefix)
  if( sname.length() >= 2 && sname.substr(0, 2) == './' ) {
    sname = sname.substr(2);
  }
  //  2) subsection of parent section ('../' prefix)
  else if( sname.length() >= 3 && sname.substr(0, 3) == '../' ) {
    do {
      if( section_stack.end() != section_stack.begin() ) 
        section_stack.pop_back();
      sname = sname.substr(3);
    } while( sname.substr(0, 3) == '../' );
  }
  // 3) subsection of the root-section
  else {
    section_stack.erase(section_stack.begin(), section_stack.end());
    // [] => back to root section
  }

  if( sname != '' ) {
    // parse section name for 'slashes'
    unsigned i=0;
    while( i < sname.length() ) {
      if( sname[i] == '/' ) {
        section_stack.push_back(sname.substr(0,i));
        if( i+1 < sname.length()-1 )
          sname = sname.substr(i+1);
        i = 0;
      }
      else 
        i++;
    }      
    section_stack.push_back(sname);
  } 
  std::string section_name = '';
  if( section_stack.size() != 0 )
    victorate(std::string, section_stack, it) {
      section_name += *it + '/';
    }
  return section_name;
}
 

std::vector< std::string > GetPot::__read_in_file (const char *FileName) [inline, private]

Definition at line 480 of file getpot.h.

References __read_in_stream().

Referenced by parse_input_file().

{
  std::ifstream  i(FileName);
  if( ! i ) return std::vector<std::string>();
  // argv[0] == the filename of the file that was read in
  return __read_in_stream(i);
}
 

std::vector< std::string > GetPot::__read_in_stream (std::istream &istr) [inline, private]

Definition at line 491 of file getpot.h.

References __get_next_token(), and __skip_whitespace().

Referenced by __read_in_file().

{
  std::vector<std::string>  brute_tokens;
  while(istr) {
    __skip_whitespace(istr);
    const std::string Token = __get_next_token(istr);
    if( Token.empty() ||
        (Token[0] == static_cast<std::string::value_type>(EOF)) ) break;
    brute_tokens.push_back(Token);
  }

  // -- reduce expressions of token1'='token2 to a single 
  //    string 'token1=token2'
  // -- copy everything into 'argv'
  // -- arguments preceded by something like '[' name ']' (section)
  //    produce a second copy of each argument with a prefix '[name]argument'
  unsigned i1 = 0;
  unsigned i2 = 1;
  unsigned i3 = 2;

  std::vector<std::string>  arglist;
  while( i1 < brute_tokens.size() ) {
    const std::string& SRef = brute_tokens[i1];
    // 1) concatinate 'abcdef' '=' 'efgasdef' to 'abcdef=efgasdef'
    // note: java.lang.String: substring(a,b) = from a to b-1
    //        C++ string:      substr(a,b)    = from a to a + b
    if( i2 < brute_tokens.size() && brute_tokens[i2] == '=' ) {
      if( i3 >= brute_tokens.size() )
        arglist.push_back(brute_tokens[i1] + brute_tokens[i2]);
      else
        arglist.push_back(brute_tokens[i1] + brute_tokens[i2] + brute_tokens[i3]);
      i1 = i3+1; i2 = i3+2; i3 = i3+3;
      continue;
    }
    else {
      arglist.push_back(SRef);
      i1=i2; i2=i3; i3++;
    }
  }
  return arglist;
}
 

bool GetPot::__search_string_vector (const std::vector< std::string > &Vec, const std::string &Str) const [inline, private]

Definition at line 1774 of file getpot.h.

Referenced by unidentified_arguments(), unidentified_nominuses(), unidentified_options(), unidentified_sections(), and unidentified_variables().

{
  victorate(std::string, VecStr, itk) {
    if( *itk == Str ) return true;
  }
  return false;
}
 

void GetPot::__skip_whitespace (std::istream &istr) [inline, private]

Definition at line 536 of file getpot.h.

Referenced by __read_in_stream().

{ 
  int tmp = istr.get();
  do {
    while( isspace(tmp) ) {
      tmp = istr.get();
      if( ! istr ) return;
    }
    // found a non whitespace 
    if( tmp == '#' ) {
      // comment => skip until end of line
      while( tmp != ' ) {
        if( ! istr ) { istr.unget(); return; }
        tmp = istr.get();
      }
      continue; 
    }
    else {
      istr.unget();
      return;
    }
  } while( istr );
}
 

bool GetPot::argument_contains (unsignedIdx, const char *FlagList) const [inline]

Definition at line 1129 of file getpot.h.

References __check_flags(), __get_remaining_string(), argv, and prefix.

{
  if( Idx >= argv.size() ) return false;

  if( prefix == '' )
    // search argument for any flag in flag list
    return __check_flags(argv[Idx], FlagList);

  // if a prefix is set, then the argument index is the index
  //   inside the 'namespace'
  // => only check list of arguments that start with prefix
  unsigned no_matches = 0;
  for(unsigned i=0; i<argv.size(); i++) {
    const std::string Remain = __get_remaining_string(argv[i], prefix);
    if( Remain != '') {
      no_matches += 1;
      if( no_matches == Idx)
        return __check_flags(Remain, FlagList);
    }
  }
  // no argument in this namespace
  return false;
}
 

int GetPot::direct_follow (intDefault, const char *Option) [inline]

Definition at line 1043 of file getpot.h.

References __convert_to_type(), __match_starting_string(), argv, and cursor.

{
  const char* FollowStr = __match_starting_string(Option);
  if( FollowStr == 0 )                    return Default;
  if( ++cursor >= argv.size() ) cursor = argv.size();
  return __convert_to_type(FollowStr, Default);
}
 

double GetPot::direct_follow (doubleDefault, const char *Option) [inline]

Definition at line 1054 of file getpot.h.

References __convert_to_type(), __match_starting_string(), argv, and cursor.

{
  const char* FollowStr = __match_starting_string(Option);
  if( FollowStr == 0 )                   return Default;
  if( ++cursor >= argv.size() ) cursor = argv.size();
  return __convert_to_type(FollowStr, Default);
}
 

const char * GetPot::direct_follow (const char *Default, const char *Option) [inline]

Definition at line 1065 of file getpot.h.

References __match_starting_string(), argv, cursor, and search_failed_f.

{
  if( search_failed_f ) return Default;
  const char* FollowStr = __match_starting_string(Option);
  if( FollowStr == 0 )          return Default;
  if( ++cursor >= argv.size() ) cursor = argv.size();
  return FollowStr;
}
 

void GetPot::disable_loop () [inline]

Definition at line 113 of file getpot.h.

References search_loop_f.

Referenced by init_multiple_occurrence().

{ search_loop_f = false; }
 

void GetPot::enable_loop () [inline]

Definition at line 114 of file getpot.h.

References search_loop_f.

{ search_loop_f = true; }
 

int GetPot::follow (intDefault, unsignedNo, const char *Option, ...) [inline]

Definition at line 974 of file getpot.h.

References next(), and search().

  { 
    if( No == 0 ) return Default;
    if( search(P) == true ) return next(Default);
  
    std::va_list ap;
    va_start(ap, P);
    for(unsigned i=1; i<No; i++) {
      char* Opt = va_arg(ap, char *);
      if( search(Opt) == true ) { 
        va_end(ap); 
        return next(Default); 
      }
    }
    va_end(ap); 
    return Default;
  }
 

const char * GetPot::follow (const char *Default, const char *Option) [inline]

Definition at line 962 of file getpot.h.

References next(), and search().

{ 
  if( search(Option) == false ) return Default;
  return next(Default);
}
 

int GetPot::follow (intDefault, const char *Option) [inline]

Definition at line 944 of file getpot.h.

References next(), and search().

{ 
  if( search(Option) == false ) return Default;
  return next(Default);
}
 

const char * GetPot::follow (const char *Default, unsignedNo, const char *Option, ...) [inline]

Definition at line 1016 of file getpot.h.

References next(), and search().

  {
    if( No == 0 ) return Default;
    if( search(P) == true ) return next(Default);
  
    std::va_list ap;
    va_start(ap, P);
    for(unsigned i=1; i<No; i++) {
      char* Opt = va_arg(ap, char *);
      if( search(Opt) == true ) { 
        va_end(ap); 
        return next(Default); 
      }
    }
    va_end(ap); 
    return Default;
  }
 

double GetPot::follow (doubleDefault, const char *Option) [inline]

Definition at line 953 of file getpot.h.

References next(), and search().

{ 
  if( search(Option) == false ) return Default;
  return next(Default);
}
 

double GetPot::follow (doubleDefault, unsignedNo, const char *Option, ...) [inline]

Definition at line 995 of file getpot.h.

References next(), and search().

  {
    if( No == 0 ) return Default;
    if( search(P) == true ) return next(Default);
  
    std::va_list ap;
    va_start(ap, P);
    for(unsigned i=1; i<No; i++) {
      char* Opt = va_arg(ap, char *);
      if( search(Opt) == true ) { 
        va_end(ap); 
        return next(Default); 
      }
    }
    va_end(ap); 
    return Default;
  }
 

const char * GetPot::get (unsignedIdx, const char *Default) const [inline]

Definition at line 866 of file getpot.h.

References argv.

{ 
  if( Idx >= argv.size() ) return Default;
  else                     return argv[Idx].c_str();
}
 

double GetPot::get (unsignedIdx, doubleDefault) const [inline]

Definition at line 857 of file getpot.h.

References __convert_to_type(), and argv.

{ 
  if( Idx >= argv.size() ) return Default;
  return __convert_to_type(argv[Idx], Default);
}
 

int GetPot::get (unsignedIdx, intDefault) const [inline]

Definition at line 848 of file getpot.h.

References __convert_to_type(), and argv.

{ 
  if( Idx >= argv.size() ) return Default;
  return __convert_to_type(argv[Idx], Default);
}
 

std::vector< std::string > GetPot::get_section_names () const [inline]

Definition at line 1331 of file getpot.h.

References section_list.

{ return section_list; }
 

std::vector< std::string > GetPot::get_variable_names () const [inline]

Definition at line 1317 of file getpot.h.

References __get_remaining_string(), prefix, and variables.

{
  std::vector<std::string>  result;
  for(std::vector<GetPot::variable>::const_iterator it = variables.begin();
      it != variables.end(); it++) {
    const std::string Tmp = __get_remaining_string((*it).name, prefix);
    if( Tmp != '' ) result.push_back(Tmp);
  }
  return result;
}
 

bool GetPot::have_variable (const char *VarName) const [inline]

Definition at line 1203 of file getpot.h.

References __find_variable().

{
  const variable* sv = __find_variable(VarName);
  if (sv == 0) return false;
  return true;
}
 

void GetPot::init_multiple_occurrence () [inline]

Definition at line 832 of file getpot.h.

References disable_loop(), and reset_cursor().

{ disable_loop(); reset_cursor(); }
 

double GetPot::next (doubleDefault) [inline]

Definition at line 894 of file getpot.h.

References __convert_to_type(), __get_remaining_string(), argv, cursor, prefix, and search_failed_f.

{ 
  if( search_failed_f ) return Default;
  cursor++;

  if( cursor >= argv.size() ) 
  { cursor = argv.size(); return Default; }

  std::string Remain = __get_remaining_string(argv[cursor], prefix);

  return Remain != '' ? __convert_to_type(Remain, Default) : Default;
}
 

int GetPot::next (intDefault) [inline]

Definition at line 879 of file getpot.h.

References __convert_to_type(), __get_remaining_string(), argv, cursor, prefix, and search_failed_f.

Referenced by follow().

{ 
  if( search_failed_f ) return Default;
  cursor++; 
  if( cursor >= argv.size() ) 
  { cursor = argv.size(); return Default; }

  const std::string Remain = __get_remaining_string(argv[cursor], prefix);

  return Remain != '' ? __convert_to_type(Remain, Default) : Default;
}
 

std::string GetPot::next (const std::string &Default) [inline]

Definition at line 926 of file getpot.h.

References __get_remaining_string(), argv, cursor, prefix, and search_failed_f.

{ 
  if( search_failed_f ) return Default;
  cursor++; 

  if( cursor >= argv.size() )
  { cursor = argv.size(); return Default; }

  const std::string Remain = __get_remaining_string(argv[cursor], prefix);

  return Remain != '' ? Remain : Default;
}
 

const char * GetPot::next (const char *Default) [inline]

Definition at line 910 of file getpot.h.

References __get_remaining_string(), argv, cursor, prefix, and search_failed_f.

{ 
  if( search_failed_f ) return Default;
  cursor++; 

  if( cursor >= argv.size() )
  { cursor = argv.size(); return Default; }

  const std::string Remain = __get_remaining_string(argv[cursor], prefix);

  return Remain != '' ? Remain.c_str() : Default;
}
 

const char * GetPot::next_nominus () [inline]

Definition at line 1183 of file getpot.h.

References argv, idx_nominus, and nominus_cursor.

{
  if( nominus_cursor < int(idx_nominus.size()) - 1 )
    return argv[idx_nominus[++nominus_cursor]].c_str();
  return 0;
}
 

unsigned GetPot::nominus_size () const [inline]

Definition at line 157 of file getpot.h.

References idx_nominus.

{ return idx_nominus.size(); }
 

std::vector< std::string > GetPot::nominus_vector () const [inline]

Definition at line 1168 of file getpot.h.

References argv, and idx_nominus.

{
  std::vector<std::string> nv;
  for(std::vector<unsigned>::const_iterator it = idx_nominus.begin();
      it != idx_nominus.end();
      it++) {
    nv.push_back(argv[*it]);
  }
  return nv;
}
 

double GetPot::operator() (const char *VarName, doubleDefault) const [inline]

Definition at line 1231 of file getpot.h.

References __convert_to_type(), __find_variable(), and GetPot::variable::original.

{
  const variable*  sv = __find_variable(VarName);
  if( sv == 0 ) return Default;
  return __convert_to_type(sv->original, Default);
}
 

const char * GetPot::operator() (const char *VarName, const char *Default) const [inline]

Definition at line 1251 of file getpot.h.

References __find_variable(), and GetPot::variable::original.

{
  const variable*  sv = __find_variable(VarName);
  if( sv == 0 ) return Default;
  return sv->original.c_str();
}
 

std::string GetPot::operator() (const char *VarName, const std::string &Default) const [inline]

Definition at line 1261 of file getpot.h.

References __find_variable(), and GetPot::variable::original.

{
  const variable*  sv = __find_variable(VarName);
  if( sv == 0 ) return Default;
  return sv->original;
}
 

long double GetPot::operator() (const char *VarName, long doubleDefault) const [inline]

Definition at line 1241 of file getpot.h.

References __convert_to_type(), __find_variable(), and GetPot::variable::original.

{
  const variable*  sv = __find_variable(VarName);
  if( sv == 0 ) return Default;
  return __convert_to_type(sv->original, Default);
}
 

int GetPot::operator() (const char *VarName, intDefault, unsignedIdx) const [inline]

Definition at line 1271 of file getpot.h.

References __convert_to_type(), __find_variable(), and GetPot::variable::get_element().

{
  const variable* sv = __find_variable(VarName);
  if( sv == 0 ) return Default;
  const std::string*  element = sv->get_element(Idx);
  if( element == 0 ) return Default;
  return __convert_to_type(*element, Default);
}
 

double GetPot::operator() (const char *VarName, doubleDefault, unsignedIdx) const [inline]

Definition at line 1283 of file getpot.h.

References __convert_to_type(), __find_variable(), and GetPot::variable::get_element().

{
  const variable* sv = __find_variable(VarName);
  if( sv == 0 ) return Default;
  const std::string*  element = sv->get_element(Idx);
  if( element == 0 ) return Default;
  return __convert_to_type(*element, Default);
}
 

const char * GetPot::operator() (const char *VarName, const char *Default, unsignedIdx) const [inline]

Definition at line 1295 of file getpot.h.

References __find_variable(), and GetPot::variable::get_element().

{
  const variable*  sv = __find_variable(VarName);
  if( sv == 0 ) return Default;
  const std::string* element = sv->get_element(Idx);     
  if( element == 0 )  return Default;
  return element->c_str();
}
 

bool GetPot::operator() (const char *VarName, boolDefault) const [inline]

Definition at line 1211 of file getpot.h.

References __convert_to_type(), __find_variable(), and GetPot::variable::original.

{
  const variable* sv = __find_variable(VarName);
  if ( sv == 0 ) return Default;
  return __convert_to_type(sv->original, Default);
}
 

int GetPot::operator() (const char *VarName, intDefault) const [inline]

Definition at line 1221 of file getpot.h.

References __convert_to_type(), __find_variable(), and GetPot::variable::original.

{
  const variable*  sv = __find_variable(VarName);
  if( sv == 0 ) return Default;
  return __convert_to_type(sv->original, Default);
}
 

GetPot & GetPot::operator= (const GetPot &Other) [inline]

Definition at line 402 of file getpot.h.

References argv, cursor, idx_nominus, nominus_cursor, search_failed_f, search_loop_f, and variables.

Referenced by GetPot(), and GetPot::variable::variable().

{
  if (&Other != this) {
    argv            = Other.argv;
    variables       = Other.variables;
    cursor          = Other.cursor;
    nominus_cursor  = Other.nominus_cursor;
    search_failed_f = Other.search_failed_f;
    idx_nominus     = Other.idx_nominus;
    search_loop_f   = Other.search_loop_f;
  }
  return *this;
}
 

const char * GetPot::operator[] (unsignedIdx) const [inline]

Definition at line 842 of file getpot.h.

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

{ return idx<argv.size() ? argv[idx].c_str() : 0; }
 

bool GetPot::options_contain (const char *FlagList) const [inline]

Definition at line 1111 of file getpot.h.

References __check_flags(), __get_remaining_string(), argv, and prefix.

{
  // go through all arguments that start with a '-' (but not '--')
  std::string str;
  for(std::vector<std::string>::const_iterator it = argv.begin();
      it != argv.end();
      it++) {
    str = __get_remaining_string(*it, prefix);

    if( str.length() >= 2 && str[0] == '-' && str[1] != '-' )
      if( __check_flags(str, FlagList) ) return true;
  }
  return false;
}
 

void GetPot::parse_command_line (intargc_, char **argv_) [inline]

Definition at line 356 of file getpot.h.

References __basic_initialization(), and __parse_argument_vector().

Referenced by GetPot().

{
  __basic_initialization();

  // -- make an internal copy of the argument list:
  std::vector<std::string> __argv;
  __argv.reserve (argc_);
  
  for(int i=0; i<argc_; i++) {
    std::string tmp(argv_[i]);
    __argv.push_back(tmp);
  }
  __parse_argument_vector(__argv); 
}
 

void GetPot::parse_input_file (const std::string &FileName) [inline]

Definition at line 374 of file getpot.h.

References __basic_initialization(), __parse_argument_vector(), and __read_in_file().

Referenced by GetPot().

{
  __basic_initialization();

  std::vector<std::string> __argv;
  __argv.push_back(FileName); 
  std::vector<std::string> args = __read_in_file(FileName.c_str());
  __argv.insert(__argv.begin()+1, args.begin(), args.end());
  __parse_argument_vector(__argv); 
}
 

void GetPot::parse_input_file (const char *FileName) [inline]

Definition at line 388 of file getpot.h.

References __basic_initialization(), __parse_argument_vector(), and __read_in_file().

{
  __basic_initialization();

  std::vector<std::string> __argv;
  __argv.push_back(FileName); 
  std::vector<std::string> args = __read_in_file(FileName);
  __argv.insert(__argv.begin()+1, args.begin(), args.end());
  __parse_argument_vector(__argv); 
}
 

int GetPot::print () const [inline]

Definition at line 1352 of file getpot.h.

References argv.

{
  std::cout << 'argc = ' << argv.size() << std::endl;
  for(std::vector<std::string>::const_iterator it = argv.begin(); it != argv.end(); it++)
    std::cout << *it << std::endl;
  std::cout << std::endl;
  return 1;
}
 

void GetPot::reset_cursor () [inline]

Definition at line 826 of file getpot.h.

References cursor, and search_failed_f.

Referenced by init_multiple_occurrence().

{ search_failed_f = false; cursor = 0; }
 

void GetPot::reset_nominus_cursor () [inline]

Definition at line 1193 of file getpot.h.

References nominus_cursor.

{ nominus_cursor = -1; }
 

bool GetPot::search (const char *option) [inline]

Definition at line 774 of file getpot.h.

References argv, cursor, prefix, search_failed_f, and search_loop_f.

Referenced by follow(), and search().

{ 
  unsigned      OldCursor = cursor;
  const std::string  SearchTerm = prefix + Option;

  if( OldCursor >= argv.size() ) OldCursor = argv.size() - 1;
  search_failed_f = true;

  // (*) first loop from cursor position until end
  unsigned  c = cursor;
  for(; c < argv.size(); c++) {
    if( argv[c] == SearchTerm ) 
    { cursor = c; search_failed_f = false; return true; }
  }
  if( ! search_loop_f ) return false;

  // (*) second loop from 0 to old cursor position
  for(c = 0; c < OldCursor; c++) {
    if( argv[c] == SearchTerm ) 
    { cursor = c; search_failed_f = false; return true; }
  }
  // in case nothing is found the cursor stays where it was
  return false;
}
 

bool GetPot::search (const std::string &option) [inline]

Definition at line 766 of file getpot.h.

References search().

{ 
  return search(Option.c_str());
}
 

bool GetPot::search (unsignedNo, const char *P, ...) [inline]

Definition at line 803 of file getpot.h.

References search().

{
    if( No == 0 ) return false;

    // search for the first argument
    if( search(P) == true ) return true;
    
    // start interpreting variable argument list
    std::va_list ap;
    va_start(ap, P);
    for(unsigned i=1; i<No; i++) {
        char* Opt = va_arg(ap, char *);
        if( search(Opt) == true ) 
        { va_end(ap); return true; }
    }
    va_end(ap);
    return false;
}
 

bool GetPot::search_failed () const [inline]

Definition at line 110 of file getpot.h.

References search_failed_f.

{ return search_failed_f; }
 

void GetPot::set_prefix (const std::string &Prefix) [inline]

Definition at line 109 of file getpot.h.

References prefix.

{ prefix = Prefix; }
 

void GetPot::set_prefix (const char *Prefix) [inline]

Definition at line 108 of file getpot.h.

References prefix.

{ prefix = std::string(Prefix); }
 

unsigned GetPot::size () const [inline]

Definition at line 875 of file getpot.h.

References argv.

Referenced by __DBE_expand().

{ return argv.size(); }
 

std::vector< std::string > GetPot::unidentified_arguments (const std::vector< std::string > &Knowns) const [inline]

Definition at line 1947 of file getpot.h.

References __get_remaining_string(), __search_string_vector(), argv, and prefix.

Referenced by unidentified_arguments().

{
  std::vector<std::string> ufos;
  std::vector<std::string>::const_iterator it = argv.begin();
  it++; // forget about argv[0] (application or filename)
  for(; it != argv.end(); it++) {
    // -- argument belongs to prefixed section ?
    const std::string arg = __get_remaining_string(*it, prefix);
    if( arg == '' ) continue;

    // -- check if in list
    if( __search_string_vector(Knowns, arg) == false)
      ufos.push_back(*it);
  }
  return ufos;
}
 

std::vector< std::string > GetPot::unidentified_arguments (unsignedNumber, const char *Known, ...) const [inline]

Definition at line 1784 of file getpot.h.

References unidentified_arguments().

  {
    std::vector<std::string> known_arguments;
  
    // (1) create a vector of known arguments
    if( Number == 0 ) return std::vector<std::string>();
  
    std::va_list ap;
    va_start(ap, KnownArgument1);
    known_arguments.push_back(std::string(KnownArgument1));
    for(unsigned i=1; i<Number; i++)
      known_arguments.push_back(std::string(va_arg(ap, char *)));
    va_end(ap);
  
    return unidentified_arguments(known_arguments);
  }
 

std::string GetPot::unidentified_flags (const char *Known, intArgumentNumber = -1) const [inline]

Definition at line 1890 of file getpot.h.

References __get_remaining_string(), argv, and prefix.

{
  std::string         ufos;
  std::vector<std::string> known_arguments;
  std::string         KFL(KnownFlagList);

  // (2) iteration over '-' arguments (options)
  if( ArgumentNumber == -1 ) {
    std::vector<std::string>::const_iterator it = argv.begin();
    it++; // forget about argv[0] (application or filename)
    for(; it != argv.end(); it++) {
      // -- argument belongs to prefixed section ?
      const std::string arg = __get_remaining_string(*it, prefix);
      if( arg == '' ) continue;

      // -- does arguments start with '-' (but not '--')
      if     ( arg.length() < 2 ) continue;
      else if( arg[0] != '-' )    continue;
      else if( arg[1] == '-' )    continue;

      // -- check out if flags inside option are contained in KnownFlagList
      const char* p=arg.c_str();
      p++; // skip starting minus
      for(; *p != ' ' ; p++)
        if( KFL.find(*p) == std::string::npos ) ufos += *p;
    }
  }
  // (1) check specific argument
  else {
    // -- only check arguments that start with prefix
    int no_matches = 0;
    for(unsigned i=1; i<argv.size(); i++) {
      const std::string Remain = __get_remaining_string(argv[i], prefix);
      if( Remain != '') {
        no_matches++;
        if( no_matches == ArgumentNumber) {
          // -- the right argument number inside the section is found
          // => check it for flags
          const char* p = Remain.c_str();
          p++; // skip starting minus
          for(; *p != ' ' ; p++)
            if( KFL.find(*p) == std::string::npos ) ufos += *p;
          return ufos;
        }
      }
    }
  }
  return ufos;
}
 

std::vector< std::string > GetPot::unidentified_nominuses (const std::vector< std::string > &Knowns) const [inline]

Definition at line 2029 of file getpot.h.

References __get_remaining_string(), __search_string_vector(), argv, and prefix.

Referenced by unidentified_nominuses().

{
  std::vector<std::string> ufos;

  // (2) iterate over all arguments 
  std::vector<std::string>::const_iterator it = argv.begin();
  it++; // forget about argv[0] (application or filename)
  for(; it != argv.end(); it++) {
    // -- check if nominus part of prefix
    const std::string arg = __get_remaining_string(*it, prefix);
    if( arg == '' ) continue;

    if( arg.length() < 1 )                                  continue;
    // option ? --> not a nomius 
    if( arg[0] == '-' )                                     continue;
    // section ? --> not a real nominus
    if( arg[0] == '[' && arg[arg.length()-1] == ']' ) continue;
    // variable definition ? --> not a real nominus
    bool continue_f = false;
    for(unsigned i=0; i<arg.length() ; i++)
      if( arg[i] == '=' ) { continue_f = true; break; }
    if( continue_f )                                           continue;

    // real nominuses are compared with the given list
    if( __search_string_vector(Knowns, arg) == false )
      ufos.push_back(*it);
  }    
  return ufos;
}
 

std::vector< std::string > GetPot::unidentified_nominuses (unsignedNumber, const char *Known, ...) const [inline]

Definition at line 1865 of file getpot.h.

References unidentified_nominuses().

  {
    std::vector<std::string> known_nominuses;
  
    // create vector of known arguments
    if( Number == 0 ) return std::vector<std::string>();
  
    std::va_list ap;
    va_start(ap, Known);
    known_nominuses.push_back(std::string(Known));
    for(unsigned i=1; i<Number; i++) {
      std::string tmp = std::string(va_arg(ap, char *));
      if( tmp.length() == 0 ) continue;
      known_nominuses.push_back(tmp);
    }
    va_end(ap);
  
    return unidentified_nominuses(known_nominuses);
  }
 

std::vector< std::string > GetPot::unidentified_options (unsignedNumber, const char *Known, ...) const [inline]

Definition at line 1804 of file getpot.h.

References unidentified_options().

  {
    std::vector<std::string> known_options;
  
    // (1) create a vector of known arguments
    if( Number == 0 ) return std::vector<std::string>();
  
    std::va_list ap;
    va_start(ap, KnownOption1);
    known_options.push_back(std::string(KnownOption1));
    for(unsigned i=1; i<Number; i++)
      known_options.push_back(std::string(va_arg(ap, char *)));
    va_end(ap);
  
    return unidentified_options(known_options);
  }
 

std::vector< std::string > GetPot::unidentified_options (const std::vector< std::string > &Knowns) const [inline]

Definition at line 1967 of file getpot.h.

References __get_remaining_string(), __search_string_vector(), argv, and prefix.

Referenced by unidentified_options().

{
  std::vector<std::string> ufos;
  std::vector<std::string>::const_iterator it = argv.begin();
  it++; // forget about argv[0] (application or filename)
  for(; it != argv.end(); it++) {
    // -- argument belongs to prefixed section ?
    const std::string arg = __get_remaining_string(*it, prefix);
    if( arg == '' ) continue;

    // is argument really an option (starting with '-') ?
    if( arg.length() < 1 || arg[0] != '-' ) continue;

    if( __search_string_vector(Knowns, arg) == false)
      ufos.push_back(*it);
  }

  return ufos;
}
 

std::vector< std::string > GetPot::unidentified_sections (const std::vector< std::string > &Knowns) const [inline]

Definition at line 2009 of file getpot.h.

References __get_remaining_string(), __search_string_vector(), prefix, and section_list.

Referenced by unidentified_sections().

{
  std::vector<std::string> ufos;

  victorate(std::string, section_list, it) {
    // -- check if section conform to prefix
    const std::string sec_name = __get_remaining_string(*it, prefix);
    if( sec_name == '' ) continue;

    // -- check if section is known
    if( __search_string_vector(Knowns, sec_name) == false )
      ufos.push_back(*it);
  }

  return ufos;    
}
 

std::vector< std::string > GetPot::unidentified_sections (unsignedNumber, const char *Known, ...) const [inline]

Definition at line 1842 of file getpot.h.

References unidentified_sections().

  {
    std::vector<std::string> known_sections;
  
    // (1) create a vector of known arguments
    if( Number == 0 ) return std::vector<std::string>();
  
    std::va_list ap;
    va_start(ap, KnownSection1);
    known_sections.push_back(std::string(KnownSection1));
    for(unsigned i=1; i<Number; i++) {
      std::string tmp = std::string(va_arg(ap, char *));
      if( tmp.length() == 0 ) continue;
      if( tmp[tmp.length()-1] != '/' ) tmp += '/';
      known_sections.push_back(tmp);
    }
    va_end(ap);
  
    return unidentified_sections(known_sections);
  }
 

std::vector< std::string > GetPot::unidentified_variables (const std::vector< std::string > &Knowns) const [inline]

Definition at line 1990 of file getpot.h.

References __get_remaining_string(), __search_string_vector(), prefix, and variables.

Referenced by unidentified_variables().

{
  std::vector<std::string> ufos;

  victorate(GetPot::variable, variables, it) {
    // -- check if variable has specific prefix
    const std::string var_name = __get_remaining_string((*it).name, prefix);
    if( var_name == '' ) continue;

    // -- check if variable is known
    if( __search_string_vector(Knowns, var_name) == false)
      ufos.push_back((*it).name);
  }
  return ufos;    
}
 

std::vector< std::string > GetPot::unidentified_variables (unsignedNumber, const char *Known, ...) const [inline]

Definition at line 1823 of file getpot.h.

References unidentified_variables().

  {
    std::vector<std::string> known_variables;
  
    // create vector of known arguments
    if( Number == 0 ) return std::vector<std::string>();
  
    std::va_list ap;
    va_start(ap, KnownVariable1);
    known_variables.push_back(std::string(KnownVariable1));
    for(unsigned i=1; i<Number; i++)
      known_variables.push_back(std::string(va_arg(ap, char *)));
    va_end(ap);
  
    return unidentified_variables(known_variables);
  }
 

unsigned GetPot::vector_variable_size (const char *VarName) const [inline]

Definition at line 1307 of file getpot.h.

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

{
  const variable*  sv = __find_variable(VarName);
  if( sv == 0 ) return 0;
  return sv->value.size();
}
 

Member Data Documentation

 

std::vector<std::string> GetPot::argv [private]

Definition at line 212 of file getpot.h.

Referenced by __match_starting_string(), __parse_argument_vector(), argument_contains(), direct_follow(), get(), next(), next_nominus(), nominus_vector(), operator=(), operator[](), options_contain(), print(), search(), size(), unidentified_arguments(), unidentified_flags(), unidentified_nominuses(), and unidentified_options().  

unsigned GetPot::cursor [private]

Definition at line 213 of file getpot.h.

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

std::vector<unsigned> GetPot::idx_nominus [private]

Definition at line 221 of file getpot.h.

Referenced by __parse_argument_vector(), next_nominus(), nominus_size(), nominus_vector(), and operator=().  

int GetPot::nominus_cursor [private]

Definition at line 220 of file getpot.h.

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

std::string GetPot::prefix [private]

Definition at line 208 of file getpot.h.

Referenced by __basic_initialization(), __DBE_get_variable(), __find_variable(), argument_contains(), get_variable_names(), next(), options_contain(), search(), set_prefix(), unidentified_arguments(), unidentified_flags(), unidentified_nominuses(), unidentified_options(), unidentified_sections(), and unidentified_variables().  

bool GetPot::search_failed_f [private]

Definition at line 216 of file getpot.h.

Referenced by __basic_initialization(), __match_starting_string(), direct_follow(), next(), operator=(), reset_cursor(), search(), and search_failed().  

bool GetPot::search_loop_f [private]

Definition at line 214 of file getpot.h.

Referenced by __basic_initialization(), __match_starting_string(), disable_loop(), enable_loop(), operator=(), and search().  

std::string GetPot::section [private]

Definition at line 209 of file getpot.h.

Referenced by __basic_initialization(), __DBE_get_variable(), and __parse_argument_vector().  

std::vector<std::string> GetPot::section_list [private]

Definition at line 210 of file getpot.h.

Referenced by __parse_argument_vector(), get_section_names(), and unidentified_sections().  

std::vector<variable> GetPot::variables [private]

Definition at line 225 of file getpot.h.

Referenced by __find_variable(), __parse_argument_vector(), get_variable_names(), operator=(), and unidentified_variables().

 

Author

Generated automatically by Doxygen for libMesh from the source code.


 

Index

NAME
SYNOPSIS
Classes
Public Member Functions
Private Member Functions
Private Attributes
Detailed Description
Constructor & Destructor Documentation
GetPot::GetPot () [inline]
GetPot::GetPot (const GetPot &Other) [inline]
GetPot::GetPot (intargc_, char **argv_) [inline]
GetPot::GetPot (const char *FileName) [inline]
GetPot::GetPot (const std::string &FileName) [inline]
GetPot::~GetPot () [inline]
Member Function Documentation
void GetPot::__basic_initialization () [inline, private]
bool GetPot::__check_flags (const std::string &Str, const char *FlagList) const [inline, private]
int GetPot::__convert_to_type (const std::string &String, intDefault) const [inline, private]
double GetPot::__convert_to_type (const std::string &String, doubleDefault) const [inline, private]
long double GetPot::__convert_to_type (const std::string &String, long doubleDefault) const [inline, private]
bool GetPot::__convert_to_type (const std::string &String, boolDefault) const [inline, private]
std::string GetPot::__DBE_expand (const std::string &str) [inline, private]
std::string GetPot::__DBE_expand_string (const std::string &str) [inline, private]
std::vector< std::string > GetPot::__DBE_get_expr_list (const std::string &str, const unsignedExpectedNumber) [inline, private]
const GetPot::variable * GetPot::__DBE_get_variable (const std::string &str) [inline, private]
std::string GetPot::__double2string (doubleValue) const [inline, private]
const GetPot::variable * GetPot::__find_variable (const char *Name) const [inline, private]
const std::string GetPot::__get_next_token (std::istream &istr) [inline, private]
const std::string GetPot::__get_remaining_string (const std::string &String, const std::string &Start) const [inline, private]
const std::string GetPot::__get_string (std::istream &istr) [inline, private]
const std::string GetPot::__get_until_closing_bracket (std::istream &istr) [inline, private]
std::string GetPot::__int2string (const int &Value) const [inline, private]
const char * GetPot::__match_starting_string (const char *StartString) [inline, private]
void GetPot::__parse_argument_vector (const std::vector< std::string > &ARGV) [inline, private]
std::string GetPot::__process_section_label (const std::string &Section, std::vector< std::string > &section_stack) [inline, private]
std::vector< std::string > GetPot::__read_in_file (const char *FileName) [inline, private]
std::vector< std::string > GetPot::__read_in_stream (std::istream &istr) [inline, private]
bool GetPot::__search_string_vector (const std::vector< std::string > &Vec, const std::string &Str) const [inline, private]
void GetPot::__skip_whitespace (std::istream &istr) [inline, private]
bool GetPot::argument_contains (unsignedIdx, const char *FlagList) const [inline]
int GetPot::direct_follow (intDefault, const char *Option) [inline]
double GetPot::direct_follow (doubleDefault, const char *Option) [inline]
const char * GetPot::direct_follow (const char *Default, const char *Option) [inline]
void GetPot::disable_loop () [inline]
void GetPot::enable_loop () [inline]
int GetPot::follow (intDefault, unsignedNo, const char *Option, ...) [inline]
const char * GetPot::follow (const char *Default, const char *Option) [inline]
int GetPot::follow (intDefault, const char *Option) [inline]
const char * GetPot::follow (const char *Default, unsignedNo, const char *Option, ...) [inline]
double GetPot::follow (doubleDefault, const char *Option) [inline]
double GetPot::follow (doubleDefault, unsignedNo, const char *Option, ...) [inline]
const char * GetPot::get (unsignedIdx, const char *Default) const [inline]
double GetPot::get (unsignedIdx, doubleDefault) const [inline]
int GetPot::get (unsignedIdx, intDefault) const [inline]
std::vector< std::string > GetPot::get_section_names () const [inline]
std::vector< std::string > GetPot::get_variable_names () const [inline]
bool GetPot::have_variable (const char *VarName) const [inline]
void GetPot::init_multiple_occurrence () [inline]
double GetPot::next (doubleDefault) [inline]
int GetPot::next (intDefault) [inline]
std::string GetPot::next (const std::string &Default) [inline]
const char * GetPot::next (const char *Default) [inline]
const char * GetPot::next_nominus () [inline]
unsigned GetPot::nominus_size () const [inline]
std::vector< std::string > GetPot::nominus_vector () const [inline]
double GetPot::operator() (const char *VarName, doubleDefault) const [inline]
const char * GetPot::operator() (const char *VarName, const char *Default) const [inline]
std::string GetPot::operator() (const char *VarName, const std::string &Default) const [inline]
long double GetPot::operator() (const char *VarName, long doubleDefault) const [inline]
int GetPot::operator() (const char *VarName, intDefault, unsignedIdx) const [inline]
double GetPot::operator() (const char *VarName, doubleDefault, unsignedIdx) const [inline]
const char * GetPot::operator() (const char *VarName, const char *Default, unsignedIdx) const [inline]
bool GetPot::operator() (const char *VarName, boolDefault) const [inline]
int GetPot::operator() (const char *VarName, intDefault) const [inline]
GetPot & GetPot::operator= (const GetPot &Other) [inline]
const char * GetPot::operator[] (unsignedIdx) const [inline]
bool GetPot::options_contain (const char *FlagList) const [inline]
void GetPot::parse_command_line (intargc_, char **argv_) [inline]
void GetPot::parse_input_file (const std::string &FileName) [inline]
void GetPot::parse_input_file (const char *FileName) [inline]
int GetPot::print () const [inline]
void GetPot::reset_cursor () [inline]
void GetPot::reset_nominus_cursor () [inline]
bool GetPot::search (const char *option) [inline]
bool GetPot::search (const std::string &option) [inline]
bool GetPot::search (unsignedNo, const char *P, ...) [inline]
bool GetPot::search_failed () const [inline]
void GetPot::set_prefix (const std::string &Prefix) [inline]
void GetPot::set_prefix (const char *Prefix) [inline]
unsigned GetPot::size () const [inline]
std::vector< std::string > GetPot::unidentified_arguments (const std::vector< std::string > &Knowns) const [inline]
std::vector< std::string > GetPot::unidentified_arguments (unsignedNumber, const char *Known, ...) const [inline]
std::string GetPot::unidentified_flags (const char *Known, intArgumentNumber = -1) const [inline]
std::vector< std::string > GetPot::unidentified_nominuses (const std::vector< std::string > &Knowns) const [inline]
std::vector< std::string > GetPot::unidentified_nominuses (unsignedNumber, const char *Known, ...) const [inline]
std::vector< std::string > GetPot::unidentified_options (unsignedNumber, const char *Known, ...) const [inline]
std::vector< std::string > GetPot::unidentified_options (const std::vector< std::string > &Knowns) const [inline]
std::vector< std::string > GetPot::unidentified_sections (const std::vector< std::string > &Knowns) const [inline]
std::vector< std::string > GetPot::unidentified_sections (unsignedNumber, const char *Known, ...) const [inline]
std::vector< std::string > GetPot::unidentified_variables (const std::vector< std::string > &Knowns) const [inline]
std::vector< std::string > GetPot::unidentified_variables (unsignedNumber, const char *Known, ...) const [inline]
unsigned GetPot::vector_variable_size (const char *VarName) const [inline]
Member Data Documentation
std::vector<std::string> GetPot::argv [private]
unsigned GetPot::cursor [private]
std::vector<unsigned> GetPot::idx_nominus [private]
int GetPot::nominus_cursor [private]
std::string GetPot::prefix [private]
bool GetPot::search_failed_f [private]
bool GetPot::search_loop_f [private]
std::string GetPot::section [private]
std::vector<std::string> GetPot::section_list [private]
std::vector<variable> GetPot::variables [private]
Author

This document was created by man2html, using the manual pages.
Time: 21:46:45 GMT, April 16, 2011