OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen 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-2007 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     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 class OFstreamAllocator
00058 {
00059     friend class OFstream;
00060 
00061     ostream* ofPtr_;
00062 
00063     // Constructors
00064 
00065         //- Construct from pathname
00066         OFstreamAllocator
00067         (
00068             const fileName& pathname,
00069             IOstream::compressionType compression=IOstream::UNCOMPRESSED
00070         );
00071 
00072     // Destructor
00073 
00074         ~OFstreamAllocator();
00075 
00076 
00077 public:
00078 
00079     // Member functions
00080 
00081         //- Access to underlying std::ostream
00082         ostream& stdStream();
00083 };
00084 
00085 
00086 /*---------------------------------------------------------------------------*\
00087                            Class OFstream Declaration
00088 \*---------------------------------------------------------------------------*/
00089 
00090 class OFstream
00091 :
00092     private OFstreamAllocator,
00093     public OSstream
00094 {
00095     // Private data
00096 
00097         fileName pathname_;
00098 
00099 
00100 public:
00101 
00102     // Declare name of the class and it's debug switch
00103     ClassName("OFstream");
00104 
00105 
00106     // Constructors
00107 
00108         //- Construct from pathname
00109         OFstream
00110         (
00111             const fileName& pathname,
00112             streamFormat format=ASCII,
00113             versionNumber version=currentVersion,
00114             compressionType compression=UNCOMPRESSED
00115         );
00116 
00117 
00118     // Destructor
00119 
00120         ~OFstream();
00121 
00122 
00123     // Member functions
00124 
00125         // Access
00126 
00127             //- Return the name of the stream
00128             const fileName& name() const
00129             {
00130                 return pathname_;
00131             }
00132 
00133             //- Return non-const access to the name of the stream
00134             fileName& name()
00135             {
00136                 return pathname_;
00137             }
00138 
00139 
00140         // Print
00141 
00142             //- Print description of IOstream to Ostream
00143             void print(Ostream&) const;
00144 };
00145 
00146 
00147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00148 // Global predefined null output stream
00149 
00150 extern OFstream Snull;
00151 
00152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00153 
00154 } // End namespace Foam
00155 
00156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00157 
00158 #endif
00159 
00160 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd