Loading...
Searching...
No Matches
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-2023 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 syncState();
50 }
51}
52
53
54// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
55
57{
58 is_.get(c);
59 syncState();
60
61 if (c == '\n' && good())
62 {
64 }
65
66 return *this;
67}
68
70inline int Foam::ISstream::peek()
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 syncState();
80
81 // Unlike with ignore(), cannot use gcount() to test success
82 if (delim == '\n')
83 {
85 }
86
87 return *this;
88}
89
90
91inline std::streamsize Foam::ISstream::getLine(std::nullptr_t, char delim)
92{
93 is_.ignore(std::numeric_limits<std::streamsize>::max(), delim);
94 std::streamsize count = is_.gcount();
95 syncState();
96
97 if (delim == '\n' && count > 0)
98 {
100 }
101
102 return count;
103}
104
105
106inline Foam::ISstream& Foam::ISstream::putback(const char c)
107{
108 if (c == '\n')
109 {
110 --lineNumber_;
111 }
112
113 if (!is_.putback(c))
114 {
115 setBad();
116 }
117
118 syncState();
119
120 return *this;
121}
122
123
124// ************************************************************************* //
A simple container for options an IOstream can normally have.
void setBad() noexcept
Set stream state to be 'bad'.
Definition IOstream.H:488
bool good() const noexcept
True if next operation might succeed.
Definition IOstream.H:281
label lineNumber_
The file line.
Definition IOstream.H:140
Generic input stream using a standard (STL) stream.
Definition ISstream.H:54
ISstream & get(char &c)
Raw, low-level get character function.
Definition ISstreamI.H:49
ISstream & putback(const char c)
Raw, low-level putback character function.
Definition ISstreamI.H:99
int peek()
Raw, low-level peek function.
Definition ISstreamI.H:63
ISstream & getLine(std::string &str, char delim='\n')
Raw, low-level getline (until delimiter) into a string.
Definition ISstreamI.H:69
void syncState()
Set stream state to match that of the std::istream.
Definition ISstream.H:195
ISstream(std::istream &is, const string &streamName, IOstreamOption streamOpt=IOstreamOption())
Construct wrapper around std::istream, set stream status.
Definition ISstreamI.H:25
Istream(const Istream &)=default
Copy construct.