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-2023 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 Foam_IFstream_H
39 #define Foam_IFstream_H
40 
41 #include "ISstream.H"
42 #include "className.H"
43 #include "fstreamPointer.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class IFstream Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 class IFstream
55 :
56  private Foam::ifstreamPointer,
57  public ISstream
58 {
59 public:
60 
61  //- Declare type-name (with debug switch)
62  ClassName("IFstream");
63 
64 
65  // Constructors
66 
67  //- Construct from pathname, default or specified stream options
68  explicit IFstream
69  (
70  const fileName& pathname,
71  IOstreamOption streamOpt = IOstreamOption()
72  );
73 
74  //- Construct from pathname and format
75  IFstream
76  (
77  const fileName& pathname,
79  )
80  :
81  IFstream(pathname, IOstreamOption(fmt))
82  {}
83 
84 
85  //- Destructor
86  ~IFstream() = default;
87 
88 
89  // Member Functions
90 
91  //- Get character(s)
92  using ISstream::get;
93 
94  //- Read/write access to the name of the stream
95  using ISstream::name;
96 
97  //- Return the size of the underlying file (-1 on error).
98  //- This corresponds to Foam::fileSize() but with extra handling of
99  //- compressed files.
100  // The return type is \c std::streamsize instead of \c off_t.
101  // \note Use sparingly since it involves a file stat()!
102  std::streamsize fileSize() const;
103 
104 
105  // STL stream
106 
107  //- Access to underlying std::istream
108  virtual std::istream& stdStream() override;
109 
110  //- Const access to underlying std::istream
111  virtual const std::istream& stdStream() const override;
112 
113  //- Rewind the stream so that it may be read again.
114  // Includes special handling for compressed streams.
115  virtual void rewind() override;
116 
117 
118  // Print
119 
120  //- Print stream description
121  virtual void print(Ostream& os) const override;
122 
123 
124  // Member Operators
125 
126  //- Return a non-const reference to const IFstream
127  // Needed for read-constructors where the stream argument is temporary:
128  // e.g. thing thisThing(IFstream("fileName")());
129  IFstream& operator()() const;
130 };
131 
132 
133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
134 
135 } // End namespace Foam
136 
137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
138 
139 #endif
140 
141 // ************************************************************************* //
A wrapped std::ifstream with possible compression handling (igzstream) that behaves much like a std::...
IFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption())
Construct from pathname, default or specified stream options.
Definition: IFstream.C:36
~IFstream()=default
Destructor.
A class for handling file names.
Definition: fileName.H:72
A simple container for options an IOstream can normally have.
ClassName("IFstream")
Declare type-name (with debug switch)
constexpr IOstreamOption(streamFormat fmt=streamFormat::ASCII, compressionType comp=compressionType::UNCOMPRESSED) noexcept
Default construct (ASCII, UNCOMPRESSED, currentVersion) or construct with format, compression...
virtual void rewind() override
Rewind the stream so that it may be read again.
Definition: IFstream.C:156
virtual const fileName & name() const override
The name of the input serial stream. (eg, the name of the Fstream file name)
Definition: ISstream.H:141
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
virtual std::istream & stdStream() override
Access to underlying std::istream.
Definition: IFstream.C:126
OBJstream os(runTime.globalPath()/outputName)
Input from file stream, using an ISstream.
Definition: IFstream.H:49
std::streamsize fileSize() const
Return the size of the underlying file (-1 on error). This corresponds to Foam::fileSize() but with e...
Definition: IFstream.C:87
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:51
Macro definitions for declaring ClassName(), NamespaceName(), etc.
IFstream & operator()() const
Return a non-const reference to const IFstream.
Definition: IFstream.C:180
streamFormat
Data format (ascii | binary)
virtual void print(Ostream &os) const override
Print stream description.
Definition: IFstream.C:171
ISstream & get(char &c)
Raw, low-level get character function.
Definition: ISstreamI.H:49
Namespace for OpenFOAM.