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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "VectorSpace.H"
29#include "IOstreams.H"
30
31#include <sstream>
32
33// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34
35template<class Form, class Cmpt, Foam::direction Ncmpts>
37(
38 Istream& is
39)
40{
41 is.readBegin("VectorSpace");
42
43 for (direction i=0; i<Ncmpts; i++)
44 {
45 is >> v_[i];
46 }
47
48 is.readEnd("VectorSpace");
49
51}
52
53
54template<class Form, class Cmpt, Foam::direction Ncmpts>
56(
58)
59{
60 std::ostringstream buf;
61
62 buf << '(' << vs.v_[0];
63
64 for (direction i=1; i<Ncmpts; ++i)
65 {
66 buf << ',' << vs.v_[i];
67 }
68
69 buf << ')';
70
71 return buf.str();
72}
73
74
75// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
76
77template<class Form, class Cmpt, Foam::direction Ncmpts>
78Foam::Istream& Foam::operator>>
79(
80 Istream& is,
81 VectorSpace<Form, Cmpt, Ncmpts>& vs
82)
83{
84 is.readBegin("VectorSpace");
85
86 for (direction i=0; i<Ncmpts; i++)
87 {
88 is >> vs.v_[i];
89 }
90
91 is.readEnd("VectorSpace");
92
93 is.check(FUNCTION_NAME);
94
95 return is;
96}
97
98
99template<class Form, class Cmpt, Foam::direction Ncmpts>
100Foam::Ostream& Foam::operator<<
101(
102 Ostream& os,
103 const VectorSpace<Form, Cmpt, Ncmpts>& vs
104)
105{
106 os << token::BEGIN_LIST << vs.v_[0];
107
108 for (direction i=1; i<Ncmpts; ++i)
109 {
110 os << token::SPACE << vs.v_[i];
111 }
112
113 os << token::END_LIST;
114
115 os.check(FUNCTION_NAME);
116 return os;
117}
118
119
120// ************************************************************************* //
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:58
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
Definition: Istream.C:129
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
Definition: Istream.C:111
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Templated vector space.
Definition: VectorSpace.H:79
Cmpt v_[Ncmpts]
The components of this vector space.
Definition: VectorSpace.H:83
VectorSpace()=default
Default construct.
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
uint8_t direction
Definition: direction.H:56
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59