dune-fem 2.8.0
Loading...
Searching...
No Matches
virtualstreams.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_VIRTUALSTREAMS_HH
2#define DUNE_FEM_VIRTUALSTREAMS_HH
3
5
6namespace Dune
7{
8
9 namespace Fem
10 {
11
12 // Forward Declarations
13 // --------------------
14
15 class VirtualOutStream;
16
17 class VirtualInStream;
18
19 template< class Traits >
20 VirtualOutStream virtualize ( OutStreamInterface< Traits > &stream );
21
22 template< class Traits >
23 VirtualInStream virtualize ( InStreamInterface< Traits > &stream );
24
25
26
27 // VirtualOutStreamObject
28 // ----------------------
29
31 {
33
34 friend class VirtualOutStream;
35
36 private:
37 unsigned int refCount;
38
39 protected:
41 : refCount( 0 )
42 {}
44
45 public:
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 writeString ( const std::string &s ) = 0;
51 virtual void writeUnsignedInt ( unsigned int value ) = 0;
52 virtual void writeUnsignedInt64 ( uint64_t value ) = 0;
53 };
54
55
56
57 // VirtualOutStreamTraits
58 // ----------------------
59
61 {
63 };
64
65
66
67 // VirtualOutStream
68 // ----------------
69
71 : public OutStreamInterface< VirtualOutStreamTraits >
72 {
75
76 template< class T >
78
79 private:
80 VirtualOutStreamObject *const stream_;
81
82 private:
83 explicit VirtualOutStream ( VirtualOutStreamObject *stream )
84 : stream_( stream )
85 {
86 ++stream_->refCount;
87 }
88
89 public:
90 VirtualOutStream ( const ThisType &other )
91 : stream_( other.stream_ )
92 {
93 ++stream_->refCount;
94 }
95
97 {
98 if( --stream_->refCount == 0 )
99 delete stream_;
100 }
101
102 private:
103 ThisType &operator= ( const ThisType & );
104
105 public:
106 void flush ()
107 {
108 stream_->flush();
109 }
110
111 void writeDouble ( double value )
112 {
113 stream_->writeDouble( value );
114 }
115
116 void writeFloat ( float value )
117 {
118 stream_->writeFloat( value );
119 }
120
121 void writeInt ( int value )
122 {
123 stream_->writeInt( value );
124 }
125
126 void writeString ( const std :: string &s )
127 {
128 stream_->writeString( s );
129 }
130
131 void writeUnsignedInt ( unsigned int value )
132 {
133 stream_->writeUnsignedInt( value );
134 }
135
136 void writeUnsignedInt64 ( unsigned int value )
137 {
138 stream_->writeUnsignedInt64( value );
139 }
140 };
141
142
143
144 // VirtualInStreamObject
145 // ---------------------
146
148 {
150
151 friend class VirtualInStream;
152
153 private:
154 unsigned int refCount;
155
156 protected:
158 : refCount( 0 )
159 {}
160
162
163 public:
164 virtual void readDouble ( double &value ) = 0;
165 virtual void readFloat ( float &value ) = 0;
166 virtual void readInt ( int &value ) = 0;
167 virtual void readString ( std::string &s ) = 0;
168 virtual void readUnsignedInt ( unsigned int &value ) = 0;
169 virtual void readUnsignedInt64 ( uint64_t &value ) = 0;
170 };
171
172
173
174 // VirtualInStreamTraits
175 // ---------------------
176
178 {
180 };
181
182
183
184 // VirtualInStream
185 // ---------------
186
188 : public InStreamInterface< VirtualInStreamTraits >
189 {
192
193 template< class T >
195
196 private:
197 VirtualInStreamObject *const stream_;
198
199 private:
200 explicit VirtualInStream ( VirtualInStreamObject *stream )
201 : stream_( stream )
202 {
203 ++stream_->refCount;
204 }
205
206 public:
207 VirtualInStream ( const ThisType &other )
208 : stream_( other.stream_ )
209 {
210 ++stream_->refCount;
211 }
212
214 {
215 if( --stream_->refCount == 0 )
216 delete stream_;
217 }
218
219 private:
220 ThisType &operator= ( const ThisType & );
221
222 public:
223 void readDouble ( double &value )
224 {
225 stream_->readDouble( value );
226 }
227
228 void readFloat ( float &value )
229 {
230 stream_->readFloat( value );
231 }
232
233 void readInt ( int &value )
234 {
235 stream_->readInt( value );
236 }
237
238 void readString ( std :: string &s )
239 {
240 stream_->readString( s );
241 }
242
243 void readUnsignedInt ( unsigned int &value )
244 {
245 stream_->readUnsignedInt( value );
246 }
247
248 void readUnsignedInt64 ( uint64_t &value )
249 {
250 stream_->readUnsignedInt64( value );
251 }
252 };
253
254
255
256 // VirtualOutStreamWrapper
257 // -----------------------
258
259 template< class Traits >
262 {
265
266 template< class T >
268
269 public:
271
272 private:
273 StreamType &stream_;
274
275 private:
276 explicit VirtualOutStreamWrapper ( StreamType &stream )
277 : stream_( stream )
278 {}
279
280 VirtualOutStreamWrapper ( const ThisType & );
281 ThisType &operator= ( const ThisType & );
282
283 public:
284 virtual void flush ()
285 {
286 stream_.flush();
287 }
288
289 virtual void writeDouble ( double value )
290 {
291 stream_.writeDouble( value );
292 }
293
294 virtual void writeFloat ( float value )
295 {
296 stream_.writeFloat( value );
297 }
298
299 virtual void writeInt ( int value )
300 {
301 stream_.writeInt( value );
302 }
303
304 virtual void writeString ( const std :: string &s )
305 {
306 stream_.writeString( s );
307 }
308
309 virtual void writeUnsignedInt( unsigned int value )
310 {
311 stream_.writeUnsignedInt( value );
312 }
313
314 virtual void writeUnsignedInt64( uint64_t value )
315 {
316 stream_.writeUnsignedInt64( value );
317 }
318 };
319
320
321
322 // VirtualInStreamWrapper
323 // ----------------------
324
325 template< class Traits >
327 : public VirtualInStreamObject
328 {
331
332 template< class T >
334
335 public:
337
338 private:
339 StreamType &stream_;
340
341 private:
342 explicit VirtualInStreamWrapper ( StreamType &stream )
343 : stream_( stream )
344 {}
345
346 VirtualInStreamWrapper ( const ThisType & );
347 ThisType &operator= ( const ThisType & );
348
349 public:
350 virtual void readDouble ( double &value )
351 {
352 stream_.readDouble( value );
353 }
354
355 virtual void readFloat ( float &value )
356 {
357 stream_.readFloat( value );
358 }
359
360 virtual void readInt ( int &value )
361 {
362 stream_.readInt( value );
363 }
364
365 virtual void readString ( std :: string &s )
366 {
367 stream_.readString( s );
368 }
369
370 virtual void readUnsignedInt( unsigned int &value )
371 {
372 stream_.readUnsignedInt( value );
373 }
374
375 virtual void readUnsignedInt64( uint64_t &value )
376 {
377 stream_.readUnsignedInt64( value );
378 }
379 };
380
381
382
383 // virtualize
384 // ----------
385
386 template< class Traits >
388 {
390 }
391
392 template< class Traits >
394 {
396 }
397
398 } // namespave Fem
399
400} // namespace Dune
401
402#endif // #ifndef DUNE_FEM_VIRTUALSTREAMS_HH
Definition: bindguard.hh:11
VirtualOutStream virtualize(OutStreamInterface< Traits > &stream)
Definition: virtualstreams.hh:387
abstract interface for an output stream
Definition: streams.hh:46
void writeInt(const int value)
write an int to the stream
Definition: streams.hh:96
void flush()
flush the stream
Definition: streams.hh:69
void writeUnsignedInt(unsigned int value)
write an unsigned int to the stream
Definition: streams.hh:132
void writeDouble(const double value)
write a double to the stream
Definition: streams.hh:78
void writeString(const std::string &s)
write a string to the stream
Definition: streams.hh:123
void writeFloat(const float value)
write a float to the stream
Definition: streams.hh:87
void writeUnsignedInt64(uint64_t value)
write an uint64_t to the stream
Definition: streams.hh:141
abstract interface for an input stream
Definition: streams.hh:179
void readUnsignedInt(unsigned int &value)
read an unsigned int from the stream
Definition: streams.hh:311
void readString(std::string &s)
read a string from the stream
Definition: streams.hh:302
void readInt(int &value)
read an int from the stream
Definition: streams.hh:241
void readDouble(double &value)
read a double from the stream
Definition: streams.hh:201
void readFloat(float &value)
read a float from the stream
Definition: streams.hh:221
void readUnsignedInt64(uint64_t &value)
read an uint64_t from the stream
Definition: streams.hh:331
Definition: virtualstreams.hh:31
virtual void writeUnsignedInt64(uint64_t value)=0
virtual void writeFloat(float value)=0
virtual void writeString(const std::string &s)=0
VirtualOutStreamObject()
Definition: virtualstreams.hh:40
virtual void writeUnsignedInt(unsigned int value)=0
virtual void writeInt(int value)=0
virtual ~VirtualOutStreamObject()
Definition: virtualstreams.hh:43
virtual void writeDouble(double value)=0
Definition: virtualstreams.hh:61
VirtualOutStream OutStreamType
Definition: virtualstreams.hh:62
Definition: virtualstreams.hh:72
friend VirtualOutStream virtualize(OutStreamInterface< T > &)
void flush()
Definition: virtualstreams.hh:106
VirtualOutStream(const ThisType &other)
Definition: virtualstreams.hh:90
void writeUnsignedInt(unsigned int value)
Definition: virtualstreams.hh:131
void writeUnsignedInt64(unsigned int value)
Definition: virtualstreams.hh:136
void writeString(const std ::string &s)
Definition: virtualstreams.hh:126
void writeInt(int value)
Definition: virtualstreams.hh:121
void writeDouble(double value)
Definition: virtualstreams.hh:111
void writeFloat(float value)
Definition: virtualstreams.hh:116
virtual ~VirtualOutStream()
Definition: virtualstreams.hh:96
Definition: virtualstreams.hh:148
virtual void readInt(int &value)=0
virtual void readUnsignedInt64(uint64_t &value)=0
VirtualInStreamObject()
Definition: virtualstreams.hh:157
virtual void readUnsignedInt(unsigned int &value)=0
virtual void readString(std::string &s)=0
virtual void readDouble(double &value)=0
virtual void readFloat(float &value)=0
virtual ~VirtualInStreamObject()
Definition: virtualstreams.hh:161
Definition: virtualstreams.hh:178
VirtualInStream InStreamType
Definition: virtualstreams.hh:179
Definition: virtualstreams.hh:189
void readString(std ::string &s)
Definition: virtualstreams.hh:238
void readDouble(double &value)
Definition: virtualstreams.hh:223
void readUnsignedInt(unsigned int &value)
Definition: virtualstreams.hh:243
void readUnsignedInt64(uint64_t &value)
Definition: virtualstreams.hh:248
virtual ~VirtualInStream()
Definition: virtualstreams.hh:213
VirtualInStream(const ThisType &other)
Definition: virtualstreams.hh:207
void readInt(int &value)
Definition: virtualstreams.hh:233
friend VirtualInStream virtualize(InStreamInterface< T > &)
void readFloat(float &value)
Definition: virtualstreams.hh:228
Definition: virtualstreams.hh:262
virtual void writeFloat(float value)
Definition: virtualstreams.hh:294
friend VirtualOutStream virtualize(OutStreamInterface< T > &)
virtual void writeUnsignedInt64(uint64_t value)
Definition: virtualstreams.hh:314
virtual void writeUnsignedInt(unsigned int value)
Definition: virtualstreams.hh:309
virtual void writeString(const std ::string &s)
Definition: virtualstreams.hh:304
virtual void flush()
Definition: virtualstreams.hh:284
virtual void writeInt(int value)
Definition: virtualstreams.hh:299
virtual void writeDouble(double value)
Definition: virtualstreams.hh:289
OutStreamInterface< Traits > StreamType
Definition: virtualstreams.hh:270
Definition: virtualstreams.hh:328
InStreamInterface< Traits > StreamType
Definition: virtualstreams.hh:336
virtual void readInt(int &value)
Definition: virtualstreams.hh:360
virtual void readUnsignedInt(unsigned int &value)
Definition: virtualstreams.hh:370
virtual void readDouble(double &value)
Definition: virtualstreams.hh:350
virtual void readUnsignedInt64(uint64_t &value)
Definition: virtualstreams.hh:375
virtual void readFloat(float &value)
Definition: virtualstreams.hh:355
friend VirtualInStream virtualize(InStreamInterface< T > &)
virtual void readString(std ::string &s)
Definition: virtualstreams.hh:365