1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 A simple wrapper around bool so that it can be read as
30 on/off, yes/no or y/n.
36 \*---------------------------------------------------------------------------*/
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 // Forward declaration of friend functions and operators
53 Istream& operator>>(Istream&, Switch&);
54 Ostream& operator<<(Ostream&, const Switch&);
58 /*---------------------------------------------------------------------------*\
59 Class Switch Declaration
60 \*---------------------------------------------------------------------------*/
69 // Private member functions
71 word wordValue(const bool) const;
72 bool boolValue(const word&) const;
79 //- Construct from components
80 Switch(const bool value)
82 wordSwitch_(wordValue(value)),
86 //- Construct from word
90 logicalSwitch_(boolValue(w))
93 //- Construct from Istream
96 //- Construct from dictionary, supplying default value so that if the
97 // value is not found, it is added into the dictionary.
98 static Switch lookupOrAddToDict
102 const Switch& defaultValue = false
108 Switch& operator=(const Switch& s)
110 wordSwitch_ = s.wordSwitch_;
111 logicalSwitch_ = s.logicalSwitch_;
116 operator bool() const
118 return logicalSwitch_;
121 operator const word&() const
129 //- Update the value of the Switch if it is found in the dictionary
130 bool readIfPresent(const word&, const dictionary&);
133 // IOstream Operators
135 friend Istream& operator>>(Istream&, Switch&);
136 friend Ostream& operator<<(Ostream&, const Switch&);
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
142 } // End namespace Foam
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148 // ************************************************************************* //