Merge branch 'upstream/OpenFOAM' into master
[freefoam.git] / src / OpenFOAM / db / IOstreams / Fstreams / IFstream.H
blob9b29d483f0dc7aa2657d2bc07bf324304fa2ac42
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::IFstream
28 Description
29     Input from file stream.
31 SourceFiles
32     IFstream.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef IFstream_H
37 #define IFstream_H
39 #include <OpenFOAM/ISstream.H>
40 #include <OpenFOAM/fileName.H>
41 #include <OpenFOAM/className.H>
43 #include <fstream>
44 using std::ifstream;
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 namespace Foam
51 class IFstream;
53 /*---------------------------------------------------------------------------*\
54                        Class IFstreamAllocator Declaration
55 \*---------------------------------------------------------------------------*/
57 //- A std::istream with ability to handle compressed files
58 class IFstreamAllocator
60     friend class IFstream;
62     // Private data
64         istream* ifPtr_;
65         IOstream::compressionType compression_;
68     // Constructors
70         //- Construct from pathname
71         IFstreamAllocator(const fileName& pathname);
74     // Destructor
76         ~IFstreamAllocator();
79 public:
81     // Member functions
83         //- Access to underlying std::istream (for e.g. lexer)
84         istream& stdStream();
88 /*---------------------------------------------------------------------------*\
89                            Class IFstream Declaration
90 \*---------------------------------------------------------------------------*/
92 class IFstream
94     public IFstreamAllocator,
95     public ISstream
97     // Private data
99         fileName pathname_;
101 public:
103     // Declare name of the class and its debug switch
104     ClassName("IFstream");
107     // Constructors
109         //- Construct from pathname
110         IFstream
111         (
112             const fileName& pathname,
113             streamFormat format=ASCII,
114             versionNumber version=currentVersion
115         );
118     // Destructor
120         ~IFstream();
123     // Member functions
125         // Access
127             //- Return the name of the stream
128             const fileName& name() const
129             {
130                 return pathname_;
131             }
133             //- Return non-const access to the name of the stream
134             fileName& name()
135             {
136                 return pathname_;
137             }
139         // Print
141             //- Print description of IOstream to Ostream
142             virtual void print(Ostream&) const;
145     // Member operators
147         //- Return a non-const reference to const IFstream
148         //  Needed for read-constructors where the stream argument is temporary:
149         //  e.g. thing thisThing(IFstream("thingFileName")());
150         IFstream& operator()() const;
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 } // End namespace Foam
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 #endif
162 // ************************ vim: set sw=4 sts=4 et: ************************ //