OpenFOAM logo
Open Source CFD Toolkit

OSstream.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-2005 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     OSstream
00027 
00028 Description
00029     Generic output stream.
00030 
00031 SourceFiles
00032     OSwrite.C
00033     chkStream.C
00034 
00035 \*---------------------------------------------------------------------------*/
00036 
00037 #ifndef OSstream_H
00038 #define OSstream_H
00039 
00040 #include "Ostream.H"
00041 
00042 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00043 
00044 namespace Foam
00045 {
00046 
00047 /*---------------------------------------------------------------------------*\
00048                            Class OSstream Declaration
00049 \*---------------------------------------------------------------------------*/
00050 
00051 class OSstream
00052 :
00053     public Ostream
00054 {
00055     // Private data
00056 
00057         fileName name_;
00058         ostream& os_;
00059 
00060 
00061 protected:
00062 
00063         //- Return the stream reference
00064         ostream& stream()
00065         {
00066             return os_;
00067         }
00068 
00069         //- Return the const stream reference
00070         const ostream& stream() const
00071         {
00072             return os_;
00073         }
00074 
00075 
00076 public:
00077 
00078     // Constructors
00079 
00080         //- Set stream status
00081         OSstream
00082         (
00083             ostream& os,
00084             const string& name,
00085             streamFormat format=ASCII,
00086             versionNumber version=currentVersion,
00087             compressionType compression=UNCOMPRESSED
00088         )
00089         :
00090             Ostream(format, version, compression),
00091             name_(name),
00092             os_(os)
00093         {
00094             if (os_.good())
00095             {
00096                 setOpened();
00097                 setGood();
00098                 os_.precision(precision_);
00099             }
00100             else
00101             {
00102                 setState(os_.rdstate());
00103             }
00104         }
00105 
00106 
00107     // Member functions
00108 
00109         // Enquiry
00110 
00111             //- Return the name of the stream
00112             //  Useful for Fstream to return the filename
00113             virtual const fileName& name() const
00114             {
00115                 return name_;
00116             }
00117 
00118             //- Return non-const access to the name of the stream
00119             //  Useful to alter the stream name
00120             virtual fileName& name()
00121             {
00122                 return name_;
00123             }
00124 
00125             //- Return flags of output stream
00126             virtual ios_base::fmtflags flags() const;
00127 
00128 
00129         // Write functions
00130 
00131             //- Write next token to stream
00132             virtual Ostream& write(const token&);
00133 
00134             //- Write character
00135             virtual Ostream& write(const char);
00136 
00137             //- Write character string
00138             virtual Ostream& write(const char*);
00139 
00140             //- Write word
00141             virtual Ostream& write(const word&);
00142 
00143             //- Write string
00144             virtual Ostream& write(const string&);
00145 
00146             //- Write label
00147             virtual Ostream& write(const label);
00148 
00149             //- Write floatScalar
00150             virtual Ostream& write(const floatScalar);
00151 
00152             //- Write doubleScalar
00153             virtual Ostream& write(const doubleScalar);
00154 
00155             //- Write binary block
00156             virtual Ostream& write(const char*, std::streamsize);
00157 
00158             //- Add indentation characters
00159             virtual void indent();
00160 
00161 
00162         // Stream state functions
00163 
00164             //- Set flags of output stream
00165             virtual ios_base::fmtflags flags(const ios_base::fmtflags flags);
00166 
00167             //- Flush stream
00168             virtual void flush();
00169 
00170             //- Add '\n' and flush stream
00171             virtual void endl();
00172 
00173             //- Get width of output field
00174             virtual int width() const;
00175 
00176             //- Set width of output field (and return old width)
00177             virtual int width(const int w);
00178 
00179             //- Get precision of output field
00180             virtual int precision() const;
00181 
00182             //- Set precision of output field (and return old precision)
00183             virtual int precision(const int p);
00184 
00185 
00186         // Print
00187 
00188             //- Print description of IOstream to Ostream
00189             virtual void print(Ostream&) const;
00190 };
00191 
00192 
00193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00194 
00195 } // End namespace Foam
00196 
00197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00198 
00199 #endif
00200 
00201 // ************************************************************************* //
For further information go to www.openfoam.org