ISstreamI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "ISstream.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
31 (
32  istream& is,
33  const string& name,
34  streamFormat format,
35  versionNumber version,
36  compressionType compression
37 )
38 :
39  Istream(format, version, compression),
40  name_(name),
41  is_(is)
42 {
43  if (is_.good())
44  {
45  setOpened();
46  setGood();
47  }
48  else
49  {
50  setState(is_.rdstate());
51  }
52 }
53 
54 
55 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
56 
58 {
59  is_.get(c);
60  setState(is_.rdstate());
61 
62  if (c == '\n')
63  {
64  lineNumber_++;
65  }
66 
67  return *this;
68 }
69 
70 
72 {
73  return is_.peek();
74 }
75 
76 
78 {
79  getline(is_, s);
80  setState(is_.rdstate());
81  lineNumber_++;
82 
83  return *this;
84 }
85 
86 
88 {
89  if (c == '\n')
90  {
91  lineNumber_--;
92  }
93 
94  if (!is_.putback(c))
95  {
96  setBad();
97  }
98 
99  setState(is_.rdstate());
100 
101  return *this;
102 }
103 
104 
105 // ************************************************************************* //
label lineNumber_
Definition: IOstream.H:231
ISstream(istream &is, const string &name, streamFormat format=ASCII, versionNumber version=currentVersion, compressionType compression=UNCOMPRESSED)
Construct as wrapper around istream.
Definition: ISstreamI.H:31
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void setBad()
Set stream to be bad.
Definition: IOstream.H:487
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
int peek()
Raw, low-level peek function.
Definition: ISstreamI.H:71
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
ISstream & get(char &)
Raw, low-level get character function.
Definition: ISstreamI.H:57
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
ISstream & putback(const char &)
Raw, low-level putback character function.
Definition: ISstreamI.H:87
Generic input stream.
Definition: ISstream.H:51
const dimensionedScalar c
Speed of light in a vacuum.
Version number type.
Definition: IOstream.H:96
void setState(ios_base::iostate state)
Set stream state.
Definition: IOstream.H:251
ISstream & getLine(string &)
Raw, low-level getline into a string function.
Definition: ISstreamI.H:77