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

VectorSpace.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 #include "VectorSpace.H"
00027 #include <OpenFOAM/IOstreams.H>
00028 
00029 #include <sstream>
00030 
00031 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00032 
00033 // Construct from Istream
00034 template<class Form, class Cmpt, int nCmpt>
00035 Foam::VectorSpace<Form, Cmpt, nCmpt>::VectorSpace
00036 (
00037     Istream& is
00038 )
00039 {
00040     // Read beginning of VectorSpace<Cmpt>
00041     is.readBegin("VectorSpace<Form, Cmpt, nCmpt>");
00042 
00043     for (int i=0; i<nCmpt; i++)
00044     {
00045         is >> v_[i];
00046     }
00047 
00048     // Read end of VectorSpace<Cmpt>
00049     is.readEnd("VectorSpace<Form, Cmpt, nCmpt>");
00050 
00051     // Check state of Istream
00052     is.check("VectorSpace<Form, Cmpt, nCmpt>::VectorSpace(Istream&)");
00053 }
00054 
00055 
00056 // Return a string representation
00057 template<class Form, class Cmpt, int nCmpt>
00058 Foam::word
00059 Foam::name
00060 (
00061     const VectorSpace<Form, Cmpt, nCmpt>& vs
00062 )
00063 {
00064     std::ostringstream buf;
00065 
00066     buf << '(';
00067 
00068     for (int i=0; i<nCmpt-1; i++)
00069     {
00070         buf << vs.v_[i] << ',';
00071     }
00072 
00073     buf << vs.v_[nCmpt-1] << ')';
00074 
00075     return buf.str();
00076 }
00077 
00078 
00079 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
00080 
00081 template<class Form, class Cmpt, int nCmpt>
00082 Foam::Istream& Foam::operator>>
00083 (
00084     Istream& is,
00085     VectorSpace<Form, Cmpt, nCmpt>& vs
00086 )
00087 {
00088     // Read beginning of VectorSpace<Cmpt, nCmpt>
00089     is.readBegin("VectorSpace<Form, Cmpt, nCmpt>");
00090 
00091     for (int i=0; i<nCmpt; i++)
00092     {
00093         is >> vs.v_[i];
00094     }
00095 
00096     // Read end of VectorSpace<Cmpt, nCmpt>
00097     is.readEnd("VectorSpace<Form, Cmpt, nCmpt>");
00098 
00099     // Check state of Istream
00100     is.check("operator>>(Istream&, VectorSpace<Form, Cmpt, nCmpt>&)");
00101 
00102     return is;
00103 }
00104 
00105 
00106 template<class Form, class Cmpt, int nCmpt>
00107 Foam::Ostream& Foam::operator<<
00108 (
00109     Ostream& os,
00110     const VectorSpace<Form, Cmpt, nCmpt>& vs
00111 )
00112 {
00113     os << token::BEGIN_LIST;
00114 
00115     for (int i=0; i<nCmpt-1; i++)
00116     {
00117         os << vs.v_[i] << token::SPACE;
00118     }
00119 
00120     os << vs.v_[nCmpt-1] << token::END_LIST;
00121 
00122     // Check state of Ostream
00123     os.check("operator<<(Ostream&, const VectorSpace<Form, Cmpt, nCmpt>&)");
00124 
00125     return os;
00126 }
00127 
00128 
00129 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines