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