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

IFstream.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::IFstream
00027 
00028 Description
00029     Input from file stream.
00030 
00031 SourceFiles
00032     IFstream.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef IFstream_H
00037 #define IFstream_H
00038 
00039 #include "ISstream.H"
00040 #include "fileName.H"
00041 #include "className.H"
00042 
00043 #include <fstream>
00044 using std::ifstream;
00045 
00046 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00047 
00048 namespace Foam
00049 {
00050 
00051 class IFstream;
00052 
00053 /*---------------------------------------------------------------------------*\
00054                        Class IFstreamAllocator Declaration
00055 \*---------------------------------------------------------------------------*/
00056 
00057 //- A std::istream with ability to handle compressed files
00058 class IFstreamAllocator
00059 {
00060     friend class IFstream;
00061 
00062     // Private data
00063 
00064         istream* ifPtr_;
00065         IOstream::compressionType compression_;
00066 
00067 
00068     // Constructors
00069 
00070         //- Construct from pathname
00071         IFstreamAllocator(const fileName& pathname);
00072 
00073 
00074     // Destructor
00075 
00076         ~IFstreamAllocator();
00077 
00078 
00079 public:
00080 
00081     // Member functions
00082 
00083         //- Access to underlying std::istream (for e.g. lexer)
00084         istream& stdStream();
00085 };
00086 
00087 
00088 /*---------------------------------------------------------------------------*\
00089                            Class IFstream Declaration
00090 \*---------------------------------------------------------------------------*/
00091 
00092 class IFstream
00093 :
00094     public IFstreamAllocator,
00095     public ISstream
00096 {
00097     // Private data
00098 
00099         fileName pathname_;
00100 
00101 public:
00102 
00103     // Declare name of the class and its debug switch
00104     ClassName("IFstream");
00105 
00106 
00107     // Constructors
00108 
00109         //- Construct from pathname
00110         IFstream
00111         (
00112             const fileName& pathname,
00113             streamFormat format=ASCII,
00114             versionNumber version=currentVersion
00115         );
00116 
00117 
00118     // Destructor
00119 
00120         ~IFstream();
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         // Print
00140 
00141             //- Print description of IOstream to Ostream
00142             virtual void print(Ostream&) const;
00143 
00144 
00145     // Member operators
00146 
00147         //- Return a non-const reference to const IFstream
00148         //  Needed for read-constructors where the stream argument is temporary:
00149         //  e.g. thing thisThing(IFstream("thingFileName")());
00150         IFstream& operator()() const;
00151 };
00152 
00153 
00154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00155 
00156 } // End namespace Foam
00157 
00158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00159 
00160 #endif
00161 
00162 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd