directionIO.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) 2016-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 "direction.H"
27 #include "IOstreams.H"
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
32 {
33  direction val;
34  is >> val;
35 
36  return val;
37 }
38 
39 
41 {
42  token t(is);
43 
44  if (!t.good())
45  {
46  is.setBad();
47  return is;
48  }
49 
50  if (t.isLabel())
51  {
52  d = direction(t.labelToken());
53  }
54  else
55  {
56  is.setBad();
58  << "wrong token type - expected direction, found " << t.info()
59  << exit(FatalIOError);
60 
61  return is;
62  }
63 
64  // Check state of Istream
65  is.check("Istream& operator>>(Istream&, direction&)");
66 
67  return is;
68 }
69 
70 
72 {
73  os.write(label(d));
74  os.check("Ostream& operator<<(Ostream&, const direction)");
75  return os;
76 }
77 
78 
79 std::ostream& Foam::operator<<(std::ostream& os, const direction d)
80 {
81  os << int(d);
82  return os;
83 }
84 
85 
86 // ************************************************************************* //
bool isLabel() const
Definition: tokenI.H:271
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
InfoProxy< token > info() const
Return info proxy.
Definition: token.H:380
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
A token holds items read from Istream.
Definition: token.H:69
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
void setBad()
Set stream to be bad.
Definition: IOstream.H:487
Istream & operator>>(Istream &, directionInfo &)
bool good() const
Definition: tokenI.H:197
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
Direction is an 8-bit unsigned integer type used to represent the Cartesian directions etc...
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
Ostream & operator<<(Ostream &, const ensightPart &)
label labelToken() const
Definition: tokenI.H:276
virtual Ostream & write(const token &)=0
Write next token to stream.
direction readDirection(Istream &)
Definition: directionIO.C:31
IOerror FatalIOError