OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

Switch Class Reference

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

List of all members.


Public Types

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

Public Member Functions

 Switch ()
 Construct null as false.
 Switch (const bool value)
 Construct from bool.
 Switch (const int value)
 Construct from integer values (treats integer as bool value).
 Switch (const std::string &value)
 Construct from std::string, string, word.
 Switch (const char *value)
 Construct from character array.
 Switch (Istream &is)
 Construct from Istream.
 operator bool () const
 Conversion to bool.
const Switchoperator= (const bool b)
 Assignment from bool.
bool readIfPresent (const word &, const dictionary &)
 Update the value of the Switch if it is found in the dictionary.

Static Public Member Functions

static switchType asEnum (const bool)
 Return a switchType representation of a bool.
static switchType asEnum (const std::string &, const bool allowInvalid=false)
 Return a switchType representation of a word.
static bool asBool (const switchType)
 Return a bool representation of a switchType.
static bool asBool (const std::string &, const bool allowInvalid=false)
 Return a bool representation of a word.
static const char * asText (const bool)
 Return a text representation of a bool value.
static const char * asText (const switchType)
 Return a text representation of a switchType.
static Switch lookupOrAddToDict (const word &, dictionary &, const Switch &defaultValue=false)
 Construct from dictionary, supplying default value so that if the.

Static Public Attributes

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

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 or y/n or none.

Source files

Definition at line 56 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 
NONE 
PLACEHOLDER 
INVALID 

Definition at line 73 of file Switch.H.


Constructor & Destructor Documentation

Switch (  )  [inline]

Construct null as false.

Definition at line 131 of file Switch.H.

Switch ( const bool  value  )  [inline]

Construct from bool.

Definition at line 137 of file Switch.H.

Switch ( const int  value  )  [inline]

Construct from integer values (treats integer as bool value).

Definition at line 143 of file Switch.H.

Switch ( const std::string &  value  )  [inline]

Construct from std::string, string, word.

Definition at line 149 of file Switch.H.

Switch ( const char *  value  )  [inline]

Construct from character array.

Definition at line 155 of file Switch.H.

Switch ( Istream is  ) 

Construct from Istream.

Definition at line 23 of file SwitchIO.C.


Member Function Documentation

Foam::Switch::switchType asEnum ( const bool  b  )  [static]

Return a switchType representation of a bool.

Definition at line 39 of file Switch.C.

Foam::Switch::switchType asEnum ( const std::string &  str,
const bool  allowInvalid = false 
) [static]

Return a switchType representation of a word.

Optionally allow bad words, and catch the error elsewhere

Definition at line 46 of file Switch.C.

References Switch::FALSE, and Switch::TRUE.

bool asBool ( const switchType  sw  )  [static]

Return a bool representation of a switchType.

Definition at line 82 of file Switch.C.

bool asBool ( const std::string &  str,
const bool  allowInvalid = false 
) [static]

Return a bool representation of a word.

Optionally allow bad words, and catch the error elsewhere

Definition at line 90 of file Switch.C.

const char * asText ( const bool  b  )  [static]

Return a text representation of a bool value.

Definition at line 115 of file Switch.C.

const char * asText ( const switchType  sw  )  [static]

Return a text representation of a switchType.

Definition at line 121 of file Switch.C.

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

References Switch::names.

operator bool (  )  const [inline]

Conversion to bool.

Definition at line 178 of file Switch.H.

References Switch::FALSE, and Switch::TRUE.

const Switch& operator= ( const bool  b  )  [inline]

Assignment from bool.

Definition at line 184 of file Switch.H.

bool readIfPresent ( const word name,
const dictionary dict 
)

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

Definition at line 140 of file Switch.C.

References dictionary::lookupOrAddDefault().

Here is the call graph for this function:


Friends And Related Function Documentation

Istream& operator>> ( Istream ,
Switch  
) [friend]

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


Member Data Documentation

const char * names [static]

Initial value:

{
    "false", "true",
    "off",   "on",
    "no",    "yes",
    "n",     "y",
    "none",  "true",  
    "invalid"
}
The set of names corresponding to the switchType enumeration.

Includes an extra entry for "invalid".

Definition at line 90 of file Switch.H.

Referenced by Switch::lookupOrAddToDict().


The documentation for this class was generated from the following files:
  • src/OpenFOAM/primitives/bools/Switch/Switch.H
  • src/OpenFOAM/primitives/bools/Switch/Switch.C
  • src/OpenFOAM/primitives/bools/Switch/SwitchIO.C
Copyright © 2000-2009 OpenCFD Ltd