ISstreamI.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-2014 OpenFOAM Foundation
9  Copyright (C) 2017-2019 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 \*---------------------------------------------------------------------------*/
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
32 (
33  std::istream& is,
34  const string& name,
37  compressionType compression
38 )
39 :
40  Istream(format, version, compression),
41  name_(name),
42  is_(is)
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 (good() && c == '\n')
64  {
65  ++lineNumber_;
66  }
67 
68  return *this;
69 }
70 
71 
73 {
74  return is_.peek();
75 }
76 
77 
78 inline Foam::ISstream& Foam::ISstream::getLine(std::string& str, char delim)
79 {
80  std::getline(is_, str, delim);
81  setState(is_.rdstate());
82 
83  if (delim == '\n')
84  {
85  ++lineNumber_;
86  }
87 
88  return *this;
89 }
90 
91 
93 {
94  if (c == '\n')
95  {
96  --lineNumber_;
97  }
98 
99  if (!is_.putback(c))
100  {
101  setBad();
102  }
103 
104  setState(is_.rdstate());
105 
106  return *this;
107 }
108 
109 
110 // ************************************************************************* //
Foam::ISstream::peek
int peek()
Raw, low-level peek function.
Definition: ISstreamI.H:72
Foam::ISstream::ISstream
ISstream(std::istream &is, const string &name, streamFormat format=ASCII, versionNumber version=currentVersion, compressionType compression=UNCOMPRESSED)
Construct as wrapper around std::istream.
Definition: ISstreamI.H:32
Foam::ISstream::getLine
ISstream & getLine(std::string &str, char delim='\n')
Raw, low-level getline into a string function.
Definition: ISstreamI.H:78
Foam::ISstream
Generic input stream using standard (STL) streams.
Definition: ISstream.H:54
Foam::ISstream::get
ISstream & get(char &c)
Raw, low-level get character function.
Definition: ISstreamI.H:58
format
word format(conversionProperties.get< word >("format"))
Foam::IOstream::setState
void setState(ios_base::iostate state)
Set stream state.
Definition: IOstream.H:135
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:79
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::IOstream::lineNumber_
label lineNumber_
The file line.
Definition: IOstream.H:115
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::ISstream::putback
ISstream & putback(const char c)
Raw, low-level putback character function.
Definition: ISstreamI.H:92
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:64
Foam::foamVersion::version
const std::string version
OpenFOAM version (name or stringified number) as a std::string.
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::IOstreamOption::compressionType
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
Definition: IOstreamOption.H:71
Foam::IOstream::good
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:216