GETPOT_NAMESPACE::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

◆ variable() [1/3]

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

constructors, destructors, assignment operator

Definition at line 3913 of file getpot.h.

3914  : name(),
3915  value(),
3916  original()
3917 {}

◆ variable() [2/3]

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

Definition at line 3922 of file getpot.h.

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

3923 {
3924 #ifdef WIN32
3925  operator=(Other);
3926 #else
3928 #endif
3929 }
variable & operator=(const variable &Other)
Definition: getpot.h:4015

◆ variable() [3/3]

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

Definition at line 3934 of file getpot.h.

References take().

3935  : name(Name)
3936 {
3937  // make a copy of the 'Value'
3938  take(Value, FieldSeparator);
3939 }
void take(const char *Value, const char *FieldSeparator)
Definition: getpot.h:3955

◆ ~variable()

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

Definition at line 4009 of file getpot.h.

4010 {}

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

References value.

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

3945 {
3946  if (Idx >= value.size())
3947  return 0;
3948  else
3949  return &(value[Idx]);
3950 }

◆ operator=()

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

Definition at line 4015 of file getpot.h.

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

Referenced by variable().

4016 {
4017  if (&Other != this)
4018  {
4019  name = Other.name;
4020  value = Other.value;
4021  original = Other.original;
4022  }
4023  return *this;
4024 }

◆ take()

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

Definition at line 3955 of file getpot.h.

References value.

Referenced by variable().

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

Member Data Documentation

◆ name

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

data members

Definition at line 500 of file getpot.h.

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

◆ original

◆ value

STRING_VECTOR GETPOT_NAMESPACE::GetPot::variable::value

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