Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
Switch Class Reference

A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none. More...

Public Types

enum  switchType {
  FALSE = 0, TRUE = 1, OFF = 2, ON = 3,
  NO = 4, YES = 5, NO_1 = 6, YES_1 = 7,
  FALSE_1 = 8, TRUE_1 = 9, NONE = 10, PLACEHOLDER = 11,
  INVALID
}
 The various text representations for a switch value. More...
 

Public Member Functions

 Switch ()
 Construct null as false. More...
 
 Switch (const switchType sw)
 Construct from enumerated value. More...
 
 Switch (const bool b)
 Construct from bool. More...
 
 Switch (const int i)
 Construct from integer values (treats integer as bool value) More...
 
 Switch (const std::string &str, const bool allowInvalid=false)
 Construct from std::string, string, word. More...
 
 Switch (const char *str, const bool allowInvalid=false)
 Construct from character array. More...
 
 Switch (Istream &is)
 Construct from Istream. More...
 
bool valid () const
 Return true if the Switch has a valid value. More...
 
const char * asText () const
 Return a text representation of the Switch. More...
 
bool readIfPresent (const word &, const dictionary &)
 Update the value of the Switch if it is found in the dictionary. More...
 
 operator bool () const
 Conversion to bool. More...
 
const Switchoperator= (const switchType sw)
 Assignment from enumerated value. More...
 
const Switchoperator= (const bool b)
 Assignment from bool. More...
 

Static Public Member Functions

static Switch lookupOrAddToDict (const word &, dictionary &, const Switch &defaultValue=false)
 Construct from dictionary, supplying default value so that if the. More...
 

Static Public Attributes

static const char * names [INVALID+1]
 The set of names corresponding to the switchType enumeration. More...
 

Friends

Istreamoperator>> (Istream &, Switch &)
 
Ostreamoperator<< (Ostream &, const Switch &)
 

Detailed Description

A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none.

Source files

Definition at line 60 of file Switch.H.

Member Enumeration Documentation

enum switchType

The various text representations for a switch value.

These also correspond to the entries in names.

Enumerator
FALSE 
TRUE 
OFF 
ON 
NO 
YES 
NO_1 
YES_1 
FALSE_1 
TRUE_1 
NONE 
PLACEHOLDER 
INVALID 

Definition at line 88 of file Switch.H.

Constructor & Destructor Documentation

Switch ( )
inline

Construct null as false.

Definition at line 119 of file Switch.H.

Referenced by Switch::Switch().

Here is the caller graph for this function:

Switch ( const switchType  sw)
inline

Construct from enumerated value.

Definition at line 125 of file Switch.H.

Switch ( const bool  b)
inline

Construct from bool.

Definition at line 131 of file Switch.H.

Switch ( const int  i)
inline

Construct from integer values (treats integer as bool value)

Definition at line 137 of file Switch.H.

References Switch::asText(), Switch::lookupOrAddToDict(), Switch::readIfPresent(), Switch::Switch(), and Switch::valid().

Here is the call graph for this function:

Switch ( const std::string &  str,
const bool  allowInvalid = false 
)
inline

Construct from std::string, string, word.

Optionally allow bad words, and catch the error elsewhere

Definition at line 144 of file Switch.H.

Switch ( const char *  str,
const bool  allowInvalid = false 
)
inline

Construct from character array.

Optionally allow bad words, and catch the error elsewhere

Definition at line 151 of file Switch.H.

Switch ( Istream is)

Construct from Istream.

Definition at line 31 of file SwitchIO.C.

Member Function Documentation

Foam::Switch lookupOrAddToDict ( const word name,
dictionary dict,
const Switch defaultValue = false 
)
static

Construct from dictionary, supplying default value so that if the.

value is not found, it is added into the dictionary.

Definition at line 107 of file Switch.C.

References dictionary::lookupOrAddDefault(), and Foam::name().

Referenced by Switch::Switch().

Here is the call graph for this function:

Here is the caller graph for this function:

bool valid ( ) const

Return true if the Switch has a valid value.

Definition at line 119 of file Switch.C.

References Switch::NONE.

Referenced by IOstream::compressionEnum(), and Switch::Switch().

Here is the caller graph for this function:

const char * asText ( ) const

Return a text representation of the Switch.

Definition at line 125 of file Switch.C.

References Switch::names.

Referenced by Switch::Switch(), and polyMeshFilterSettings::writeSettings().

Here is the caller graph for this function:

bool readIfPresent ( const word name,
const dictionary dict 
)

Update the value of the Switch if it is found in the dictionary.

Definition at line 131 of file Switch.C.

References Foam::name(), and dictionary::readIfPresent().

Referenced by qZeta::read(), and Switch::Switch().

Here is the call graph for this function:

Here is the caller graph for this function:

operator bool ( ) const
inline

Conversion to bool.

Definition at line 184 of file Switch.H.

const Switch& operator= ( const switchType  sw)
inline

Assignment from enumerated value.

Definition at line 190 of file Switch.H.

const Switch& operator= ( const bool  b)
inline

Assignment from bool.

Definition at line 197 of file Switch.H.

References Switch::FALSE, Switch::operator<<, Switch::operator>>, and Switch::TRUE.

Friends And Related Function Documentation

Istream& operator>> ( Istream ,
Switch  
)
friend

Referenced by Switch::operator=().

Ostream& operator<< ( Ostream ,
const Switch  
)
friend

Referenced by Switch::operator=().

Member Data Documentation

const char * names
static
Initial value:
=
{
"false", "true",
"off", "on",
"no", "yes",
"n", "y",
"f", "t",
"none", "true",
"invalid"
}

The set of names corresponding to the switchType enumeration.

Includes an extra entry for "invalid".

Definition at line 103 of file Switch.H.

Referenced by Switch::asText(), and Foam::operator<<().


The documentation for this class was generated from the following files: