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-2020 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 OFstream_H
39 #define OFstream_H
40 
41 #include "OSstream.H"
42 #include "fileName.H"
43 #include "className.H"
44 #include <fstream>
45 #include <memory>
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 namespace Detail
53 {
54 
55 /*---------------------------------------------------------------------------*\
56  Class Detail::OFstreamAllocator Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 //- A std::ostream with the ability to handle compressed files
61 {
62 protected:
63 
64  // Member Data
65 
66  //- The allocated stream pointer (ofstream or ogzstream).
67  std::unique_ptr<std::ostream> allocatedPtr_;
68 
69 
70  // Constructors
71 
72  //- Construct from pathname
74  (
75  const fileName& pathname,
77  const bool append = false
78  );
79 };
80 
81 } // End namespace Detail
82 
83 
84 /*---------------------------------------------------------------------------*\
85  Class OFstream Declaration
86 \*---------------------------------------------------------------------------*/
87 
88 class OFstream
89 :
91  public OSstream
92 {
93 public:
94 
95  //- Declare type-name (with debug switch)
96  ClassName("OFstream");
97 
98 
99  // Constructors
100 
101  //- Construct from pathname
102  explicit OFstream
103  (
104  const fileName& pathname,
105  IOstreamOption streamOpt = IOstreamOption(),
106  const bool append = false
107  );
108 
109  //- Construct from pathname, format (version, compression)
111  (
112  const fileName& pathname,
113  streamFormat fmt,
115  compressionType comp = compressionType::UNCOMPRESSED,
116  const bool append = false
117  )
118  :
119  OFstream(pathname, IOstreamOption(fmt, comp, ver), append)
120  {}
121 
122 
123  //- Destructor
124  ~OFstream() = default;
125 
126 
127  // Member Functions
128 
129  // Access
130 
131  //- Read/write access to the name of the stream
132  using OSstream::name;
133 
134 
135  // STL stream
136 
137  //- Access to underlying std::ostream
138  virtual std::ostream& stdStream();
139 
140  //- Const access to underlying std::ostream
141  virtual const std::ostream& stdStream() const;
142 
143 
144  // Print
145 
146  //- Print stream description to Ostream
147  void print(Ostream& os) const;
148 };
149 
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 //- Global predefined null output stream "/dev/null"
154 extern OFstream Snull;
155 
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 
158 } // End namespace Foam
159 
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161 
162 #endif
163 
164 // ************************************************************************* //
Foam::IOstreamOption::UNCOMPRESSED
compression = false
Definition: IOstreamOption.H:79
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::IOstreamOption::IOstreamOption
constexpr IOstreamOption(streamFormat fmt=streamFormat::ASCII, compressionType comp=compressionType::UNCOMPRESSED) noexcept
Definition: IOstreamOption.H:196
Foam::Detail::OFstreamAllocator
A std::ostream with the ability to handle compressed files.
Definition: OFstream.H:59
Foam::OFstream::ClassName
ClassName("OFstream")
Declare type-name (with debug switch)
Foam::OFstream::OFstream
OFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool append=false)
Construct from pathname.
Definition: OFstream.C:112
Foam::IOstreamOption::currentVersion
static const versionNumber currentVersion
The current version number (2.0)
Definition: IOstreamOption.H:168
Foam::OFstream::~OFstream
~OFstream()=default
Destructor.
Foam::Detail::OFstreamAllocator::OFstreamAllocator
OFstreamAllocator(const fileName &pathname, IOstream::compressionType comp=IOstream::UNCOMPRESSED, const bool append=false)
Construct from pathname.
Definition: OFstream.C:44
Foam::OFstream::print
void print(Ostream &os) const
Print stream description to Ostream.
Definition: OFstream.C:168
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:85
Foam::OSstream::name
virtual const fileName & name() const
Return the name of the stream.
Definition: OSstream.H:107
className.H
Macro definitions for declaring ClassName(), NamespaceName(), etc.
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
fileName.H
Foam::OSstream
Generic output stream using a standard (STL) stream.
Definition: OSstream.H:54
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:70
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:87
Foam::OFstream::stdStream
virtual std::ostream & stdStream()
Access to underlying std::ostream.
Definition: OFstream.C:146
Foam::Detail::OFstreamAllocator::allocatedPtr_
std::unique_ptr< std::ostream > allocatedPtr_
The allocated stream pointer (ofstream or ogzstream).
Definition: OFstream.H:66
Foam::IOstreamOption::compressionType
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
Definition: IOstreamOption.H:77
append
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
Foam::Snull
OFstream Snull
Global predefined null output stream "/dev/null".
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
OSstream.H