VectorSpace.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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 Functions * * * * * * * * * * * * //
77 
78 template<class Form, class Cmpt, Foam::direction Ncmpts>
80 {
81  os << value;
82 }
83 
84 
85 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
86 
87 template<class Form, class Cmpt, Foam::direction Ncmpts>
88 Foam::Istream& Foam::operator>>
89 (
90  Istream& is,
91  VectorSpace<Form, Cmpt, Ncmpts>& vs
92 )
93 {
94  // Read beginning of VectorSpace<Cmpt, Ncmpts>
95  is.readBegin("VectorSpace<Form, Cmpt, Ncmpts>");
96 
97  for (direction i=0; i<Ncmpts; i++)
98  {
99  is >> vs.v_[i];
100  }
101 
102  // Read end of VectorSpace<Cmpt, Ncmpts>
103  is.readEnd("VectorSpace<Form, Cmpt, Ncmpts>");
104 
105  // Check state of Istream
106  is.check("operator>>(Istream&, VectorSpace<Form, Cmpt, Ncmpts>&)");
107 
108  return is;
109 }
110 
111 
112 template<class Form, class Cmpt, Foam::direction Ncmpts>
113 Foam::Ostream& Foam::operator<<
114 (
115  Ostream& os,
116  const VectorSpace<Form, Cmpt, Ncmpts>& vs
117 )
118 {
119  os << token::BEGIN_LIST << vs.v_[0];
120 
121  for (direction i=1; i<Ncmpts; i++)
122  {
123  os << token::SPACE << vs.v_[i];
124  }
125 
126  os << token::END_LIST;
127 
128  // Check state of Ostream
129  os.check("operator<<(Ostream&, const VectorSpace<Form, Cmpt, Ncmpts>&)");
130 
131  return os;
132 }
133 
134 
135 // ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
Istream & readEnd(const char *funcName)
Definition: Istream.C:103
Istream & readBegin(const char *funcName)
Definition: Istream.C:86
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Templated vector space.
Definition: VectorSpace.H:79
VectorSpace()
Construct null.
Definition: VectorSpaceI.H:40
Cmpt v_[Ncmpts]
The components of this vector space.
Definition: VectorSpace.H:84
A class for handling words, derived from string.
Definition: word.H:62
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
uint8_t direction
Definition: direction.H:45