FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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...

#include <OpenFOAM/Switch.H>


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

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 Switch &  operator= (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

Istream &  operator>> (Istream &, Switch &)
Ostream &  operator<< (Ostream &, const Switch &)

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


Constructor & Destructor Documentation

Switch (  ) [inline]

Construct null as false.

Definition at line 128 of file Switch.H.

Switch ( const bool   value  ) [inline]

Construct from bool.

Definition at line 134 of file Switch.H.

Switch ( const int   value  ) [inline]

Construct from integer values (treats integer as bool value)

Definition at line 140 of file Switch.H.

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

Construct from std::string, string, word.

Definition at line 146 of file Switch.H.

Switch ( const char *   value  ) [inline]

Construct from character array.

Definition at line 152 of file Switch.H.

Switch ( Istream &   is  )

Construct from Istream.

Definition at line 31 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 47 of file Switch.C.

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

Referenced by Foam::operator>>().

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

References Foam::abort(), Foam::FatalError, FatalErrorIn, Switch::INVALID, Foam::nl, Switch::NO, Switch::NO_1, Switch::NONE, Switch::YES, and Switch::YES_1.

bool asBool ( const switchType   sw  ) [static]

Return a bool representation of a switchType.

Definition at line 90 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 98 of file Switch.C.

References Foam::abort(), Foam::FatalError, FatalErrorIn, Switch::INVALID, and Foam::nl.

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

Return a text representation of a bool value.

Definition at line 123 of file Switch.C.

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

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

Return a text representation of a switchType.

Definition at line 129 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 136 of file Switch.C.

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

operator bool (  ) const [inline]

Conversion to bool.

Definition at line 173 of file Switch.H.

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

Assignment from bool.

Definition at line 179 of file Switch.H.

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

bool readIfPresent ( const word &   name,
const dictionary &   dict  
)

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

Definition at line 148 of file Switch.C.

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

Referenced by qZeta::read().


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

Referenced by Foam::operator<<().


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