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-2021 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 * * * * * * * * * * * * * //
39
41{
42 return staticName_;
43}
44
45
47{
48 return staticName_;
49}
50
51
53{
54 return argList::envRelativePath(this->name());
55}
56
57
58bool Foam::IOstream::check(const char* operation) const
59{
60 return fatalCheck(operation);
61}
62
63
64bool Foam::IOstream::fatalCheck(const char* operation) const
65{
66 const bool ok = !bad();
67
68 if (!ok)
69 {
71 << "error in IOstream " << relativeName()
72 << " for operation " << operation
74 }
75
76 return ok;
77}
78
79
81{
82 os << "IOstream: " << "Version " << version() << ", format "
83 << format() << ", line " << lineNumber();
84
85 if (opened())
86 {
87 os << ", OPENED";
88 }
89
90 if (closed())
91 {
92 os << ", CLOSED";
93 }
94
95 if (good())
96 {
97 os << ", GOOD";
98 }
99
100 if (eof())
101 {
102 os << ", EOF";
103 }
104
105 if (fail())
106 {
107 os << ", FAIL";
108 }
109
110 if (bad())
111 {
112 os << ", BAD";
113 }
114
115 os << endl;
116}
117
118
119void Foam::IOstream::print(Ostream& os, const int streamState) const
120{
121 if (streamState == ios_base::goodbit)
122 {
123 os << "ios_base::goodbit set : the last operation on stream succeeded"
124 << endl;
125 }
126 else if (streamState & ios_base::badbit)
127 {
128 os << "ios_base::badbit set : characters possibly lost"
129 << endl;
130 }
131 else if (streamState & ios_base::failbit)
132 {
133 os << "ios_base::failbit set : some type of formatting error"
134 << endl;
135 }
136 else if (streamState & ios_base::eofbit)
137 {
138 os << "ios_base::eofbit set : at end of stream"
139 << endl;
140 }
141}
142
143
144// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
145
146template<>
148{
149 ip.t_.print(os);
150 return os;
151}
152
153
154// ************************************************************************* //
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:64
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
virtual const fileName & name() const
Return the name of the stream.
Definition: IOstream.C:40
static fileName staticName_
Name for any generic stream - normally treat as readonly.
Definition: IOstream.H:106
fileName relativeName() const
Return the name of the stream relative to the current case.
Definition: IOstream.C:52
A helper class for outputting values to Ostream.
Definition: InfoProxy.H:52
const T & t_
Definition: InfoProxy.H:55
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
static fileName envRelativePath(const fileName &input, const bool caseTag=false)
Definition: argList.C:556
A class for handling file names.
Definition: fileName.H:76
scalar print()
Print to screen.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
OBJstream os(runTime.globalPath()/outputName)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
IOerror FatalIOError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
word format(conversionProperties.get< word >("format"))