OFstream.H
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-2017 OpenFOAM Foundation
9  Copyright (C) 2017-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 Class
28  Foam::OFstream
29 
30 Description
31  Output to file stream, using an OSstream
32 
33 SourceFiles
34  OFstream.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Foam_OFstream_H
39 #define Foam_OFstream_H
40 
41 #include "OSstream.H"
42 #include "className.H"
43 #include "fstreamPointer.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class OFstream Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 class OFstream
55 :
56  private Foam::ofstreamPointer,
57  public OSstream
58 {
59 public:
60 
61  //- Declare type-name (with debug switch)
62  ClassName("OFstream");
63 
64 
65  // Constructors
66 
67  //- Construct a null output file stream.
68  // Behaves like \c /dev/null and is named accordingly
69  explicit OFstream(std::nullptr_t);
70 
71  //- Construct with specified atomic behaviour
72  //- from pathname, stream option, optional append
73  OFstream
74  (
76  const fileName& pathname,
77  IOstreamOption streamOpt = IOstreamOption(),
79  );
80 
81  //- Construct from pathname and other specifications
82  explicit OFstream
83  (
84  const fileName& pathname,
85  IOstreamOption streamOpt = IOstreamOption(),
87  )
88  :
89  OFstream(IOstreamOption::NON_ATOMIC, pathname, streamOpt, append)
90  {}
91 
92  //- Construct from pathname, format (uncompressed), optional append,
93  //- atomic behaviour as per system default
94  OFstream
95  (
96  const fileName& pathname,
100  )
101  :
102  OFstream(pathname, IOstreamOption(fmt, cmp), append)
103  {}
104 
105  //- Construct with specified atomic behaviour
106  //- from pathname, format (uncompressed), optional append
107  OFstream
108  (
110  const fileName& pathname,
114  )
115  :
116  OFstream(atomic, pathname, IOstreamOption(fmt, cmp), append)
117  {}
118 
119 
120  //- Destructor. Possibly invokes an atomic rename
121  //- (preference defined during construction)
122  ~OFstream();
123 
124 
125  // Member Functions
126 
127  //- Read/write access to the name of the stream
128  using OSstream::name;
129 
130 
131  // STL stream
132 
133  //- Access to underlying std::ostream
134  virtual std::ostream& stdStream();
135 
136  //- Const access to underlying std::ostream
137  virtual const std::ostream& stdStream() const;
138 
139  //- Rewind the stream so that it may be written again.
140  //- Reopens the file (truncation)
141  virtual void rewind();
142 
143 
144  // Print
145 
146  //- Print stream description
147  void print(Ostream& os) const;
148 
149 
150  // Additional constructors and methods
151  #ifdef Foam_IOstream_extras
152 
153  //- Construct from pathname, format (version, compression)
154  FOAM_DEPRECATED_FOR(2022-09, "Construct without specifying version")
155  OFstream
156  (
157  const fileName& pathname,
159  IOstreamOption::versionNumber ver,
162  )
163  :
164  OFstream(pathname, IOstreamOption(fmt, ver, cmp), append)
165  {}
166 
167  #endif /* Foam_IOstream_extras */
168 };
169 
170 
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 
173 //- Global predefined null output stream "/dev/null"
174 extern OFstream Snull;
175 
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177 
178 } // End namespace Foam
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 
182 #endif
183 
184 // ************************************************************************* //
virtual const fileName & name() const
Get the name of the output serial stream. (eg, the name of the Fstream file name) ...
Definition: OSstream.H:128
Generic output stream using a standard (STL) stream.
Definition: OSstream.H:50
A wrapped std::ofstream with possible compression handling (ogzstream) that behaves much like a std::...
A class for handling file names.
Definition: fileName.H:71
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
~OFstream()
Destructor. Possibly invokes an atomic rename (preference defined during construction) ...
Definition: OFstream.C:102
Output to file stream, using an OSstream.
Definition: OFstream.H:49
OFstream Snull
Global predefined null output stream "/dev/null".
A simple container for options an IOstream can normally have.
virtual std::ostream & stdStream()
Access to underlying std::ostream.
Definition: OFstream.C:110
class FOAM_DEPRECATED_FOR(2017-05, "Foam::Enum") NamedEnum
Definition: NamedEnum.H:65
constexpr IOstreamOption(streamFormat fmt=streamFormat::ASCII, compressionType comp=compressionType::UNCOMPRESSED) noexcept
Default construct (ASCII, UNCOMPRESSED, currentVersion) or construct with format, compression...
atomicType
Atomic operations (output)
virtual void rewind()
Rewind the stream so that it may be written again. Reopens the file (truncation)
Definition: OFstream.C:140
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
ClassName("OFstream")
Declare type-name (with debug switch)
OBJstream os(runTime.globalPath()/outputName)
appendType
File appending (NON_APPEND | APPEND)
OFstream(std::nullptr_t)
Construct a null output file stream.
Definition: OFstream.C:36
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
Macro definitions for declaring ClassName(), NamespaceName(), etc.
streamFormat
Data format (ascii | binary)
void print(Ostream &os) const
Print stream description.
Definition: OFstream.C:164
Namespace for OpenFOAM.