www.cemf.ir
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, writeFormat wf = ASCII);
69 
70  //- Destructor
71  virtual ~Istream() = default;
72 
73 
75 
76  //- Return the name of the stream
77  virtual const word& name() const
78  {
79  return name_;
80  }
81 
82  //- Return non-const access to the name of the stream
83  virtual word& name()
84  {
85  return name_;
86  }
87 
88  //- Return flags of output stream
89  virtual ios_base::fmtflags flags() const;
90 
91 
93 
94  //- Raw, low-level get character function.
95  Istream& get(char& c);
96 
97  //- Raw, low-level peek function.
98  // Does not remove the character from the stream.
99  // Returns the next character in the stream or EOF if the
100  // end of file is read.
101  int peek();
102 
103  //- Raw, low-level getline (until delimiter) into a string.
104  Istream& getLine(word& str, char delim = '\n');
105 
106  //- Low-level discard until delimiter
107  // return the number of characters extracted
108  std::streamsize getLine(std::nullptr_t, char delim = '\n');
109 
110  //- Raw, low-level putback character function.
111  Istream& putback(const char c);
112 
113  //- Return next token from stream
114  virtual iIstream& read(token& t) override;
115 
116  //- Read a character
117  virtual iIstream& read(char& c) override;
118 
119  //- Read a word
120  virtual iIstream& read(word& str) override;
121 
122  //- Read a string
123  virtual iIstream& readString(word& str) override;
124 
125  //- Read a int64
126  virtual iIstream& read(int64&) override;
127 
128  //- Read a int32
129  virtual iIstream& read(int32&) override;
130 
131  //- Read a int16
132  virtual iIstream& read(int16&) override;
133 
134  //- Read a int8
135  virtual iIstream& read(int8&) override;
136 
137  //- Read a label
138  virtual iIstream& read(label&) override;
139 
140  //- Read a uint32
141  virtual iIstream& read(uint32&) override;
142 
143  //- Read a uint16
144  virtual iIstream& read(uint16&) override;
145 
146  //- Read a float
147  virtual iIstream& read(float& val) override;
148 
149  //- Read a double
150  virtual iIstream& read(double& val) override;
151 
152  iIstream& read(char* buffer, std::streamsize count) override;
153 
154 
155  //- Rewind the stream so that it may be read again
156  virtual void rewind();
157 
158 
159  //- Set stream flags
160  virtual ios_base::fmtflags flags(const ios_base::fmtflags flags);
161 
162 
163 
164  //- Access to underlying std::istream
165  virtual std::istream& stdStream()
166  {
167  return is_;
168  }
169 
170  //- Const access to underlying std::istream
171  virtual const std::istream& stdStream() const
172  {
173  return is_;
174  }
175 
176 
177 };
178 
179 
180 }
181 
182 
183 #endif
184 
pFlow::Istream::operator=
void operator=(const Istream &)=delete
pFlow::Istream::stdStream
virtual std::istream & stdStream()
Definition: Istream.hpp:165
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::Istream::Istream
Istream(std::istream &is, const word &streamName, writeFormat wf=ASCII)
Definition: Istream.cpp:308
pFlow::IOstream::ASCII
@ ASCII
Definition: IOstream.hpp:59
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::Istream::name
virtual word & name()
Return non-const access to the name of the stream.
Definition: Istream.hpp:83
pFlow::int64
long long int int64
Definition: builtinTypes.hpp:55
pFlow::Istream::name
virtual const word & name() const
Return the name of the stream.
Definition: Istream.hpp:77
pFlow
Definition: demComponent.hpp:28
pFlow::Istream::rewind
virtual void rewind()
Definition: Istream.cpp:871
pFlow::Istream::readString
virtual iIstream & readString(word &str) override
Definition: Istream.cpp:684
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:396
pFlow::Istream::~Istream
virtual ~Istream()=default
pFlow::count
auto count(const Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:26
pFlow::Istream::get
Istream & get(char &c)
Definition: Istream.cpp:329
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:343
pFlow::IOstream::writeFormat
writeFormat
Definition: IOstream.hpp:57
pFlow::Istream::flags
virtual ios_base::fmtflags flags() const
Return flags of stream.
Definition: Istream.cpp:885
pFlow::Istream::stdStream
virtual const std::istream & stdStream() const
Definition: Istream.hpp:171
pFlow::Istream::putback
Istream & putback(const char c)
Definition: Istream.cpp:379
pFlow::Istream::getLine
Istream & getLine(word &str, char delim='\n')
Definition: Istream.cpp:349
pFlow::Istream::is_
std::istream & is_
Definition: Istream.hpp:46