libMesh
Public Member Functions | Public Attributes | List of all members
GETPOT_NAMESPACE::GetPot::variable Struct Reference

Variable to be specified on the command line or in input files. More...

Public Member Functions

 variable ()
 constructors, destructors, assignment operator More...
 
 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
 get a specific element in the string vector (return 0 if not present) More...
 

Public Attributes

std::string name
 data members More...
 
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 480 of file getpot.h.

Constructor & Destructor Documentation

◆ variable() [1/3]

GETPOT_NAMESPACE::GetPot::variable::variable ( )
inline

constructors, destructors, assignment operator

Definition at line 3906 of file getpot.h.

3907  : name(),
3908  value(),
3909  original()
3910 {}
std::string name
data members
Definition: getpot.h:502

◆ variable() [2/3]

GETPOT_NAMESPACE::GetPot::variable::variable ( const variable Other)
inline

Definition at line 3915 of file getpot.h.

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

3916 {
3917 #ifdef WIN32
3918  operator=(Other);
3919 #else
3921 #endif
3922 }
variable & operator=(const variable &Other)
Definition: getpot.h:4008

◆ variable() [3/3]

GETPOT_NAMESPACE::GetPot::variable::variable ( const char *  Name,
const char *  Value,
const char *  FieldSeparator 
)
inline

Definition at line 3927 of file getpot.h.

References take().

3928  : name(Name)
3929 {
3930  // make a copy of the 'Value'
3931  take(Value, FieldSeparator);
3932 }
std::string name
data members
Definition: getpot.h:502
void take(const char *Value, const char *FieldSeparator)
Definition: getpot.h:3948

◆ ~variable()

GETPOT_NAMESPACE::GetPot::variable::~variable ( )
inline

Definition at line 4002 of file getpot.h.

4003 {}

Member Function Documentation

◆ get_element()

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

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

Definition at line 3937 of file getpot.h.

References value.

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

3938 {
3939  if (Idx >= value.size())
3940  return 0;
3941  else
3942  return &(value[Idx]);
3943 }

◆ operator=()

GetPot::variable & GETPOT_NAMESPACE::GetPot::variable::operator= ( const variable Other)
inline

Definition at line 4008 of file getpot.h.

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

Referenced by variable().

4009 {
4010  if (&Other != this)
4011  {
4012  name = Other.name;
4013  value = Other.value;
4014  original = Other.original;
4015  }
4016  return *this;
4017 }
std::string name
data members
Definition: getpot.h:502

◆ take()

void GETPOT_NAMESPACE::GetPot::variable::take ( const char *  Value,
const char *  FieldSeparator 
)
inline

Definition at line 3948 of file getpot.h.

References value.

Referenced by variable().

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

Member Data Documentation

◆ name

std::string GETPOT_NAMESPACE::GetPot::variable::name

data members

Definition at line 502 of file getpot.h.

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

◆ original

std::string GETPOT_NAMESPACE::GetPot::variable::original

◆ value

STRING_VECTOR GETPOT_NAMESPACE::GetPot::variable::value

Definition at line 503 of file getpot.h.

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


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