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 -------------------------------------------------------------------------------
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  {
50  }
51 }
52 
53 
54 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
55 
57 {
58  is_.get(c);
59  syncState();
60 
61  if (c == '\n' && good())
62  {
63  ++lineNumber_;
64  }
65 
66  return *this;
67 }
68 
69 
70 inline int Foam::ISstream::peek()
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  syncState();
80 
81  // Unlike with ignore(), cannot use gcount() to test success
82  if (delim == '\n')
83  {
84  ++lineNumber_;
85  }
86 
87  return *this;
88 }
89 
90 
91 inline 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  {
99  ++lineNumber_;
100  }
101 
102  return count;
103 }
104 
105 
106 inline 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 // ************************************************************************* //
ISstream & putback(const char c)
Raw, low-level putback character function.
Definition: ISstreamI.H:99
ISstream(std::istream &is, const string &streamName, IOstreamOption streamOpt=IOstreamOption())
Construct wrapper around std::istream, set stream status.
Definition: ISstreamI.H:25
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void syncState()
Set stream state to match that of the std::istream.
Definition: ISstream.H:183
A simple container for options an IOstream can normally have.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of &#39;true&#39; entries.
Definition: BitOps.H:73
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
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:51
const dimensionedScalar c
Speed of light in a vacuum.
void setOpened() noexcept
Set stream opened.
Definition: IOstream.H:150
void setGood() noexcept
Set stream state to be good.
Definition: IOstream.H:174
ISstream & get(char &c)
Raw, low-level get character function.
Definition: ISstreamI.H:49