Loading...
Searching...
No Matches
IOstream.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-2015 OpenFOAM Foundation
9 Copyright (C) 2018-2022 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 "IOstream.H"
30#include "error.H"
31#include "argList.H"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
36
37
38// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
41{
42 return staticName_;
43}
44
49}
50
52bool Foam::IOstream::check(const char* operation) const
53{
54 return fatalCheck(operation);
55}
56
57
58bool Foam::IOstream::fatalCheck(const char* operation) const
59{
60 const bool ok = !bad();
61
62 if (!ok)
63 {
65 << "error in IOstream " << relativeName()
66 << " for operation " << operation
68 }
69
70 return ok;
71}
72
73
74bool Foam::IOstream::fatalCheckNativeSizes(const char* operation) const
75{
76 const bool ok = this->checkNativeSizes();
77
78 if (!ok)
79 {
81 << "Error in stream: " << relativeName()
82 << " for operation " << operation << nl
83 << "Expecting (label=" << (8*sizeof(label))
84 << ";scalar=" << (8*sizeof(scalar))
85 << ") found (label=" << (8*this->labelByteSize())
86 << ";scalar=" << (8*this->scalarByteSize()) << ')' << nl
88 }
89
90 return ok;
91}
92
93
94void Foam::IOstream::print(Ostream& os) const
95{
96 os << "IOstream: " << "Version " << version() << ", format "
97 << format() << ", line " << lineNumber();
98
99 if (opened())
100 {
101 os << ", OPENED";
102 }
103
104 if (closed())
105 {
106 os << ", CLOSED";
107 }
108
109 if (good())
110 {
111 os << ", GOOD";
112 }
113
114 if (eof())
115 {
116 os << ", EOF";
117 }
118
119 if (fail())
120 {
121 os << ", FAIL";
122 }
123
124 if (bad())
125 {
126 os << ", BAD";
127 }
128
129 os << endl;
130}
131
132
133void Foam::IOstream::print(Ostream& os, const int streamState) const
134{
135 if (streamState == std::ios_base::goodbit)
136 {
137 os << "goodbit set : the last operation on stream succeeded" << endl;
138 }
139 else if (streamState & std::ios_base::badbit)
140 {
141 os << "badbit set : characters possibly lost" << endl;
142 }
143 else if (streamState & std::ios_base::failbit)
144 {
145 os << "failbit set : some type of formatting error" << endl;
146 }
147 else if (streamState & std::ios_base::eofbit)
148 {
149 os << "eofbit set : at end of stream" << endl;
151}
152
153
154// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
155
156template<>
157Foam::Ostream& Foam::operator<<
158(
159 Ostream& os,
160 const InfoProxy<IOstream>& iproxy
161)
162{
163 (*iproxy).print(os);
164 return os;
165}
166
167
168// ************************************************************************* //
versionNumber version() const noexcept
Get the stream version.
bool fail() const noexcept
True if next operation will fail.
Definition IOstream.H:297
label lineNumber() const noexcept
Const access to the current stream line number.
Definition IOstream.H:409
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition IOstream.C:51
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition IOstream.C:45
unsigned scalarByteSize() const noexcept
The sizeof (scalar) in bytes associated with the stream.
Definition IOstream.H:340
bool good() const noexcept
True if next operation might succeed.
Definition IOstream.H:281
bool bad() const noexcept
True if stream is corrupted.
Definition IOstream.H:305
bool opened() const noexcept
True if stream has been opened.
Definition IOstream.H:265
virtual void print(Ostream &os) const
Print stream description to Ostream.
Definition IOstream.C:87
virtual const fileName & name() const
The name of the stream.
Definition IOstream.C:33
bool eof() const noexcept
True if end of input seen.
Definition IOstream.H:289
bool checkNativeSizes() const noexcept
Test if the label/scalar byte-size associated with the stream are the native label/scalar sizes.
Definition IOstream.H:386
bool fatalCheckNativeSizes(const char *operation) const
Assert that the label/scalar byte-size associated with the stream are the native label/scalar sizes.
Definition IOstream.C:67
static fileName staticName_
Name for any generic stream - normally treat as readonly.
Definition IOstream.H:115
bool closed() const noexcept
True if stream is closed.
Definition IOstream.H:273
unsigned labelByteSize() const noexcept
The sizeof (label) in bytes associated with the stream.
Definition IOstream.H:332
fileName relativeName() const
Return the name of the stream relative to the current case.
Definition IOstream.C:39
A helper class for outputting values to Ostream.
Definition InfoProxy.H:49
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
static fileName envRelativePath(const fileName &input, const bool caseTag=false)
Return the input relative to the globalPath by stripping off a leading value of the envGlobalPath.
Definition argList.C:675
A class for handling file names.
Definition fileName.H:75
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
OBJstream os(runTime.globalPath()/outputName)
auto & name
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
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
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
word format(conversionProperties.get< word >("format"))