ISstreamI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "ISstream.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
31 (
32  istream& is,
33  const string& name,
35  versionNumber version,
36  compressionType compression
37 )
38 :
39  Istream(format, version, compression),
40  name_(name),
41  is_(is),
42  buf_(bufInitialCapacity)
43 {
44  if (is_.good())
45  {
46  setOpened();
47  setGood();
48  }
49  else
50  {
51  setState(is_.rdstate());
52  }
53 }
54 
55 
56 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
57 
59 {
60  is_.get(c);
61  setState(is_.rdstate());
62 
63  if (c == '\n')
64  {
65  lineNumber_++;
66  }
67 
68  return *this;
69 }
70 
71 
73 {
74  return is_.peek();
75 }
76 
77 
79 {
80  if (c == '\n')
81  {
82  lineNumber_--;
83  }
84 
85  if (!is_.putback(c))
86  {
87  setBad();
88  }
89 
90  setState(is_.rdstate());
91 
92  return *this;
93 }
94 
95 
96 // ************************************************************************* //
Version number type.
Definition: IOstream.H:97
void setGood()
Set stream to be good.
Definition: IOstream.H:254
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
void setState(ios_base::iostate state)
Set stream state.
Definition: IOstream.H:248
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
void setOpened()
Set stream opened.
Definition: IOstream.H:236
Generic input stream.
Definition: ISstream.H:55
ISstream & get(char &)
Low-level get character function.
Definition: ISstreamI.H:58
int peek()
Low-level peek function.
Definition: ISstreamI.H:72
ISstream(istream &is, const string &name, streamFormat format=ASCII, versionNumber version=currentVersion, compressionType compression=UNCOMPRESSED)
Construct as wrapper around istream.
Definition: ISstreamI.H:31
ISstream & putback(const char &)
Low-level putback character function.
Definition: ISstreamI.H:78
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
const dimensionedScalar c
Speed of light in a vacuum.
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
word format(conversionProperties.lookup("format"))