ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / OpenFOAM / db / IOstreams / Fstreams / OFstream.C
blobda9fc290a2b5201c4e409e9d97ce20a3809e3c00
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.
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.
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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "OFstream.H"
27 #include "OSspecific.H"
28 #include "gzstream.h"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 defineTypeNameAndDebug(Foam::OFstream, 0);
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 Foam::OFstreamAllocator::OFstreamAllocator
39     const fileName& pathname,
40     IOstream::compressionType compression
43     ofPtr_(NULL)
45     if (pathname.empty())
46     {
47         if (OFstream::debug)
48         {
49             Info<< "OFstreamAllocator::OFstreamAllocator(const fileName&) : "
50                    "cannot open null file " << endl;
51         }
52     }
54     if (compression == IOstream::COMPRESSED)
55     {
56         // get identically named uncompressed version out of the way
57         if (isFile(pathname, false))
58         {
59             rm(pathname);
60         }
62         ofPtr_ = new ogzstream((pathname + ".gz").c_str());
63     }
64     else
65     {
66         // get identically named compressed version out of the way
67         if (isFile(pathname + ".gz", false))
68         {
69             rm(pathname + ".gz");
70         }
72         ofPtr_ = new ofstream(pathname.c_str());
73     }
77 Foam::OFstreamAllocator::~OFstreamAllocator()
79     delete ofPtr_;
83 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
85 Foam::OFstream::OFstream
87     const fileName& pathname,
88     streamFormat format,
89     versionNumber version,
90     compressionType compression
93     OFstreamAllocator(pathname, compression),
94     OSstream(*ofPtr_, "OFstream.sinkFile_", format, version, compression),
95     pathname_(pathname)
97     setClosed();
98     setState(ofPtr_->rdstate());
100     if (!good())
101     {
102         if (debug)
103         {
104             Info<< "IFstream::IFstream(const fileName&,"
105                    "streamFormat format=ASCII,"
106                    "versionNumber version=currentVersion) : "
107                    "could not open file for input\n"
108                    "in stream " << info() << Foam::endl;
109         }
111         setBad();
112     }
113     else
114     {
115         setOpened();
116     }
118     lineNumber_ = 1;
122 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
124 Foam::OFstream::~OFstream()
128 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
130 std::ostream& Foam::OFstream::stdStream()
132     if (!ofPtr_)
133     {
134         FatalErrorIn("OFstream::stdStream()")
135             << "No stream allocated." << abort(FatalError);
136     }
137     return *ofPtr_;
141 const std::ostream& Foam::OFstream::stdStream() const
143     if (!ofPtr_)
144     {
145         FatalErrorIn("OFstreamAllocator::stdStream() const")
146             << "No stream allocated." << abort(FatalError);
147     }
148     return *ofPtr_;
152 void Foam::OFstream::print(Ostream& os) const
154     os  << "    OFstream: ";
155     OSstream::print(os);
159 // ************************************************************************* //