libMesh
Loading...
Searching...
No Matches
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
 
 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)
 

Public Attributes

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

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

◆ variable() [2/3]

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

Definition at line 3916 of file getpot.h.

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

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

◆ variable() [3/3]

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

Definition at line 3928 of file getpot.h.

3929 : name(Name)
3930{
3931 // make a copy of the 'Value'
3932 take(Value, FieldSeparator);
3933}
void take(const char *Value, const char *FieldSeparator)
Definition getpot.h:3949

References take().

◆ ~variable()

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

Definition at line 4003 of file getpot.h.

4004{}

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

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

References value.

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

◆ operator=()

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

Definition at line 4009 of file getpot.h.

4010{
4011 if (&Other != this)
4012 {
4013 name = Other.name;
4014 value = Other.value;
4015 original = Other.original;
4016 }
4017 return *this;
4018}

References name, original, value, and value.

Referenced by variable().

◆ take()

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

Definition at line 3949 of file getpot.h.

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

References value.

Referenced by variable().

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

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