initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / db / IOstreams / Fstreams / OFstream.H
blob7ad2ebd88a17bd08dd93305d2771171da6b3c982
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::OFstream
28 Description
29     Output to file stream.
31 SourceFiles
32     OFstream.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef OFstream_H
37 #define OFstream_H
39 #include "OSstream.H"
40 #include "fileName.H"
41 #include "className.H"
43 #include <fstream>
44 using std::ofstream;
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 namespace Foam
51 class OFstream;
53 /*---------------------------------------------------------------------------*\
54                        Class OFstreamAllocator Declaration
55 \*---------------------------------------------------------------------------*/
57 //- A std::ostream with ability to handle compressed files
58 class OFstreamAllocator
60     friend class OFstream;
62     ostream* ofPtr_;
64     // Constructors
66         //- Construct from pathname
67         OFstreamAllocator
68         (
69             const fileName& pathname,
70             IOstream::compressionType compression=IOstream::UNCOMPRESSED
71         );
73     // Destructor
75         ~OFstreamAllocator();
78 public:
80     // Member functions
82         //- Access to underlying std::ostream
83         ostream& stdStream();
87 /*---------------------------------------------------------------------------*\
88                            Class OFstream Declaration
89 \*---------------------------------------------------------------------------*/
91 class OFstream
93     private OFstreamAllocator,
94     public OSstream
96     // Private data
98         fileName pathname_;
101 public:
103     // Declare name of the class and its debug switch
104     ClassName("OFstream");
107     // Constructors
109         //- Construct from pathname
110         OFstream
111         (
112             const fileName& pathname,
113             streamFormat format=ASCII,
114             versionNumber version=currentVersion,
115             compressionType compression=UNCOMPRESSED
116         );
119     // Destructor
121         ~OFstream();
124     // Member functions
126         // Access
128             //- Return the name of the stream
129             const fileName& name() const
130             {
131                 return pathname_;
132             }
134             //- Return non-const access to the name of the stream
135             fileName& name()
136             {
137                 return pathname_;
138             }
141         // Print
143             //- Print description of IOstream to Ostream
144             void print(Ostream&) const;
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 // Global predefined null output stream
151 extern OFstream Snull;
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 } // End namespace Foam
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 #endif
161 // ************************************************************************* //