OpenFOAM logo
Open Source CFD Toolkit

Switch.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2005 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Switch
00027 
00028 Description
00029     A simple wrapper around bool so that it can be read as
00030     on/off, yes/no or y/n.
00031 
00032 SourceFiles
00033     Switch.C
00034     SwitchIO.C
00035 
00036 \*---------------------------------------------------------------------------*/
00037 
00038 #ifndef Switch_H
00039 #define Switch_H
00040 
00041 #include "bool.H"
00042 #include "word.H"
00043 
00044 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00045 
00046 namespace Foam
00047 {
00048 
00049 /*---------------------------------------------------------------------------*\
00050                            Class Switch Declaration
00051 \*---------------------------------------------------------------------------*/
00052 
00053 class Switch
00054 {
00055     // Private data
00056 
00057         word wordSwitch_;
00058         bool logicalSwitch_;
00059 
00060     // Private member functions
00061 
00062         word wordValue(const bool) const;
00063         bool boolValue(const word&) const;
00064 
00065 
00066 public:
00067 
00068     // Constructors
00069 
00070         //- Construct from components
00071         Switch(const bool value)
00072         :
00073             wordSwitch_(wordValue(value)),
00074             logicalSwitch_(value)
00075         {}
00076 
00077         //- Construct from word
00078         Switch(const word& w)
00079         :
00080             wordSwitch_(w),
00081             logicalSwitch_(boolValue(w))
00082         {}
00083 
00084         //- Construct from Istream
00085         Switch(Istream& is);
00086 
00087 
00088     // Member Operators
00089 
00090         Switch& operator=(const Switch& s)
00091         {
00092             wordSwitch_ = s.wordSwitch_;
00093             logicalSwitch_ = s.logicalSwitch_;
00094 
00095             return *this;
00096         }
00097 
00098         operator bool() const
00099         {
00100             return logicalSwitch_;
00101         }
00102 
00103         operator const word&() const
00104         {
00105             return wordSwitch_;
00106         }
00107 
00108 
00109     // IOstream Operators
00110 
00111         friend Istream& operator>>(Istream&, Switch&);
00112         friend Ostream& operator<<(Ostream&, const Switch&);
00113 };
00114 
00115 
00116 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00117 
00118 } // End namespace Foam
00119 
00120 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00121 
00122 #endif
00123 
00124 // ************************************************************************* //
For further information go to www.openfoam.org