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 | Copyright (C) 2011 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 pathname
67  (
68  const fileName& pathname,
70  );
71 
72  //- Destructor
74 
75 };
76 
77 
78 /*---------------------------------------------------------------------------*\
79  Class OFstream Declaration
80 \*---------------------------------------------------------------------------*/
81 
82 class OFstream
83 :
84  private OFstreamAllocator,
85  public OSstream
86 {
87  // Private data
88 
89  fileName pathname_;
90 
91 
92 public:
93 
94  // Declare name of the class and its debug switch
95  ClassName("OFstream");
96 
97 
98  // Constructors
99 
100  //- Construct from pathname
101  OFstream
102  (
103  const fileName& pathname,
104  streamFormat format=ASCII,
105  versionNumber version=currentVersion,
106  compressionType compression=UNCOMPRESSED
107  );
108 
109 
110  //- Destructor
111  ~OFstream();
112 
113 
114  // Member functions
115 
116  // Access
117 
118  //- Return the name of the stream
119  const fileName& name() const
120  {
121  return pathname_;
122  }
123 
124  //- Return non-const access to the name of the stream
125  fileName& name()
126  {
127  return pathname_;
128  }
129 
130 
131  // STL stream
132 
133  //- Access to underlying std::ostream
134  virtual ostream& stdStream();
135 
136  //- Const access to underlying std::ostream
137  virtual const ostream& stdStream() const;
138 
139 
140  // Print
141 
142  //- Print description of IOstream to Ostream
143  void print(Ostream&) const;
144 };
145 
146 
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148 
149 //- Global predefined null output stream "/dev/null"
150 extern OFstream Snull;
151 
152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
153 
154 } // End namespace Foam
155 
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 
158 #endif
159 
160 // ************************************************************************* //
Output to file stream.
Definition: OFstream.H:81
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Generic output stream.
Definition: OSstream.H:51
A std::ostream with ability to handle compressed files.
Definition: OFstream.H:56
Namespace for OpenFOAM.
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition: className.H:69
word format(conversionProperties.lookup("format"))
Macro definitions for declaring ClassName(), NamespaceName(), etc.
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
OFstream Snull
Global predefined null output stream "/dev/null".
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
A class for handling file names.
Definition: fileName.H:69
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
friend class OFstream
Definition: OFstream.H:58
Version number type.
Definition: IOstream.H:96