DUNE-FEM (unstable)

streams.hh
1#ifndef DUNE_FEM_STREAMS_HH
2#define DUNE_FEM_STREAMS_HH
3
4#include <string>
5#include <fstream>
6
7// we would use cstdint,
8// if it would be available for all compilers, e.g. clang
9//#include <stdint.h>
10#include <cstdint>
11
13
14#include <dune/fem/misc/bartonnackmaninterface.hh>
15#include <dune/fem/misc/mpimanager.hh>
16
17namespace Dune
18{
19
20 namespace Fem
21 {
22
23 class StreamError : public Exception {};
24
25
45 template< class TraitsImp >
47 : public BartonNackmanInterface< OutStreamInterface< TraitsImp >, typename TraitsImp::OutStreamType >
48 {
50 typedef BartonNackmanInterface< ThisType, typename TraitsImp::OutStreamType > BaseType;
51
52 public:
54 typedef TraitsImp Traits;
55
57 typedef typename Traits::OutStreamType OutStreamType;
58
61
62 protected:
63 using BaseType::asImp;
64
65 public:
71 void flush ()
72 {
74 }
75
80 void writeDouble ( const double value )
81 {
83 }
84
89 void writeFloat ( const float value )
90 {
92 }
93
98 void writeInt ( const int value )
99 {
101 }
102
107 void writeSignedInt64 ( int64_t value )
108 {
110 }
111
116 void writeChar ( const char value )
117 {
119 }
120
125 void writeBool ( const bool value )
126 {
128 }
129
134 void writeString ( const std::string &s )
135 {
137 }
138
143 void writeUnsignedInt ( unsigned int value )
144 {
146 }
147
152 void writeUnsignedInt64 ( uint64_t value )
153 {
155 }
156
157 protected:
158 void writeError () const
159 {
160 DUNE_THROW( StreamError, "Unable to write to stream." );
161 }
162 };
163
164
165
187 template< class TraitsImp >
189 : public BartonNackmanInterface< InStreamInterface< TraitsImp >, typename TraitsImp::InStreamType >
190 {
192 typedef BartonNackmanInterface< ThisType, typename TraitsImp::InStreamType > BaseType;
193
194 public:
196 typedef TraitsImp Traits;
197
199 typedef typename Traits::InStreamType InStreamType;
200
203
204 protected:
205 using BaseType::asImp;
206
207 public:
212 void readDouble ( double &value )
213 {
215 }
216
221 double readDouble ()
222 {
223 double value;
224 readDouble( value );
225 return value;
226 }
227
232 void readFloat ( float &value )
233 {
235 }
236
241 float readFloat ()
242 {
243 float value;
244 readFloat( value );
245 return value;
246 }
247
252 void readInt ( int &value )
253 {
255 }
256
261 int readInt ()
262 {
263 int value;
264 readInt( value );
265 return value;
266 }
267
272 void readSignedInt64 ( int64_t &value )
273 {
275 }
276
282 {
283 int64_t value;
284 readSignedInt64( value );
285 return value;
286 }
287
292 void readChar ( char &value )
293 {
295 }
296
301 int readChar ()
302 {
303 char value;
304 readChar( value );
305 return value;
306 }
307
313 void readBool ( bool &value )
314 {
316 }
317
322 bool readBool ()
323 {
324 bool value;
325 readBool( value );
326 return value;
327 }
328
333 void readString ( std::string &s )
334 {
336 }
337
342 void readUnsignedInt ( unsigned int &value )
343 {
345 }
346
351 unsigned int readUnsignedInt ()
352 {
353 unsigned int value;
354 readUnsignedInt( value );
355 return value;
356 }
357
362 void readUnsignedInt64 ( uint64_t &value )
363 {
365 }
366
372 {
373 uint64_t value;
374 readUnsignedInt64( value );
375 return value;
376 }
377
378 protected:
379 void readError () const
380 {
381 DUNE_THROW( StreamError, "Unable to read from stream." );
382 }
383 };
384
388 template <class StreamImpl>
390 {
393
400 static StreamImpl* create( const std::string& filename,
401 const int rank = MPIManager::rank(),
403 {
404 return new StreamImpl( filename );
405 }
406 };
407
408 } // namespace Fem
409
410} // end namespace Dune
411
412#include "streams_inline.hh"
413
414#endif // #ifndef DUNE_FEM_STREAMS_HH
#define CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(__interface_method_to_call__)
Definition: bartonnackmanifcheck.hh:61
abstract interface for an input stream
Definition: streams.hh:190
void readUnsignedInt(unsigned int &value)
read an unsigned int from the stream
Definition: streams.hh:342
int64_t readSignedInt64()
read an int64_t from the stream
Definition: streams.hh:281
double readDouble()
read a double from the stream
Definition: streams.hh:221
bool readBool()
read a bool from the stream
Definition: streams.hh:322
float readFloat()
read a double from the stream
Definition: streams.hh:241
Traits::InStreamType InStreamType
type of the implementation (Barton-Nackman)
Definition: streams.hh:199
ThisType InStreamInterfaceType
type of the interface
Definition: streams.hh:202
void readString(std::string &s)
read a string from the stream
Definition: streams.hh:333
void readInt(int &value)
read an int from the stream
Definition: streams.hh:252
void readDouble(double &value)
read a double from the stream
Definition: streams.hh:212
void readFloat(float &value)
read a float from the stream
Definition: streams.hh:232
void readChar(char &value)
read a char from the stream
Definition: streams.hh:292
TraitsImp Traits
type of the traits
Definition: streams.hh:196
int readChar()
read a char from the stream
Definition: streams.hh:301
void readSignedInt64(int64_t &value)
read an int64_t from the stream
Definition: streams.hh:272
unsigned int readUnsignedInt()
read an unsigned int from the stream
Definition: streams.hh:351
void readUnsignedInt64(uint64_t &value)
read an uint64_t from the stream
Definition: streams.hh:362
int readInt()
read an int from the stream
Definition: streams.hh:261
uint64_t readUnsignedInt64()
read an uint64_t from the stream
Definition: streams.hh:371
void readBool(bool &value)
read a bool from the stream
Definition: streams.hh:313
abstract interface for an output stream
Definition: streams.hh:48
void writeBool(const bool value)
write a bool to the stream
Definition: streams.hh:125
Traits::OutStreamType OutStreamType
type of the implementation (Barton-Nackman)
Definition: streams.hh:57
void writeInt(const int value)
write an int to the stream
Definition: streams.hh:98
void writeSignedInt64(int64_t value)
write an int64_t to the stream
Definition: streams.hh:107
void flush()
flush the stream
Definition: streams.hh:71
void writeChar(const char value)
write a char to the stream
Definition: streams.hh:116
void writeUnsignedInt(unsigned int value)
write an unsigned int to the stream
Definition: streams.hh:143
void writeDouble(const double value)
write a double to the stream
Definition: streams.hh:80
void writeString(const std::string &s)
write a string to the stream
Definition: streams.hh:134
void writeFloat(const float value)
write a float to the stream
Definition: streams.hh:89
ThisType OutStreamInterfaceType
type of the interface
Definition: streams.hh:60
TraitsImp Traits
type of the traits
Definition: streams.hh:54
void writeUnsignedInt64(uint64_t value)
write an uint64_t to the stream
Definition: streams.hh:152
MPI_Comm MPICommunicator
The type of the mpi communicator.
Definition: mpihelper.hh:192
static MPICommunicator getCommunicator()
get the default communicator
Definition: mpihelper.hh:200
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
Factory class for Fem Streams to deal with different constructor parameters.
Definition: streams.hh:390
static StreamImpl * create(const std::string &filename, const int rank=MPIManager::rank(), const MPICommunicatorType &mpiComm=MPIHelper ::getCommunicator())
return pointer to stream object created by new.
Definition: streams.hh:400
MPIHelper::MPICommunicator MPICommunicatorType
type of MPI communicator
Definition: streams.hh:392
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)