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-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 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 
45 #include <fstream>
46 using std::ofstream;
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 namespace Detail
54 {
55 
56 /*---------------------------------------------------------------------------*\
57  Class Detail::OFstreamAllocator Declaration
58 \*---------------------------------------------------------------------------*/
59 
60 //- A std::ostream with the ability to handle compressed files
62 {
63 protected:
64 
65  // Member Data
66 
67  //- The allocated stream pointer (ofstream or ogzstream).
68  std::ostream* allocatedPtr_;
69 
70 
71  // Constructors
72 
73  //- Construct from pathname
75  (
76  const fileName& pathname,
78  const bool append = false
79  );
80 
81 
82  //- Destructor
84 
85 
86  // Protected Member Functions
87 
88  //- Delete the stream pointer
89  void deallocate();
90 
91 };
92 
93 } // End namespace Detail
94 
95 
96 /*---------------------------------------------------------------------------*\
97  Class OFstream Declaration
98 \*---------------------------------------------------------------------------*/
99 
100 class OFstream
101 :
103  public OSstream
104 {
105 public:
106 
107  // Declare name of the class and its debug switch
108  ClassName("OFstream");
109 
110 
111  // Constructors
112 
113  //- Construct from pathname
114  OFstream
115  (
116  const fileName& pathname,
120  const bool append = false
121  );
122 
123 
124  //- Destructor
125  ~OFstream() = default;
126 
127 
128  // Member functions
129 
130  // Access
131 
132  //- Read/write access to the name of the stream
133  using OSstream::name;
134 
135 
136  // STL stream
137 
138  //- Access to underlying std::ostream
139  virtual std::ostream& stdStream();
140 
141  //- Const access to underlying std::ostream
142  virtual const std::ostream& stdStream() const;
143 
144 
145  // Print
146 
147  //- Print description of IOstream to Ostream
148  void print(Ostream& os) const;
149 };
150 
151 
152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
153 
154 //- Global predefined null output stream "/dev/null"
155 extern OFstream Snull;
156 
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 
159 } // End namespace Foam
160 
161 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 
163 #endif
164 
165 // ************************************************************************* //
Foam::IOstreamOption::UNCOMPRESSED
compression = false
Definition: IOstreamOption.H:73
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::Detail::OFstreamAllocator
A std::ostream with the ability to handle compressed files.
Definition: OFstream.H:60
Foam::OFstream::ClassName
ClassName("OFstream")
Foam::IOstreamOption::format
streamFormat format() const noexcept
Get the current stream format.
Definition: IOstreamOption.H:273
Foam::IOstreamOption::currentVersion
static const versionNumber currentVersion
The current version number.
Definition: IOstreamOption.H:193
Foam::OFstream::~OFstream
~OFstream()=default
Destructor.
Foam::OFstream::print
void print(Ostream &os) const
Print description of IOstream to Ostream.
Definition: OFstream.C:189
Foam::Detail::OFstreamAllocator::~OFstreamAllocator
~OFstreamAllocator()
Destructor.
Definition: OFstream.C:105
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:79
Foam::OSstream::name
virtual const fileName & name() const
Return the name of the stream.
Definition: OSstream.H:91
className.H
Macro definitions for declaring ClassName(), NamespaceName(), etc.
Foam::OFstream::OFstream
OFstream(const fileName &pathname, streamFormat format=ASCII, versionNumber version=currentVersion, compressionType compression=UNCOMPRESSED, const bool append=false)
Construct from pathname.
Definition: OFstream.C:124
fileName.H
Foam::OSstream
Generic output stream.
Definition: OSstream.H:54
Foam::IOstreamOption::version
versionNumber version() const noexcept
Get the stream version.
Definition: IOstreamOption.H:321
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:64
Foam::Detail::OFstreamAllocator::deallocate
void deallocate()
Delete the stream pointer.
Definition: OFstream.C:111
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:99
Foam::Detail::OFstreamAllocator::OFstreamAllocator
OFstreamAllocator(const fileName &pathname, IOstream::compressionType compression=IOstream::UNCOMPRESSED, const bool append=false)
Construct from pathname.
Definition: OFstream.C:43
Foam::IOstreamOption::ASCII
"ascii"
Definition: IOstreamOption.H:66
Foam::Detail::OFstreamAllocator::allocatedPtr_
std::ostream * allocatedPtr_
The allocated stream pointer (ofstream or ogzstream).
Definition: OFstream.H:67
Foam::OFstream::stdStream
virtual std::ostream & stdStream()
Access to underlying std::ostream.
Definition: OFstream.C:167
Foam::IOstreamOption::compressionType
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
Definition: IOstreamOption.H:71
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
Foam::IOstreamOption::compression
compressionType compression() const noexcept
Get the stream compression.
Definition: IOstreamOption.H:297
OSstream.H