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

Constructor & Destructor Documentation

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

constructors, destructors, assignment operator

Definition at line 3616 of file getpot.h.

3617  : name(),
3618  value(),
3619  original()
3620 {}
GETPOT_NAMESPACE::GetPot::variable::variable ( const variable Other)
inline

Definition at line 3625 of file getpot.h.

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

3626 {
3627 #ifdef WIN32
3628  operator=(Other);
3629 #else
3631 #endif
3632 }
GETPOT_NAMESPACE::GetPot::variable::variable ( const char *  Name,
const char *  Value,
const char *  FieldSeparator 
)
inline

Definition at line 3637 of file getpot.h.

References take().

3638  : name(Name)
3639 {
3640  // make a copy of the 'Value'
3641  take(Value, FieldSeparator);
3642 }
GETPOT_NAMESPACE::GetPot::variable::~variable ( )
inline

Definition at line 3712 of file getpot.h.

3713 {}

Member Function Documentation

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

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

3648 {
3649  if (Idx >= value.size())
3650  return 0;
3651  else
3652  return &(value[Idx]);
3653 }
GetPot::variable & GETPOT_NAMESPACE::GetPot::variable::operator= ( const variable Other)
inline

Definition at line 3718 of file getpot.h.

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

Referenced by variable().

3719 {
3720  if (&Other != this)
3721  {
3722  name = Other.name;
3723  value = Other.value;
3724  original = Other.original;
3725  }
3726  return *this;
3727 }
void GETPOT_NAMESPACE::GetPot::variable::take ( const char *  Value,
const char *  FieldSeparator 
)
inline

Definition at line 3658 of file getpot.h.

Referenced by variable().

3659 {
3660  original = std::string(Value); // string member var
3661  value.clear(); // vector<string> member var
3662 
3663  /*
3664  // separate string by white space delimiters using 'strtok'
3665  // thread safe usage of strtok (no static members)
3666  char* spt = 0;
3667  // make a copy of the 'Value'
3668  char* copy = new char[strlen(Value)+1];
3669  strcpy(copy, Value);
3670  char* follow_token = strtok_r(copy, FieldSeparator, &spt);
3671  while (follow_token != 0)
3672  {
3673  value.push_back(std::string(follow_token));
3674  follow_token = strtok_r(NULL, FieldSeparator, &spt);
3675  }
3676 
3677  delete [] copy;
3678  */
3679 
3680  // Don't use strtok, instead tokenize the input char "Value" using std::string operations so
3681  // that the results end up in the local "value" member
3682 
3683  // Construct std::string objects from the input char*s. I think the only
3684  // FieldSeparator recognized by GetPot is whitespace?
3685  std::string Value_str = std::string(Value);
3686  std::string delimiters = std::string(FieldSeparator);
3687 
3688  // Skip delimiters at beginning.
3689  std::string::size_type lastPos = Value_str.find_first_not_of(delimiters, 0);
3690 
3691  // Find first "non-delimiter".
3692  std::string::size_type pos = Value_str.find_first_of(delimiters, lastPos);
3693 
3694  // Loop over the input string until all the tokens have been pushed back
3695  // into the local "value" member.
3696  while (std::string::npos != pos || std::string::npos != lastPos)
3697  {
3698  // Found a token, add it to the vector.
3699  value.push_back(Value_str.substr(lastPos, pos - lastPos));
3700 
3701  // Skip delimiters. Note the "not_of"
3702  lastPos = Value_str.find_first_not_of(delimiters, pos);
3703 
3704  // Find next "non-delimiter"
3705  pos = Value_str.find_first_of(delimiters, lastPos);
3706  }
3707 
3708  // We're done, all the tokens should now be in the vector<string>
3709 }

Member Data Documentation

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

data memebers

Definition at line 395 of file getpot.h.

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

STRING_VECTOR GETPOT_NAMESPACE::GetPot::variable::value

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

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:08 UTC

Hosted By:
SourceForge.net Logo