All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2020 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,
34  streamFormat format,
35  versionNumber version,
36  compressionType compression
37 )
38 :
39  Istream(format, version, compression),
40  name_(name),
41  is_(is)
42 {
43  if (is_.good())
44  {
45  setOpened();
46  setGood();
47  }
48  else
49  {
50  setState(is_.rdstate());
51  }
52 }
53 
54 
55 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
56 
58 {
59  is_.get(c);
60  setState(is_.rdstate());
61 
62  if (c == '\n')
63  {
64  lineNumber_++;
65  }
66 
67  return *this;
68 }
69 
70 
72 {
73  return is_.peek();
74 }
75 
76 
78 {
79  if (c == '\n')
80  {
81  lineNumber_--;
82  }
83 
84  if (!is_.putback(c))
85  {
86  setBad();
87  }
88 
89  setState(is_.rdstate());
90 
91  return *this;
92 }
93 
94 
95 // ************************************************************************* //
label lineNumber_
Definition: IOstream.H:231
ISstream(istream &is, const string &name, streamFormat format=ASCII, versionNumber version=currentVersion, compressionType compression=UNCOMPRESSED)
Construct as wrapper around istream.
Definition: ISstreamI.H:31
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
const dimensionedScalar & c
Speed of light in a vacuum.
void setBad()
Set stream to be bad.
Definition: IOstream.H:487
int peek()
Low-level peek function.
Definition: ISstreamI.H:71
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
ISstream & get(char &)
Low-level get character function.
Definition: ISstreamI.H:57
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
ISstream & putback(const char &)
Low-level putback character function.
Definition: ISstreamI.H:77
Generic input stream.
Definition: ISstream.H:51
Version number type.
Definition: IOstream.H:96
void setState(ios_base::iostate state)
Set stream state.
Definition: IOstream.H:251