Istream.hpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 // based on OpenFOAM stream, with some modifications/simplifications
21 // to be tailored to our needs
22 
23 
24 #ifndef __Istream_hpp__
25 #define __Istream_hpp__
26 
27 #include <limits>
28 #include <iostream>
29 
30 #include "iIstream.hpp"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace pFlow
35 {
36 
37 
38 class Istream
39 :
40  public iIstream
41 {
42  // Private Data
43 
45 
46  std::istream& is_;
47 
48 
49  //- Get the next valid character
50  char nextValid();
51 
52  //- Read a word token
53  void readWordToken(token& t);
54 
55 
56  //- Read a variable name starting with '$'.
57  // Handles "$var" and "${var}" forms, permits '/' scoping character.
58  Istream& readVariable(word& str);
59 
60  //- No copy assignment
61  void operator=(const Istream&) = delete;
62 
63 
64 public:
65 
66 
67  //- Construct wrapper around std::istream, set stream status
68  Istream( std::istream& is, const word& streamName);
69 
70 
71  //- Destructor
72  virtual ~Istream() = default;
73 
74 
76 
77  //- Return the name of the stream
78  virtual const word& name() const
79  {
80  return name_;
81  }
82 
83  //- Return non-const access to the name of the stream
84  virtual word& name()
85  {
86  return name_;
87  }
88 
89  //- Return flags of output stream
90  virtual ios_base::fmtflags flags() const;
91 
92 
94 
95  //- Raw, low-level get character function.
96  Istream& get(char& c);
97 
98  //- Raw, low-level peek function.
99  // Does not remove the character from the stream.
100  // Returns the next character in the stream or EOF if the
101  // end of file is read.
102  int peek();
103 
104  //- Raw, low-level getline (until delimiter) into a string.
105  Istream& getLine(word& str, char delim = '\n');
106 
107  //- Low-level discard until delimiter
108  // return the number of characters extracted
109  std::streamsize getLine(std::nullptr_t, char delim = '\n');
110 
111  //- Raw, low-level putback character function.
112  Istream& putback(const char c);
113 
114  //- Return next token from stream
115  virtual iIstream& read(token& t) override;
116 
117  //- Read a character
118  virtual iIstream& read(char& c) override;
119 
120  //- Read a word
121  virtual iIstream& read(word& str) override;
122 
123  //- Read a string
124  virtual iIstream& readString(word& str) override;
125 
126  //- Read a int64
127  virtual iIstream& read(int64&) override;
128 
129  //- Read a int32
130  virtual iIstream& read(int32&) override;
131 
132  //- Read a int16
133  virtual iIstream& read(int16&) override;
134 
135  //- Read a int8
136  virtual iIstream& read(int8&) override;
137 
138  //- Read a label
139  virtual iIstream& read(label&) override;
140 
141  //- Read a uint32
142  virtual iIstream& read(uint32&) override;
143 
144  //- Read a uint16
145  virtual iIstream& read(uint16&) override;
146 
147  //- Read a float
148  virtual iIstream& read(float& val) override;
149 
150  //- Read a double
151  virtual iIstream& read(double& val) override;
152 
153 
154  //- Rewind the stream so that it may be read again
155  virtual void rewind();
156 
157 
158  //- Set stream flags
159  virtual ios_base::fmtflags flags(const ios_base::fmtflags flags);
160 
161 
162 
163  //- Access to underlying std::istream
164  virtual std::istream& stdStream()
165  {
166  return is_;
167  }
168 
169  //- Const access to underlying std::istream
170  virtual const std::istream& stdStream() const
171  {
172  return is_;
173  }
174 
175 
176 };
177 
178 
179 }
180 
181 
182 #endif
183 
pFlow::Istream::operator=
void operator=(const Istream &)=delete
pFlow::Istream::stdStream
virtual std::istream & stdStream()
Definition: Istream.hpp:164
pFlow::token
Definition: token.hpp:42
pFlow::Istream::nextValid
char nextValid()
Definition: Istream.cpp:53
iIstream.hpp
pFlow::Istream::readWordToken
void readWordToken(token &t)
Definition: Istream.cpp:131
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::Istream::name
virtual word & name()
Definition: Istream.hpp:84
pFlow::int64
long long int int64
Definition: builtinTypes.hpp:55
pFlow::Istream::name
virtual const word & name() const
Definition: Istream.hpp:78
pFlow
Definition: demComponent.hpp:28
pFlow::Istream::rewind
virtual void rewind()
Definition: Istream.cpp:850
pFlow::Istream::readString
virtual iIstream & readString(word &str) override
Definition: Istream.cpp:683
pFlow::Istream
Definition: Istream.hpp:38
pFlow::int16
short int int16
Definition: builtinTypes.hpp:51
pFlow::uint16
unsigned short int uint16
Definition: builtinTypes.hpp:57
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::Istream::readVariable
Istream & readVariable(word &str)
Definition: Istream.cpp:145
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::Istream::read
virtual iIstream & read(token &t) override
Definition: Istream.cpp:395
pFlow::Istream::~Istream
virtual ~Istream()=default
pFlow::Istream::get
Istream & get(char &c)
Definition: Istream.cpp:328
pFlow::Istream::Istream
Istream(std::istream &is, const word &streamName)
Definition: Istream.cpp:308
pFlow::Istream::name_
word name_
Definition: Istream.hpp:44
pFlow::label
std::size_t label
Definition: builtinTypes.hpp:61
pFlow::int8
signed char int8
Definition: builtinTypes.hpp:49
pFlow::Istream::peek
int peek()
Definition: Istream.cpp:342
pFlow::Istream::flags
virtual ios_base::fmtflags flags() const
Definition: Istream.cpp:864
pFlow::Istream::stdStream
virtual const std::istream & stdStream() const
Definition: Istream.hpp:170
pFlow::Istream::putback
Istream & putback(const char c)
Definition: Istream.cpp:378
pFlow::Istream::getLine
Istream & getLine(word &str, char delim='\n')
Definition: Istream.cpp:348
pFlow::Istream::is_
std::istream & is_
Definition: Istream.hpp:46