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-2021 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 "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
68  explicit IFstream
69  (
70  const fileName& pathname,
71  IOstreamOption streamOpt = IOstreamOption()
72  );
73 
74  //- Construct from pathname, format (version)
76  (
77  const fileName& pathname,
80  )
81  :
82  IFstream(pathname, IOstreamOption(fmt, ver))
83  {}
84 
85 
86  //- Destructor
87  ~IFstream() = default;
88 
89 
90  // Member Functions
91 
92  //- Get character(s)
93  using ISstream::get;
94 
95  //- Read/write access to the name of the stream
96  using ISstream::name;
97 
98 
99  // STL stream
100 
101  //- Access to underlying std::istream
102  virtual std::istream& stdStream();
103 
104  //- Const access to underlying std::istream
105  virtual const std::istream& stdStream() const;
106 
107  //- Rewind the stream so that it may be read again.
108  // Includes special handling for compressed streams.
109  virtual void rewind();
110 
111 
112  // Print
113 
114  //- Print stream description
115  virtual void print(Ostream& os) const;
116 
117 
118  // Member Operators
119 
120  //- Return a non-const reference to const IFstream
121  // Needed for read-constructors where the stream argument is temporary:
122  // e.g. thing thisThing(IFstream("fileName")());
123  IFstream& operator()() const;
124 };
125 
126 
127 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
128 
129 } // End namespace Foam
130 
131 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
132 
133 #endif
134 
135 // ************************************************************************* //
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::IOstreamOption::IOstreamOption
constexpr IOstreamOption(streamFormat fmt=streamFormat::ASCII, compressionType comp=compressionType::UNCOMPRESSED) noexcept
Definition: IOstreamOption.H:193
Foam::IFstream
Input from file stream, using an ISstream.
Definition: IFstream.H:53
Foam::IFstream::print
virtual void print(Ostream &os) const
Print stream description.
Definition: IFstream.C:139
ISstream.H
Foam::IOstreamOption::currentVersion
static const versionNumber currentVersion
The current version number (2.0)
Definition: IOstreamOption.H:165
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:148
Foam::ISstream::get
ISstream & get(char &c)
Raw, low-level get character function.
Definition: ISstreamI.H:56
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:85
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
Foam::IFstream::~IFstream
~IFstream()=default
Destructor.
Foam::ISstream::name
virtual const fileName & name() const
Return the name of the stream.
Definition: ISstream.H:113
fstreamPointer.H
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:70
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::IFstream::IFstream
IFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption())
Construct from pathname.
Definition: IFstream.C:43
Foam::IFstream::stdStream
virtual std::istream & stdStream()
Access to underlying std::istream.
Definition: IFstream.C:94
Foam::ifstreamPointer
A wrapped std::ifstream with possible compression handling (igzstream) that behaves much like a std::...
Definition: fstreamPointer.H:71
Foam::IFstream::rewind
virtual void rewind()
Rewind the stream so that it may be read again.
Definition: IFstream.C:124
Foam::IFstream::ClassName
ClassName("IFstream")
Declare type-name (with debug switch)
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56