OFstream.H 3.85 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6
     \\/     M anipulation  | Copyright (C) 2017 OpenCFD Ltd.
7
8
9
10
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

11
12
13
14
    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
15
16
17
18
19
20
21

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    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
25
26
27

Class
    Foam::OFstream

Description
28
    Output to file stream, using a OSstream
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

SourceFiles
    OFstream.C

\*---------------------------------------------------------------------------*/

#ifndef OFstream_H
#define OFstream_H

#include "OSstream.H"
#include "fileName.H"
#include "className.H"

#include <fstream>
using std::ofstream;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

/*---------------------------------------------------------------------------*\
51
                      Class OFstreamAllocator Declaration
52
53
\*---------------------------------------------------------------------------*/

54
//- A std::ostream with the ability to handle compressed files
55
56
class OFstreamAllocator
{
57
58
59
60
61
62
protected:

    // Member Data

        //- The allocated stream pointer (ofstream or ogzstream).
        std::ostream* allocatedPtr_;
63
64
65
66
67
68
69
70
71
72
73


    // Constructors

        //- Construct from pathname
        OFstreamAllocator
        (
            const fileName& pathname,
            IOstream::compressionType compression=IOstream::UNCOMPRESSED
        );

74

75
76
    //- Destructor
    ~OFstreamAllocator();
77

78
79
80
81
82
83

    // Protected Member Functions

        //- Delete the stream pointer
        void deallocate();

84
85
86
87
};


/*---------------------------------------------------------------------------*\
88
                          Class OFstream Declaration
89
90
91
92
\*---------------------------------------------------------------------------*/

class OFstream
:
93
    public OFstreamAllocator,
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
    public OSstream
{
public:

    // Declare name of the class and its debug switch
    ClassName("OFstream");


    // Constructors

        //- Construct from pathname
        OFstream
        (
            const fileName& pathname,
            streamFormat format=ASCII,
            versionNumber version=currentVersion,
            compressionType compression=UNCOMPRESSED
        );


114
115
    //- Destructor
    ~OFstream();
116
117
118
119


    // Member functions

120
      // Access
121

122
123
        //- Read/write access to the name of the stream
        using OSstream::name;
124
125


126
      // STL stream
127

128
129
        //- Access to underlying std::ostream
        virtual std::ostream& stdStream();
130

131
132
        //- Const access to underlying std::ostream
        virtual const std::ostream& stdStream() const;
133
134


135
      // Print
136

137
138
        //- Print description of IOstream to Ostream
        void print(Ostream& os) const;
139
140
141
142
143
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

144
//- Global predefined null output stream "/dev/null"
145
146
147
148
149
150
151
152
153
154
155
extern OFstream Snull;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //