GetPot::variable Struct Reference

Public Member Functions

 variable ()
 
 variable (const variable &)
 
 variable (const char *Name, const char *Value, const char *FieldSeparator)
 
 ~variable ()
 
variableoperator= (const variable &Other)
 
void take (const char *Value, const char *FieldSeparator)
 
const std::string * get_element (unsigned Idx) const
 

Public Attributes

std::string name
 
STRING_VECTOR value
 
std::string original
 

Detailed Description

Variable to be specified on the command line or in input files. (i.e. of the form var='12 312 341')

Definition at line 478 of file getpot.h.

Constructor & Destructor Documentation

GetPot::variable::variable ( )
inline

constructors, destructors, assignment operator

Definition at line 3911 of file getpot.h.

3912  : name(),
3913  value(),
3914  original()
3915 {}
std::string name
Definition: getpot.h:500
std::string original
Definition: getpot.h:502
STRING_VECTOR value
Definition: getpot.h:501
GetPot::variable::variable ( const variable Other)
inline

Definition at line 3920 of file getpot.h.

References GetPot::operator=(), and operator=().

3921 {
3922 #ifdef WIN32
3923  operator=(Other);
3924 #else
3926 #endif
3927 }
variable & operator=(const variable &Other)
Definition: getpot.h:4013
GetPot::variable::variable ( const char *  Name,
const char *  Value,
const char *  FieldSeparator 
)
inline

Definition at line 3932 of file getpot.h.

References take().

3933  : name(Name)
3934 {
3935  // make a copy of the 'Value'
3936  take(Value, FieldSeparator);
3937 }
void take(const char *Value, const char *FieldSeparator)
Definition: getpot.h:3953
std::string name
Definition: getpot.h:500
GetPot::variable::~variable ( )
inline

Definition at line 4007 of file getpot.h.

4008 {}

Member Function Documentation

const std::string * GetPot::variable::get_element ( unsigned  Idx) const
inline

get a specific element in the string vector (return 0 if not present)

Definition at line 3942 of file getpot.h.

Referenced by GetPot::get_value_no_default(), and GetPot::operator()().

3943 {
3944  if (Idx >= value.size())
3945  return 0;
3946  else
3947  return &(value[Idx]);
3948 }
STRING_VECTOR value
Definition: getpot.h:501
GetPot::variable & GetPot::variable::operator= ( const variable Other)
inline

Definition at line 4013 of file getpot.h.

References libMesh::Quality::name(), name, original, and value.

Referenced by variable().

4014 {
4015  if (&Other != this)
4016  {
4017  name = Other.name;
4018  value = Other.value;
4019  original = Other.original;
4020  }
4021  return *this;
4022 }
std::string name
Definition: getpot.h:500
std::string original
Definition: getpot.h:502
STRING_VECTOR value
Definition: getpot.h:501
void GetPot::variable::take ( const char *  Value,
const char *  FieldSeparator 
)
inline

Definition at line 3953 of file getpot.h.

Referenced by variable().

3954 {
3955  original = std::string(Value); // string member var
3956  value.clear(); // vector<string> member var
3957 
3958  /*
3959  // separate string by white space delimiters using 'strtok'
3960  // thread safe usage of strtok (no static members)
3961  char* spt = 0;
3962  // make a copy of the 'Value'
3963  char* copy = new char[strlen(Value)+1];
3964  strcpy(copy, Value);
3965  char* follow_token = strtok_r(copy, FieldSeparator, &spt);
3966  while (follow_token != 0)
3967  {
3968  value.push_back(std::string(follow_token));
3969  follow_token = strtok_r(NULL, FieldSeparator, &spt);
3970  }
3971 
3972  delete [] copy;
3973  */
3974 
3975  // Don't use strtok, instead tokenize the input char "Value" using std::string operations so
3976  // that the results end up in the local "value" member
3977 
3978  // Construct std::string objects from the input char*s. I think the only
3979  // FieldSeparator recognized by GetPot is whitespace?
3980  std::string Value_str = std::string(Value);
3981  std::string delimiters = std::string(FieldSeparator);
3982 
3983  // Skip delimiters at beginning.
3984  std::string::size_type lastPos = Value_str.find_first_not_of(delimiters, 0);
3985 
3986  // Find first "non-delimiter".
3987  std::string::size_type pos = Value_str.find_first_of(delimiters, lastPos);
3988 
3989  // Loop over the input string until all the tokens have been pushed back
3990  // into the local "value" member.
3991  while (std::string::npos != pos || std::string::npos != lastPos)
3992  {
3993  // Found a token, add it to the vector.
3994  value.push_back(Value_str.substr(lastPos, pos - lastPos));
3995 
3996  // Skip delimiters. Note the "not_of"
3997  lastPos = Value_str.find_first_not_of(delimiters, pos);
3998 
3999  // Find next "non-delimiter"
4000  pos = Value_str.find_first_of(delimiters, lastPos);
4001  }
4002 
4003  // We're done, all the tokens should now be in the vector<string>
4004 }
std::string original
Definition: getpot.h:502
STRING_VECTOR value
Definition: getpot.h:501

Member Data Documentation

std::string GetPot::variable::name

data memebers

Definition at line 500 of file getpot.h.

Referenced by GetPot::_DBE_expand(), and operator=().

std::string GetPot::variable::original
STRING_VECTOR GetPot::variable::value

Definition at line 501 of file getpot.h.

Referenced by operator=(), and GetPot::vector_variable_size().


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