VectorSpace.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "VectorSpace.H"
27 #include "IOstreams.H"
28 
29 #include <sstream>
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 // Construct from Istream
34 template<class Form, class Cmpt, int nCmpt>
36 (
37  Istream& is
38 )
39 {
40  // Read beginning of VectorSpace<Cmpt>
41  is.readBegin("VectorSpace<Form, Cmpt, nCmpt>");
42 
43  for (int i=0; i<nCmpt; i++)
44  {
45  is >> v_[i];
46  }
47 
48  // Read end of VectorSpace<Cmpt>
49  is.readEnd("VectorSpace<Form, Cmpt, nCmpt>");
50 
51  // Check state of Istream
52  is.check("VectorSpace<Form, Cmpt, nCmpt>::VectorSpace(Istream&)");
53 }
54 
55 
56 // Return a string representation
57 template<class Form, class Cmpt, int nCmpt>
60 (
61  const VectorSpace<Form, Cmpt, nCmpt>& vs
62 )
63 {
64  std::ostringstream buf;
65 
66  buf << '(';
67 
68  for (int i=0; i<nCmpt-1; i++)
69  {
70  buf << vs.v_[i] << ',';
71  }
72 
73  buf << vs.v_[nCmpt-1] << ')';
74 
75  return buf.str();
76 }
77 
78 
79 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
80 
81 template<class Form, class Cmpt, int nCmpt>
82 Foam::Istream& Foam::operator>>
83 (
84  Istream& is,
85  VectorSpace<Form, Cmpt, nCmpt>& vs
86 )
87 {
88  // Read beginning of VectorSpace<Cmpt, nCmpt>
89  is.readBegin("VectorSpace<Form, Cmpt, nCmpt>");
90 
91  for (int i=0; i<nCmpt; i++)
92  {
93  is >> vs.v_[i];
94  }
95 
96  // Read end of VectorSpace<Cmpt, nCmpt>
97  is.readEnd("VectorSpace<Form, Cmpt, nCmpt>");
98 
99  // Check state of Istream
100  is.check("operator>>(Istream&, VectorSpace<Form, Cmpt, nCmpt>&)");
101 
102  return is;
103 }
104 
105 
106 template<class Form, class Cmpt, int nCmpt>
107 Foam::Ostream& Foam::operator<<
108 (
109  Ostream& os,
110  const VectorSpace<Form, Cmpt, nCmpt>& vs
111 )
112 {
113  os << token::BEGIN_LIST;
114 
115  for (int i=0; i<nCmpt-1; i++)
116  {
117  os << vs.v_[i] << token::SPACE;
118  }
119 
120  os << vs.v_[nCmpt-1] << token::END_LIST;
121 
122  // Check state of Ostream
123  os.check("operator<<(Ostream&, const VectorSpace<Form, Cmpt, nCmpt>&)");
124 
125  return os;
126 }
127 
128 
129 // ************************************************************************* //
VectorSpace.H
Foam::Istream::readEnd
Istream & readEnd(const char *funcName)
Definition: Istream.C:105
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::VectorSpace::VectorSpace
VectorSpace()
Construct null.
Definition: VectorSpaceI.H:39
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::Istream::readBegin
Istream & readBegin(const char *funcName)
Definition: Istream.C:88
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47