All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OFstream.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::OFstream
26 
27 Description
28  Output to file stream.
29 
30 SourceFiles
31  OFstream.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef OFstream_H
36 #define OFstream_H
37 
38 #include "OSstream.H"
39 #include "fileName.H"
40 #include "className.H"
41 
42 #include <fstream>
43 using std::ofstream;
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 class OFstream;
51 
52 /*---------------------------------------------------------------------------*\
53  Class OFstreamAllocator Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 //- A std::ostream with ability to handle compressed files
58 {
59  friend class OFstream;
60 
61  ostream* ofPtr_;
62 
63  // Constructors
64 
65  //- Construct from filePath
67  (
68  const fileName& filePath,
70  const bool append = false
71  );
72 
73  //- Destructor
75 
76 };
77 
78 
79 /*---------------------------------------------------------------------------*\
80  Class OFstream Declaration
81 \*---------------------------------------------------------------------------*/
82 
83 class OFstream
84 :
85  private OFstreamAllocator,
86  public OSstream
87 {
88  // Private Data
89 
90  fileName filePath_;
91 
92 
93 public:
94 
95  // Declare name of the class and its debug switch
96  ClassName("OFstream");
97 
98 
99  // Constructors
100 
101  //- Construct from filePath
102  OFstream
103  (
104  const fileName& filePath,
108  const bool append = false
109  );
110 
111 
112  //- Destructor
113  ~OFstream();
114 
115 
116  // Member Functions
117 
118  // Access
119 
120  //- Return the name of the stream
121  const fileName& name() const
122  {
123  return filePath_;
124  }
125 
126  //- Return non-const access to the name of the stream
127  fileName& name()
128  {
129  return filePath_;
130  }
131 
132 
133  // STL stream
134 
135  //- Access to underlying std::ostream
136  virtual ostream& stdStream();
137 
138  //- Const access to underlying std::ostream
139  virtual const ostream& stdStream() const;
140 
141 
142  // Print
143 
144  //- Print description of IOstream to Ostream
145  void print(Ostream&) const;
146 };
147 
148 
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 
151 //- Global predefined null output stream "/dev/null"
152 extern OFstream Snull;
153 
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 
156 } // End namespace Foam
157 
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 
160 #endif
161 
162 // ************************************************************************* //
Version number type.
Definition: IOstream.H:97
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
streamFormat format() const
Return current stream format.
Definition: IOstream.H:374
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
versionNumber version() const
Return the stream version.
Definition: IOstream.H:396
compressionType compression() const
Return the stream compression.
Definition: IOstream.H:413
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
A std::ostream with ability to handle compressed files.
Definition: OFstream.H:57
friend class OFstream
Definition: OFstream.H:58
Output to file stream.
Definition: OFstream.H:86
virtual ostream & stdStream()
Access to underlying std::ostream.
Definition: OFstream.C:159
ClassName("OFstream")
~OFstream()
Destructor.
Definition: OFstream.C:153
void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: OFstream.C:181
const fileName & name() const
Return the name of the stream.
Definition: OFstream.H:120
Generic output stream.
Definition: OSstream.H:54
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A class for handling file names.
Definition: fileName.H:82
Macro definitions for declaring ClassName(), NamespaceName(), etc.
Namespace for OpenFOAM.
OFstream Snull
Global predefined null output stream "/dev/null".