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-------------------------------------------------------------------------------
11License
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
76inline 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
90inline 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// ************************************************************************* //
The IOstreamOption is a simple container for options an IOstream can normally have.
void setState(std::ios_base::iostate state) noexcept
Set stream state.
Definition: IOstream.H:141
void setGood() noexcept
Set stream state to be good.
Definition: IOstream.H:147
void setOpened() noexcept
Set stream opened.
Definition: IOstream.H:129
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:58
ISstream & putback(const char c)
Raw, low-level putback character function.
Definition: ISstreamI.H:106
int peek()
Raw, low-level peek function.
Definition: ISstreamI.H:70
ISstream & getLine(std::string &str, char delim='\n')
Raw, low-level getline (until delimiter) into a string.
Definition: ISstreamI.H:76
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
unsigned int get() const
Get value as unsigned, no range-checking.
Definition: PackedListI.H:302