Loading...
Searching...
No Matches
directionIO.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) 2016 OpenFOAM Foundation
9 Copyright (C) 2018-2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "direction.H"
30#include "IOstreams.H"
31
32// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33
35{
36 direction val(0);
37 is >> val;
38
39 return val;
40}
41
42
43Foam::Istream& Foam::operator>>(Istream& is, direction& val)
44{
45 token t(is);
46
47 if (!t.good())
48 {
50 << "Bad token - could not get uint8/direction"
51 << exit(FatalIOError);
52 is.setBad();
53 return is;
54 }
55
56 if (t.isLabel())
57 {
58 val = direction(t.labelToken());
59 }
60 else
61 {
63 << "Wrong token type - expected label (uint8/direction), found "
64 << t.info()
65 << exit(FatalIOError);
66 is.setBad();
67 return is;
68 }
69
70 is.check(FUNCTION_NAME);
71 return is;
72}
73
74
75Foam::Ostream& Foam::operator<<(Ostream& os, const direction val)
77 os.write(label(val));
78 os.check(FUNCTION_NAME);
79 return os;
80}
81
82
83std::ostream& Foam::operator<<(std::ostream& os, const direction val)
84{
85 os << int(val);
86 return os;
87}
88
89
90// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
void setBad() noexcept
Set stream state to be 'bad'.
Definition IOstream.H:488
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition IOstream.C:45
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A token holds an item read from Istream.
Definition token.H:70
bool isLabel() const noexcept
Integral token is convertible to Foam::label.
Definition tokenI.H:843
bool good() const noexcept
True if token is not UNDEFINED or ERROR.
Definition tokenI.H:584
label labelToken() const
Return integer type as label value or Error.
Definition tokenI.H:869
InfoProxy< token > info() const noexcept
Return info proxy, for printing token information to a stream.
Definition token.H:1253
Direction is an 8-bit unsigned integer type used to represent Cartesian directions,...
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
direction readDirection(Istream &is)
Read direction (uint8_t) from stream.
Definition directionIO.C:27
Istream & operator>>(Istream &, directionInfo &)
uint8_t direction
Definition direction.H:49
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125