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 -------------------------------------------------------------------------------
11 License
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 argList::envRelativePath(this->name());
49 }
50 
51 
52 bool Foam::IOstream::check(const char* operation) const
53 {
54  return fatalCheck(operation);
55 }
56 
57 
58 bool 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 
74 void Foam::IOstream::print(Ostream& os) const
75 {
76  os << "IOstream: " << "Version " << version() << ", format "
77  << format() << ", line " << lineNumber();
78 
79  if (opened())
80  {
81  os << ", OPENED";
82  }
83 
84  if (closed())
85  {
86  os << ", CLOSED";
87  }
88 
89  if (good())
90  {
91  os << ", GOOD";
92  }
93 
94  if (eof())
95  {
96  os << ", EOF";
97  }
98 
99  if (fail())
100  {
101  os << ", FAIL";
102  }
103 
104  if (bad())
105  {
106  os << ", BAD";
107  }
108 
109  os << endl;
110 }
111 
112 
113 void Foam::IOstream::print(Ostream& os, const int streamState) const
114 {
115  if (streamState == std::ios_base::goodbit)
116  {
117  os << "ios_base::goodbit set : the last operation on stream succeeded"
118  << endl;
119  }
120  else if (streamState & std::ios_base::badbit)
121  {
122  os << "ios_base::badbit set : characters possibly lost"
123  << endl;
124  }
125  else if (streamState & std::ios_base::failbit)
126  {
127  os << "ios_base::failbit set : some type of formatting error"
128  << endl;
129  }
130  else if (streamState & std::ios_base::eofbit)
131  {
132  os << "ios_base::eofbit set : at end of stream"
133  << endl;
134  }
135 }
136 
137 
138 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
139 
140 template<>
141 Foam::Ostream& Foam::operator<<
142 (
143  Ostream& os,
144  const InfoProxy<IOstream>& iproxy
145 )
146 {
147  (*iproxy).print(os);
148  return os;
149 }
150 
151 
152 // ************************************************************************* //
fileName relativeName() const
Return the name of the stream relative to the current case.
Definition: IOstream.C:39
A class for handling file names.
Definition: fileName.H:72
virtual const fileName & name() const
The name of the stream.
Definition: IOstream.C:33
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:45
static fileName staticName_
Name for any generic stream - normally treat as readonly.
Definition: IOstream.H:115
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
virtual void print(Ostream &os) const
Print stream description to Ostream.
Definition: IOstream.C:67
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:658
word format(conversionProperties.get< word >("format"))
const std::string version
OpenFOAM version (name or stringified number) as a std::string.
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:51
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...