1#ifndef DUNE_FEM_VIRTUALSTREAMS_HH
2#define DUNE_FEM_VIRTUALSTREAMS_HH
4#include <dune/fem/io/streams/streams.hh>
15 class VirtualOutStream;
17 class VirtualInStream;
19 template<
class Traits >
20 VirtualOutStream virtualize ( OutStreamInterface< Traits > &stream );
22 template<
class Traits >
23 VirtualInStream virtualize ( InStreamInterface< Traits > &stream );
30 class VirtualOutStreamObject
32 typedef VirtualOutStreamObject ThisType;
34 friend class VirtualOutStream;
37 unsigned int refCount;
40 inline VirtualOutStreamObject ()
43 virtual ~VirtualOutStreamObject() {}
46 virtual void flush () = 0;
47 virtual void writeDouble (
double value ) = 0;
48 virtual void writeFloat (
float value ) = 0;
49 virtual void writeInt (
int value ) = 0;
50 virtual void writeSignedInt64 ( int64_t value ) = 0;
51 virtual void writeString (
const std::string &s ) = 0;
52 virtual void writeUnsignedInt (
unsigned int value ) = 0;
53 virtual void writeUnsignedInt64 ( uint64_t value ) = 0;
61 struct VirtualOutStreamTraits
63 typedef VirtualOutStream OutStreamType;
71 class VirtualOutStream
72 :
public OutStreamInterface< VirtualOutStreamTraits >
74 typedef VirtualOutStream ThisType;
78 friend VirtualOutStream virtualize ( OutStreamInterface< T > & );
81 VirtualOutStreamObject *
const stream_;
84 explicit VirtualOutStream ( VirtualOutStreamObject *stream )
91 VirtualOutStream (
const ThisType &other )
92 : stream_( other.stream_ )
97 virtual ~VirtualOutStream ()
99 if( --stream_->refCount == 0 )
104 ThisType &operator= (
const ThisType & );
112 void writeDouble (
double value )
114 stream_->writeDouble( value );
117 void writeFloat (
float value )
119 stream_->writeFloat( value );
122 void writeInt (
int value )
124 stream_->writeInt( value );
127 void writeSignedInt64 ( int64_t value )
129 stream_->writeSignedInt64( value );
134 stream_->writeString( s );
137 void writeUnsignedInt (
unsigned int value )
139 stream_->writeUnsignedInt( value );
144 stream_->writeUnsignedInt64( value );
153 class VirtualInStreamObject
155 typedef VirtualInStream ThisType;
157 friend class VirtualInStream;
160 unsigned int refCount;
163 VirtualInStreamObject ()
167 virtual ~VirtualInStreamObject() {}
170 virtual void readDouble (
double &value ) = 0;
171 virtual void readFloat (
float &value ) = 0;
172 virtual void readInt (
int &value ) = 0;
173 virtual void readSignedInt64 ( int64_t &value ) = 0;
174 virtual void readString ( std::string &s ) = 0;
175 virtual void readUnsignedInt (
unsigned int &value ) = 0;
176 virtual void readUnsignedInt64 ( uint64_t &value ) = 0;
184 struct VirtualInStreamTraits
186 typedef VirtualInStream InStreamType;
194 class VirtualInStream
195 :
public InStreamInterface< VirtualInStreamTraits >
197 typedef VirtualInStream ThisType;
201 friend VirtualInStream virtualize ( InStreamInterface< T > & );
204 VirtualInStreamObject *
const stream_;
207 explicit VirtualInStream ( VirtualInStreamObject *stream )
214 VirtualInStream (
const ThisType &other )
215 : stream_( other.stream_ )
220 virtual ~VirtualInStream ()
222 if( --stream_->refCount == 0 )
227 ThisType &operator= (
const ThisType & );
232 stream_->readDouble( value );
237 stream_->readFloat( value );
242 stream_->readInt( value );
247 stream_->readSignedInt64( value );
252 stream_->readString( s );
257 stream_->readUnsignedInt( value );
262 stream_->readUnsignedInt64( value );
271 template<
class Traits >
272 class VirtualOutStreamWrapper
273 :
public VirtualOutStreamObject
275 typedef VirtualOutStreamWrapper< Traits > ThisType;
276 typedef VirtualOutStreamObject BaseType;
279 friend VirtualOutStream virtualize ( OutStreamInterface< T > & );
282 typedef OutStreamInterface< Traits > StreamType;
288 explicit VirtualOutStreamWrapper ( StreamType &stream )
292 VirtualOutStreamWrapper (
const ThisType & );
293 ThisType &operator= (
const ThisType & );
296 virtual void flush ()
301 virtual void writeDouble (
double value )
303 stream_.writeDouble( value );
306 virtual void writeFloat (
float value )
308 stream_.writeFloat( value );
311 virtual void writeInt (
int value )
313 stream_.writeInt( value );
316 virtual void writeSignedInt64 ( int64_t value )
318 stream_.writeSignedInt64( value );
321 virtual void writeString (
const std :: string &s )
323 stream_.writeString( s );
326 virtual void writeUnsignedInt(
unsigned int value )
328 stream_.writeUnsignedInt( value );
331 virtual void writeUnsignedInt64( uint64_t value )
333 stream_.writeUnsignedInt64( value );
342 template<
class Traits >
343 class VirtualInStreamWrapper
344 :
public VirtualInStreamObject
346 typedef VirtualInStreamWrapper< Traits > ThisType;
347 typedef VirtualInStreamObject BaseType;
350 friend VirtualInStream virtualize ( InStreamInterface< T > & );
353 typedef InStreamInterface< Traits > StreamType;
359 explicit VirtualInStreamWrapper ( StreamType &stream )
363 VirtualInStreamWrapper (
const ThisType & );
364 ThisType &operator= (
const ThisType & );
367 virtual void readDouble (
double &value )
369 stream_.readDouble( value );
372 virtual void readFloat (
float &value )
374 stream_.readFloat( value );
377 virtual void readInt (
int &value )
379 stream_.readInt( value );
382 virtual void readSignedInt64 ( int64_t &value )
384 stream_.readSignedInt64( value );
387 virtual void readString ( std :: string &s )
389 stream_.readString( s );
392 virtual void readUnsignedInt(
unsigned int &value )
394 stream_.readUnsignedInt( value );
397 virtual void readUnsignedInt64( uint64_t &value )
399 stream_.readUnsignedInt64( value );
408 template<
class Traits >
409 VirtualOutStream virtualize ( OutStreamInterface< Traits > &stream )
411 return VirtualOutStream(
new VirtualOutStreamWrapper< Traits >( stream ) );
414 template<
class Traits >
415 VirtualInStream virtualize ( InStreamInterface< Traits > &stream )
417 return VirtualInStream(
new VirtualInStreamWrapper< Traits >( stream ) );
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
float readFloat()
read a double from the stream
Definition: streams.hh:241
void readString(std::string &s)
read a string from the stream
Definition: streams.hh:333
unsigned int readUnsignedInt()
read an unsigned int from the stream
Definition: streams.hh:351
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 writeString(const std::string &s)
write a string to the stream
Definition: streams.hh:134
void writeUnsignedInt64(uint64_t value)
write an uint64_t to the stream
Definition: streams.hh:152
Dune namespace.
Definition: alignedallocator.hh:13