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  if (bad())
54  {
56  << "error in IOstream " << name() << " for operation " << operation
57  << exit(FatalIOError);
58  }
59 
60  return !bad();
61 }
62 
63 
64 void Foam::IOstream::fatalCheck(const char* operation) const
65 {
66  if (bad())
67  {
69  << "error in IOstream " << name() << " for operation " << operation
70  << exit(FatalIOError);
71  }
72 }
73 
74 
76 {
77  os << "IOstream: " << "Version " << version() << ", format "
78  << format() << ", line " << lineNumber();
79 
80  if (opened())
81  {
82  os << ", OPENED";
83  }
84 
85  if (closed())
86  {
87  os << ", CLOSED";
88  }
89 
90  if (good())
91  {
92  os << ", GOOD";
93  }
94 
95  if (eof())
96  {
97  os << ", EOF";
98  }
99 
100  if (fail())
101  {
102  os << ", FAIL";
103  }
104 
105  if (bad())
106  {
107  os << ", BAD";
108  }
109 
110  os << endl;
111 }
112 
113 
114 void Foam::IOstream::print(Ostream& os, const int streamState) const
115 {
116  if (streamState == ios_base::goodbit)
117  {
118  os << "ios_base::goodbit set : the last operation on stream succeeded"
119  << endl;
120  }
121  else if (streamState & ios_base::badbit)
122  {
123  os << "ios_base::badbit set : characters possibly lost"
124  << endl;
125  }
126  else if (streamState & ios_base::failbit)
127  {
128  os << "ios_base::failbit set : some type of formatting error"
129  << endl;
130  }
131  else if (streamState & ios_base::eofbit)
132  {
133  os << "ios_base::eofbit set : at end of stream"
134  << endl;
135  }
136 }
137 
138 
139 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
140 
141 template<>
143 {
144  ip.t_.print(os);
145  return os;
146 }
147 
148 
149 // ************************************************************************* //
Foam::IOstream::fatalCheck
void fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:64
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 description of IOstream to Ostream.
Definition: IOstream.C:75
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
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:375
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &)
Definition: boundaryPatch.C:102