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-2024 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,
69  const IOstream::compressionType compression
71  const bool append = false
72  );
73 
74  //- Destructor
76 
77 };
78 
79 
80 /*---------------------------------------------------------------------------*\
81  Class OFstream Declaration
82 \*---------------------------------------------------------------------------*/
83 
84 class OFstream
85 :
86  private OFstreamAllocator,
87  public OSstream
88 {
89  // Private Data
90 
91  fileName filePath_;
92 
93 
94 public:
95 
96  // Declare name of the class and its debug switch
97  ClassName("OFstream");
98 
99 
100  // Constructors
101 
102  //- Construct from filePath
103  OFstream
104  (
105  const fileName& filePath,
106  const streamFormat format = ASCII,
109  const bool append = false
110  );
111 
112 
113  //- Destructor
114  ~OFstream();
115 
116 
117  // Member Functions
118 
119  // Access
120 
121  //- Return the name of the stream
122  const fileName& name() const
123  {
124  return filePath_;
125  }
126 
127  //- Return non-const access to the name of the stream
128  fileName& name()
129  {
130  return filePath_;
131  }
132 
133 
134  // STL stream
135 
136  //- Access to underlying std::ostream
137  virtual ostream& stdStream();
138 
139  //- Const access to underlying std::ostream
140  virtual const ostream& stdStream() const;
141 
142 
143  // Print
144 
145  //- Print description of IOstream to Ostream
146  void print(Ostream&) const;
147 };
148 
149 
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 
152 //- Global predefined null output stream "/dev/null"
153 extern OFstream Snull;
154 
155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 
157 } // End namespace Foam
158 
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 
161 #endif
162 
163 // ************************************************************************* //
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:377
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
versionNumber version() const
Return the stream version.
Definition: IOstream.H:399
compressionType compression() const
Return the stream compression.
Definition: IOstream.H:416
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:87
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:121
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".