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-2016 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 template<class Form, class Cmpt, Foam::direction Ncmpts>
35 (
36  Istream& is
37 )
38 {
39  // Read beginning of VectorSpace<Cmpt>
40  is.readBegin("VectorSpace<Form, Cmpt, Ncmpts>");
41 
42  for (direction i=0; i<Ncmpts; i++)
43  {
44  is >> v_[i];
45  }
46 
47  // Read end of VectorSpace<Cmpt>
48  is.readEnd("VectorSpace<Form, Cmpt, Ncmpts>");
49 
50  // Check state of Istream
51  is.check("VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace(Istream&)");
52 }
53 
54 
55 template<class Form, class Cmpt, Foam::direction Ncmpts>
57 (
59 )
60 {
61  std::ostringstream buf;
62 
63  buf << '(' << vs.v_[0];
64 
65  for (direction i=1; i<Ncmpts; i++)
66  {
67  buf << ',' << vs.v_[i];
68  }
69 
70  buf << ')';
71 
72  return buf.str();
73 }
74 
75 
76 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
77 
78 template<class Form, class Cmpt, Foam::direction Ncmpts>
79 Foam::Istream& Foam::operator>>
80 (
81  Istream& is,
83 )
84 {
85  // Read beginning of VectorSpace<Cmpt, Ncmpts>
86  is.readBegin("VectorSpace<Form, Cmpt, Ncmpts>");
87 
88  for (direction i=0; i<Ncmpts; i++)
89  {
90  is >> vs.v_[i];
91  }
92 
93  // Read end of VectorSpace<Cmpt, Ncmpts>
94  is.readEnd("VectorSpace<Form, Cmpt, Ncmpts>");
95 
96  // Check state of Istream
97  is.check("operator>>(Istream&, VectorSpace<Form, Cmpt, Ncmpts>&)");
98 
99  return is;
100 }
101 
102 
103 template<class Form, class Cmpt, Foam::direction Ncmpts>
104 Foam::Ostream& Foam::operator<<
105 (
106  Ostream& os,
108 )
109 {
110  os << token::BEGIN_LIST << vs.v_[0];
111 
112  for (direction i=1; i<Ncmpts; i++)
113  {
114  os << token::SPACE << vs.v_[i];
115  }
116 
117  os << token::END_LIST;
118 
119  // Check state of Ostream
120  os.check("operator<<(Ostream&, const VectorSpace<Form, Cmpt, Ncmpts>&)");
121 
122  return os;
123 }
124 
125 
126 // ************************************************************************* //
Istream & readBegin(const char *funcName)
Definition: Istream.C:86
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
uint8_t direction
Definition: direction.H:45
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
VectorSpace()
Construct null.
Definition: VectorSpaceI.H:40
Templated vector space.
Definition: VectorSpace.H:53
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Istream & readEnd(const char *funcName)
Definition: Istream.C:103
A class for handling words, derived from string.
Definition: word.H:59
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Cmpt v_[Ncmpts]
The components of this vector space.
Definition: VectorSpace.H:81