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-2020 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& streamName,
35  IOstreamOption streamOpt
36 )
37 :
38  Istream(streamOpt),
39  name_(streamName),
40  is_(is)
41 {
42  if (is_.good())
43  {
44  setOpened();
45  setGood();
46  }
47  else
48  {
49  setState(is_.rdstate());
50  }
51 }
52 
53 
54 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
55 
57 {
58  is_.get(c);
59  setState(is_.rdstate());
60 
61  if (good() && c == '\n')
62  {
63  ++lineNumber_;
64  }
65 
66  return *this;
67 }
68 
69 
71 {
72  return is_.peek();
73 }
74 
75 
76 inline Foam::ISstream& Foam::ISstream::getLine(std::string& str, char delim)
77 {
78  std::getline(is_, str, delim);
79  setState(is_.rdstate());
80 
81  if (delim == '\n')
82  {
83  ++lineNumber_;
84  }
85 
86  return *this;
87 }
88 
89 
90 inline std::streamsize Foam::ISstream::getLine(std::nullptr_t, char delim)
91 {
92  is_.ignore(std::numeric_limits<std::streamsize>::max(), delim);
93  setState(is_.rdstate());
94 
95  std::streamsize count = is_.gcount();
96 
97  if (count && delim == '\n')
98  {
99  ++lineNumber_;
100  }
101 
102  return count;
103 }
104 
105 
107 {
108  if (c == '\n')
109  {
110  --lineNumber_;
111  }
112 
113  if (!is_.putback(c))
114  {
115  setBad();
116  }
117 
118  setState(is_.rdstate());
119 
120  return *this;
121 }
122 
123 
124 // ************************************************************************* //
Foam::ISstream::peek
int peek()
Raw, low-level peek function.
Definition: ISstreamI.H:70
Foam::ISstream::getLine
ISstream & getLine(std::string &str, char delim='\n')
Raw, low-level getline (until delimiter) into a string.
Definition: ISstreamI.H:76
Foam::ISstream
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:55
Foam::IOstream::good
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:233
Foam::ISstream::get
ISstream & get(char &c)
Raw, low-level get character function.
Definition: ISstreamI.H:56
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:121
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::ISstream::putback
ISstream & putback(const char c)
Raw, low-level putback character function.
Definition: ISstreamI.H:106
Foam::ISstream::ISstream
ISstream(std::istream &is, const string &streamName, IOstreamOption streamOpt=IOstreamOption())
Construct wrapper around std::istream, set stream status.
Definition: ISstreamI.H:32
Foam::IOstream::setState
void setState(std::ios_base::iostate state) noexcept
Set stream state.
Definition: IOstream.H:141
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.