OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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