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/any. More...

Public Types

enum class  switchType : unsigned char {
  False = 0 , True = 1 , off = 2 , on = 3 ,
  no = 4 , yes = 5 , n = 6 , y = 7 ,
  f = 8 , t = 9 , none = 10 , any = 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...
 
void operator= (const switchType sw)
 Assignment to enumerated value. More...
 
void operator= (const bool b)
 Assignment to bool. More...
 

Static Public Member Functions

static unsigned char toInt (const switchType x)
 Convert switchType to integer (unsigned char) More...
 
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 unsigned char nSwitchType
 Number of switchTypes. More...
 

Friends

switchType operator++ (switchType &x)
 Increment the switchType counter. More...
 
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/any.

Source files

Definition at line 60 of file Switch.H.

Member Enumeration Documentation

◆ switchType

enum switchType : unsigned char
strong

The various text representations for a switch value.

These also correspond to the entries in names.

Enumerator
False 
True 
off 
on 
no 
yes 
none 
any 
invalid 

Definition at line 68 of file Switch.H.

Constructor & Destructor Documentation

◆ Switch() [1/7]

Switch ( )
inline

Construct null as false.

Definition at line 128 of file Switch.H.

References Foam::False.

◆ Switch() [2/7]

Switch ( const switchType  sw)
inline

Construct from enumerated value.

Definition at line 134 of file Switch.H.

◆ Switch() [3/7]

Switch ( const bool  b)
inline

Construct from bool.

Definition at line 140 of file Switch.H.

References Foam::False.

◆ Switch() [4/7]

Switch ( const int  i)
inline

Construct from integer values (treats integer as bool value)

Definition at line 146 of file Switch.H.

References Foam::False.

◆ Switch() [5/7]

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 153 of file Switch.H.

◆ Switch() [6/7]

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 160 of file Switch.H.

◆ Switch() [7/7]

Switch ( Istream is)

Construct from Istream.

Definition at line 31 of file SwitchIO.C.

Member Function Documentation

◆ toInt()

static unsigned char toInt ( const switchType  x)
inlinestatic

Convert switchType to integer (unsigned char)

Definition at line 90 of file Switch.H.

References x.

Referenced by Switch::operator bool().

Here is the caller graph for this function:

◆ lookupOrAddToDict()

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 110 of file Switch.C.

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

Referenced by makeMomentumTransportModelTypes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ valid()

bool valid ( ) const

Return true if the Switch has a valid value.

Definition at line 123 of file Switch.C.

Referenced by IOstream::compressionEnum(), and Foam::operator>>().

Here is the caller graph for this function:

◆ asText()

const char * asText ( ) const

Return a text representation of the Switch.

Definition at line 129 of file Switch.C.

◆ readIfPresent()

bool readIfPresent ( const word name,
const dictionary dict 
)

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

Definition at line 135 of file Switch.C.

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

Referenced by DAC< ThermoType >::DAC(), and makeMomentumTransportModelTypes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator bool()

operator bool ( ) const
inline

Conversion to bool.

Definition at line 193 of file Switch.H.

References Switch::toInt().

Here is the call graph for this function:

◆ operator=() [1/2]

void operator= ( const switchType  sw)
inline

Assignment to enumerated value.

Definition at line 199 of file Switch.H.

◆ operator=() [2/2]

void operator= ( const bool  b)
inline

Assignment to bool.

Definition at line 205 of file Switch.H.

References b, Switch::False, and Switch::True.

Friends And Related Function Documentation

◆ operator++

switchType operator++ ( switchType x)
friend

Increment the switchType counter.

Definition at line 96 of file Switch.H.

◆ operator>>

Istream& operator>> ( Istream ,
Switch  
)
friend

◆ operator<<

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

Member Data Documentation

◆ nSwitchType

const unsigned char nSwitchType
static
Initial value:
=
static_cast<unsigned char>(switchType::invalid) + 1

Number of switchTypes.

Definition at line 86 of file Switch.H.


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