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

Scalar_.C

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00027 
00028 namespace Foam
00029 {
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 const char* const pTraits<Scalar>::typeName = "scalar";
00034 const Scalar pTraits<Scalar>::zero = 0.0;
00035 const Scalar pTraits<Scalar>::one = 1.0;
00036 const Scalar pTraits<Scalar>::min = -ScalarVGREAT;
00037 const Scalar pTraits<Scalar>::max = ScalarVGREAT;
00038 
00039 const char* pTraits<Scalar>::componentNames[] = { "x" };
00040 
00041 pTraits<Scalar>::pTraits(Istream& is)
00042 {
00043     is >> p_;
00044 }
00045 
00046 
00047 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00048 
00049 word name(const Scalar val)
00050 {
00051     std::ostringstream buf;
00052     buf << val;
00053     return buf.str();
00054 }
00055 
00056 
00057 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
00058 
00059 Scalar readScalar(Istream& is)
00060 {
00061     Scalar rs;
00062     is >> rs;
00063 
00064     return rs;
00065 }
00066 
00067 
00068 Istream& operator>>(Istream& is, Scalar& s)
00069 {
00070     token t(is);
00071 
00072     if (!t.good())
00073     {
00074         is.setBad();
00075         return is;
00076     }
00077 
00078     if (t.isNumber())
00079     {
00080         s = t.number();
00081     }
00082     else
00083     {
00084         is.setBad();
00085         FatalIOErrorIn("operator>>(Istream&, Scalar&)", is)
00086             << "wrong token type - expected Scalar found " << t.info()
00087             << exit(FatalIOError);
00088 
00089         return is;
00090     }
00091 
00092     // Check state of Istream
00093     is.check("Istream& operator>>(Istream&, Scalar&)");
00094 
00095     return is;
00096 }
00097 
00098 
00099 Ostream& operator<<(Ostream& os, const Scalar s)
00100 {
00101     os.write(s);
00102     os.check("Ostream& operator<<(Ostream&, const Scalar&)");
00103     return os;
00104 }
00105 
00106 
00107 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00108 
00109 } // End namespace Foam
00110 
00111 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines