queso-0.56.0
Public Member Functions | Public Attributes | List of all members
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 456 of file getpot.h.

Constructor & Destructor Documentation

GetPot::variable::variable ( )
inline

constructors, destructors, assignment operator

Definition at line 3839 of file getpot.h.

3840  : name(),
3841  value(),
3842  original()
3843 {}
std::string name
Definition: getpot.h:478
std::string original
Definition: getpot.h:480
STRING_VECTOR value
Definition: getpot.h:479
GetPot::variable::variable ( const variable Other)
inline

Definition at line 3848 of file getpot.h.

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

3849 {
3850 #ifdef WIN32
3851  operator=(Other);
3852 #else
3854 #endif
3855 }
variable & operator=(const variable &Other)
Definition: getpot.h:3941
GetPot::variable::variable ( const char *  Name,
const char *  Value,
const char *  FieldSeparator 
)
inline

Definition at line 3860 of file getpot.h.

References take().

3861  : name(Name)
3862 {
3863  // make a copy of the 'Value'
3864  take(Value, FieldSeparator);
3865 }
std::string name
Definition: getpot.h:478
void take(const char *Value, const char *FieldSeparator)
Definition: getpot.h:3881
GetPot::variable::~variable ( )
inline

Definition at line 3935 of file getpot.h.

3936 {}

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

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

3871 {
3872  if (Idx >= value.size())
3873  return 0;
3874  else
3875  return &(value[Idx]);
3876 }
STRING_VECTOR value
Definition: getpot.h:479
GetPot::variable & GetPot::variable::operator= ( const variable Other)
inline

Definition at line 3941 of file getpot.h.

References name, original, and value.

Referenced by variable().

3942 {
3943  if (&Other != this)
3944  {
3945  name = Other.name;
3946  value = Other.value;
3947  original = Other.original;
3948  }
3949  return *this;
3950 }
std::string name
Definition: getpot.h:478
std::string original
Definition: getpot.h:480
STRING_VECTOR value
Definition: getpot.h:479
void GetPot::variable::take ( const char *  Value,
const char *  FieldSeparator 
)
inline

Definition at line 3881 of file getpot.h.

Referenced by variable().

3882 {
3883  original = std::string(Value); // string member var
3884  value.clear(); // vector<string> member var
3885 
3886  /*
3887  // separate string by white space delimiters using 'strtok'
3888  // thread safe usage of strtok (no static members)
3889  char* spt = 0;
3890  // make a copy of the 'Value'
3891  char* copy = new char[strlen(Value)+1];
3892  strcpy(copy, Value);
3893  char* follow_token = strtok_r(copy, FieldSeparator, &spt);
3894  while (follow_token != 0)
3895  {
3896  value.push_back(std::string(follow_token));
3897  follow_token = strtok_r(NULL, FieldSeparator, &spt);
3898  }
3899 
3900  delete [] copy;
3901  */
3902 
3903  // Don't use strtok, instead tokenize the input char "Value" using std::string operations so
3904  // that the results end up in the local "value" member
3905 
3906  // Construct std::string objects from the input char*s. I think the only
3907  // FieldSeparator recognized by GetPot is whitespace?
3908  std::string Value_str = std::string(Value);
3909  std::string delimiters = std::string(FieldSeparator);
3910 
3911  // Skip delimiters at beginning.
3912  std::string::size_type lastPos = Value_str.find_first_not_of(delimiters, 0);
3913 
3914  // Find first "non-delimiter".
3915  std::string::size_type pos = Value_str.find_first_of(delimiters, lastPos);
3916 
3917  // Loop over the input string until all the tokens have been pushed back
3918  // into the local "value" member.
3919  while (std::string::npos != pos || std::string::npos != lastPos)
3920  {
3921  // Found a token, add it to the vector.
3922  value.push_back(Value_str.substr(lastPos, pos - lastPos));
3923 
3924  // Skip delimiters. Note the "not_of"
3925  lastPos = Value_str.find_first_not_of(delimiters, pos);
3926 
3927  // Find next "non-delimiter"
3928  pos = Value_str.find_first_of(delimiters, lastPos);
3929  }
3930 
3931  // We're done, all the tokens should now be in the vector<string>
3932 }
std::string original
Definition: getpot.h:480
STRING_VECTOR value
Definition: getpot.h:479

Member Data Documentation

std::string GetPot::variable::name

data memebers

Definition at line 478 of file getpot.h.

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

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

Definition at line 479 of file getpot.h.

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


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

Generated on Tue Nov 29 2016 10:53:12 for queso-0.56.0 by  doxygen 1.8.5