1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
28 #include "dictionary.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 // NB: values chosen such that bitwise '&' 0x1 yields the bool value
33 // INVALID is also evaluates to false, but don't rely on that
34 const char* Foam::Switch::names[Foam::Switch::INVALID+1] =
41 "none", "true", // is there a reasonable counterpart to "none"?
46 // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
48 Foam::Switch::switchType Foam::Switch::asEnum
50 const std::string& str,
51 const bool allowInvalid
54 for (int sw = 0; sw < Switch::INVALID; ++sw)
88 return switchType(sw);
97 FatalErrorIn("Switch::asEnum(const std::string&, const bool)")
98 << "unknown switch word " << str << nl
102 return Switch::INVALID;
106 Foam::Switch Foam::Switch::lookupOrAddToDict
110 const Switch& defaultValue
113 return dict.lookupOrAddDefault<Switch>(name, defaultValue);
117 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
119 bool Foam::Switch::valid() const
121 return switch_ <= Switch::NONE;
125 const char* Foam::Switch::asText() const
127 return names[switch_];
131 bool Foam::Switch::readIfPresent(const word& name, const dictionary& dict)
133 return dict.readIfPresent<Switch>(name, *this);
137 // ************************************************************************* //