IFstream.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011 OpenFOAM Foundation
9  Copyright (C) 2017-2018 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::IFstream
29 
30 Description
31  Input from file stream, using an ISstream
32 
33 SourceFiles
34  IFstream.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef IFstream_H
39 #define IFstream_H
40 
41 #include "ISstream.H"
42 #include "fileName.H"
43 #include "className.H"
44 
45 #include <fstream>
46 using std::ifstream;
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 namespace Detail
54 {
55 
56 /*---------------------------------------------------------------------------*\
57  Class Detail::IFstreamAllocator Declaration
58 \*---------------------------------------------------------------------------*/
59 
60 //- A std::istream with the ability to handle compressed files
62 {
63 protected:
64 
65  // Member Data
66 
67  //- The allocated stream pointer (ifstream or igzstream).
68  std::istream* allocatedPtr_;
69 
70  //- The requested compression type
72 
73 
74  // Constructors
75 
76  //- Construct from pathname
77  IFstreamAllocator(const fileName& pathname);
78 
79 
80  //- Destructor
82 
83 
84  // Protected Member Functions
85 
86  //- Delete the stream pointer
87  void deallocate();
88 
89 };
90 
91 } // End namespace Detail
92 
93 
94 /*---------------------------------------------------------------------------*\
95  Class IFstream Declaration
96 \*---------------------------------------------------------------------------*/
97 
98 class IFstream
99 :
101  public ISstream
102 {
103 public:
104 
105  // Declare name of the class and its debug switch
106  ClassName("IFstream");
107 
108 
109  // Constructors
110 
111  //- Construct from pathname
112  IFstream
113  (
114  const fileName& pathname,
117  );
118 
119 
120  //- Destructor
121  ~IFstream() = default;
122 
123 
124  // Member Functions
125 
126  // Access
127 
128  //- Read/write access to the name of the stream
129  using ISstream::name;
130 
131 
132  // STL stream
133 
134  //- Access to underlying std::istream
135  virtual std::istream& stdStream();
136 
137  //- Const access to underlying std::istream
138  virtual const std::istream& stdStream() const;
139 
140  //- Rewind the stream so that it may be read again
141  virtual void rewind();
142 
143 
144  // Print
145 
146  //- Print description of IOstream to Ostream
147  virtual void print(Ostream& os) const;
148 
149 
150  // Member Operators
151 
152  //- Return a non-const reference to const IFstream
153  // Needed for read-constructors where the stream argument is temporary:
154  // e.g. thing thisThing(IFstream("fileName")());
155  IFstream& operator()() const;
156 };
157 
158 
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 
161 } // End namespace Foam
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 #endif
166 
167 // ************************************************************************* //
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::IFstream
Input from file stream, using an ISstream.
Definition: IFstream.H:97
Foam::Detail::IFstreamAllocator::~IFstreamAllocator
~IFstreamAllocator()
Destructor.
Definition: IFstream.C:81
Foam::IFstream::print
virtual void print(Ostream &os) const
Print description of IOstream to Ostream.
Definition: IFstream.C:199
ISstream.H
Foam::IOstreamOption::format
streamFormat format() const noexcept
Get the current stream format.
Definition: IOstreamOption.H:273
Foam::IOstreamOption::currentVersion
static const versionNumber currentVersion
The current version number.
Definition: IOstreamOption.H:193
Foam::ISstream
Generic input stream using standard (STL) streams.
Definition: ISstream.H:54
Foam::IFstream::operator()
IFstream & operator()() const
Return a non-const reference to const IFstream.
Definition: IFstream.C:208
Foam::Detail::IFstreamAllocator::allocatedPtr_
std::istream * allocatedPtr_
The allocated stream pointer (ifstream or igzstream).
Definition: IFstream.H:67
Foam::IFstream::IFstream
IFstream(const fileName &pathname, streamFormat format=ASCII, versionNumber version=currentVersion)
Construct from pathname.
Definition: IFstream.C:102
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:79
Foam::Detail::IFstreamAllocator
A std::istream with the ability to handle compressed files.
Definition: IFstream.H:60
className.H
Macro definitions for declaring ClassName(), NamespaceName(), etc.
fileName.H
Foam::IFstream::~IFstream
~IFstream()=default
Destructor.
Foam::ISstream::name
virtual const fileName & name() const
Return the name of the stream.
Definition: ISstream.H:111
Foam::IOstreamOption::version
versionNumber version() const noexcept
Get the stream version.
Definition: IOstreamOption.H:321
Foam::Detail::IFstreamAllocator::deallocate
void deallocate()
Delete the stream pointer.
Definition: IFstream.C:89
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:64
Foam::Detail::IFstreamAllocator::IFstreamAllocator
IFstreamAllocator(const fileName &pathname)
Construct from pathname.
Definition: IFstream.C:43
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::IFstream::stdStream
virtual std::istream & stdStream()
Access to underlying std::istream.
Definition: IFstream.C:144
Foam::IOstreamOption::ASCII
"ascii"
Definition: IOstreamOption.H:66
Foam::Detail::IFstreamAllocator::compression_
IOstream::compressionType compression_
The requested compression type.
Definition: IFstream.H:70
Foam::IFstream::rewind
virtual void rewind()
Rewind the stream so that it may be read again.
Definition: IFstream.C:168
Foam::IFstream::ClassName
ClassName("IFstream")
Foam::IOstreamOption::compressionType
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
Definition: IOstreamOption.H:71
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56