OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

OFstream.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::OFstream
00027 
00028 Description
00029     Output to file stream.
00030 
00031 SourceFiles
00032     OFstream.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef OFstream_H
00037 #define OFstream_H
00038 
00039 #include "OSstream.H"
00040 #include "fileName.H"
00041 #include "className.H"
00042 
00043 #include <fstream>
00044 using std::ofstream;
00045 
00046 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00047 
00048 namespace Foam
00049 {
00050 
00051 class OFstream;
00052 
00053 /*---------------------------------------------------------------------------*\
00054                        Class OFstreamAllocator Declaration
00055 \*---------------------------------------------------------------------------*/
00056 
00057 //- A std::ostream with ability to handle compressed files
00058 class OFstreamAllocator
00059 {
00060     friend class OFstream;
00061 
00062     ostream* ofPtr_;
00063 
00064     // Constructors
00065 
00066         //- Construct from pathname
00067         OFstreamAllocator
00068         (
00069             const fileName& pathname,
00070             IOstream::compressionType compression=IOstream::UNCOMPRESSED
00071         );
00072 
00073     // Destructor
00074 
00075         ~OFstreamAllocator();
00076 
00077 
00078 public:
00079 
00080     // Member functions
00081 
00082         //- Access to underlying std::ostream
00083         ostream& stdStream();
00084 };
00085 
00086 
00087 /*---------------------------------------------------------------------------*\
00088                            Class OFstream Declaration
00089 \*---------------------------------------------------------------------------*/
00090 
00091 class OFstream
00092 :
00093     private OFstreamAllocator,
00094     public OSstream
00095 {
00096     // Private data
00097 
00098         fileName pathname_;
00099 
00100 
00101 public:
00102 
00103     // Declare name of the class and its debug switch
00104     ClassName("OFstream");
00105 
00106 
00107     // Constructors
00108 
00109         //- Construct from pathname
00110         OFstream
00111         (
00112             const fileName& pathname,
00113             streamFormat format=ASCII,
00114             versionNumber version=currentVersion,
00115             compressionType compression=UNCOMPRESSED
00116         );
00117 
00118 
00119     // Destructor
00120 
00121         ~OFstream();
00122 
00123 
00124     // Member functions
00125 
00126         // Access
00127 
00128             //- Return the name of the stream
00129             const fileName& name() const
00130             {
00131                 return pathname_;
00132             }
00133 
00134             //- Return non-const access to the name of the stream
00135             fileName& name()
00136             {
00137                 return pathname_;
00138             }
00139 
00140 
00141         // Print
00142 
00143             //- Print description of IOstream to Ostream
00144             void print(Ostream&) const;
00145 };
00146 
00147 
00148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00149 // Global predefined null output stream
00150 
00151 extern OFstream Snull;
00152 
00153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00154 
00155 } // End namespace Foam
00156 
00157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00158 
00159 #endif
00160 
00161 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd