OFstream.H 3.96 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5
    \\  /    A nd           | www.openfoam.com
OpenFOAM bot's avatar
OpenFOAM bot committed
6 7
     \\/     M anipulation  |
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
8
    Copyright (C) 2011-2017 OpenFOAM Foundation
Mark Olesen's avatar
Mark Olesen committed
9
    Copyright (C) 2017-2020 OpenCFD Ltd.
10 11 12 13
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

14 15 16 17
    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.
18 19 20 21 22 23 24

    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
25
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
26 27 28 29 30

Class
    Foam::OFstream

Description
31
    Output to file stream, using an OSstream
32 33 34 35 36 37 38 39 40 41 42 43 44

SourceFiles
    OFstream.C

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

#ifndef OFstream_H
#define OFstream_H

#include "OSstream.H"
#include "fileName.H"
#include "className.H"
#include <fstream>
45
#include <memory>
46 47 48 49 50 51

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

namespace Foam
{

52 53 54
namespace Detail
{

55
/*---------------------------------------------------------------------------*\
56
                  Class Detail::OFstreamAllocator Declaration
57 58
\*---------------------------------------------------------------------------*/

59
//- A std::ostream with the ability to handle compressed files
60 61
class OFstreamAllocator
{
62 63 64 65 66
protected:

    // Member Data

        //- The allocated stream pointer (ofstream or ogzstream).
67
        std::unique_ptr<std::ostream> allocatedPtr_;
68 69 70 71 72 73 74 75


    // Constructors

        //- Construct from pathname
        OFstreamAllocator
        (
            const fileName& pathname,
76
            IOstream::compressionType comp = IOstream::UNCOMPRESSED,
77
            const bool append = false
78 79 80
        );
};

81
} // End namespace Detail
82

83 84

/*---------------------------------------------------------------------------*\
85
                          Class OFstream Declaration
86 87 88 89
\*---------------------------------------------------------------------------*/

class OFstream
:
90
    public Detail::OFstreamAllocator,
91 92 93 94
    public OSstream
{
public:

Mark Olesen's avatar
Mark Olesen committed
95
    //- Declare type-name (with debug switch)
96 97 98 99 100 101
    ClassName("OFstream");


    // Constructors

        //- Construct from pathname
Mark Olesen's avatar
Mark Olesen committed
102
        explicit OFstream
103 104 105 106
        (
            const fileName& pathname,
            streamFormat format=ASCII,
            versionNumber version=currentVersion,
107 108
            compressionType compression=UNCOMPRESSED,
            const bool append = false
109 110 111
        );


112
    //- Destructor
113
    ~OFstream() = default;
114 115


Mark Olesen's avatar
Mark Olesen committed
116
    // Member Functions
117

118
    // Access
119

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


124
    // STL stream
125

126 127
        //- Access to underlying std::ostream
        virtual std::ostream& stdStream();
128

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


133
    // Print
134

Mark Olesen's avatar
Mark Olesen committed
135
        //- Print stream description to Ostream
136
        void print(Ostream& os) const;
137 138 139 140 141
};


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

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

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

} // End namespace Foam

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

#endif

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