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-2020 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 #include <fstream>
45 #include <memory>
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 namespace Detail
53 {
54 
55 /*---------------------------------------------------------------------------*\
56  Class Detail::IFstreamAllocator Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 //- A std::istream with the ability to handle compressed files
61 {
62 protected:
63 
64  // Member Data
65 
66  //- The allocated stream pointer (ifstream or igzstream).
67  std::unique_ptr<std::istream> allocatedPtr_;
68 
69  //- The detected compression type
71 
72 
73  // Constructors
74 
75  //- Construct from pathname
76  IFstreamAllocator(const fileName& pathname);
77 };
78 
79 } // End namespace Detail
80 
81 
82 /*---------------------------------------------------------------------------*\
83  Class IFstream Declaration
84 \*---------------------------------------------------------------------------*/
85 
86 class IFstream
87 :
89  public ISstream
90 {
91 public:
92 
93  //- Declare type-name (with debug switch)
94  ClassName("IFstream");
95 
96 
97  // Constructors
98 
99  //- Construct from pathname
100  explicit IFstream
101  (
102  const fileName& pathname,
103  IOstreamOption streamOpt = IOstreamOption()
104  );
105 
106  //- Construct from pathname, format (version)
108  (
109  const fileName& pathname,
110  streamFormat fmt,
112  )
113  :
114  IFstream(pathname, IOstreamOption(fmt, ver))
115  {}
116 
117 
118  //- Destructor
119  ~IFstream() = default;
120 
121 
122  // Member Functions
123 
124  // Access
125 
126  //- Read/write access to the name of the stream
127  using ISstream::name;
128 
129 
130  // STL stream
131 
132  //- Access to underlying std::istream
133  virtual std::istream& stdStream();
134 
135  //- Const access to underlying std::istream
136  virtual const std::istream& stdStream() const;
137 
138  //- Rewind the stream so that it may be read again
139  virtual void rewind();
140 
141 
142  // Print
143 
144  //- Print stream description to Ostream
145  virtual void print(Ostream& os) const;
146 
147 
148  // Member Operators
149 
150  //- Return a non-const reference to const IFstream
151  // Needed for read-constructors where the stream argument is temporary:
152  // e.g. thing thisThing(IFstream("fileName")());
153  IFstream& operator()() const;
154 };
155 
156 
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 
159 } // End namespace Foam
160 
161 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 
163 #endif
164 
165 // ************************************************************************* //
Foam::Detail::IFstreamAllocator::detectedCompression_
IOstream::compressionType detectedCompression_
The detected compression type.
Definition: IFstream.H:69
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::IOstreamOption::IOstreamOption
constexpr IOstreamOption(streamFormat fmt=streamFormat::ASCII, compressionType comp=compressionType::UNCOMPRESSED) noexcept
Definition: IOstreamOption.H:196
Foam::IFstream
Input from file stream, using an ISstream.
Definition: IFstream.H:85
Foam::IFstream::print
virtual void print(Ostream &os) const
Print stream description to Ostream.
Definition: IFstream.C:172
ISstream.H
Foam::IOstreamOption::currentVersion
static const versionNumber currentVersion
The current version number (2.0)
Definition: IOstreamOption.H:168
Foam::ISstream
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:55
Foam::IFstream::operator()
IFstream & operator()() const
Return a non-const reference to const IFstream.
Definition: IFstream.C:181
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:85
Foam::Detail::IFstreamAllocator
A std::istream with the ability to handle compressed files.
Definition: IFstream.H:59
className.H
Macro definitions for declaring ClassName(), NamespaceName(), etc.
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
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:124
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:70
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::IFstream
IFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption())
Construct from pathname.
Definition: IFstream.C:81
Foam::IFstream::stdStream
virtual std::istream & stdStream()
Access to underlying std::istream.
Definition: IFstream.C:117
Foam::IFstream::rewind
virtual void rewind()
Rewind the stream so that it may be read again.
Definition: IFstream.C:141
Foam::IFstream::ClassName
ClassName("IFstream")
Declare type-name (with debug switch)
Foam::IOstreamOption::compressionType
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
Definition: IOstreamOption.H:77
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::Detail::IFstreamAllocator::allocatedPtr_
std::unique_ptr< std::istream > allocatedPtr_
The allocated stream pointer (ifstream or igzstream).
Definition: IFstream.H:66