complex.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-2018 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 "complex.H"
27 #include "IOstreams.H"
28 
29 #include <sstream>
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 const char* const Foam::complex::typeName = "complex";
36 
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 
40 {
41  is >> *this;
42 }
43 
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
48 {
49  std::ostringstream buf;
50  buf << '(' << c.Re() << ',' << c.Im() << ')';
51  return buf.str();
52 }
53 
54 
55 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
56 
58 {
59  // Read beginning of complex
60  is.readBegin("complex");
61 
62  is >> c.re >> c.im;
63 
64  // Read end of complex
65  is.readEnd("complex");
66 
67  // Check state of Istream
68  is.check("operator>>(Istream&, complex&)");
69 
70  return is;
71 }
72 
73 
75 {
76  os << token::BEGIN_LIST
77  << c.re << token::SPACE << c.im
78  << token::END_LIST;
79 
80  return os;
81 }
82 
83 
84 // ************************************************************************* //
Istream & readBegin(const char *funcName)
Definition: Istream.C:86
complex()
Construct null.
Definition: complexI.H:33
static const complex one
Definition: complex.H:94
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
scalar Im() const
Definition: complexI.H:52
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
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
Istream & operator>>(Istream &, directionInfo &)
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
static const complex zero
Definition: complex.H:93
const dimensionedScalar c
Speed of light in a vacuum.
Ostream & operator<<(Ostream &, const ensightPart &)
static const char *const typeName
Definition: complex.H:91
Extension to the c++ complex library type.
Definition: complex.H:76
scalar Re() const
Definition: complexI.H:46