1 #ifndef DUNE_FEM_XDRSTREAMS_HH 2 #define DUNE_FEM_XDRSTREAMS_HH 8 #include <dune/common/exceptions.hh> 17 template<
class OutStreamImp >
35 template<
class OutStreamImp >
49 enum { maxStringSize = 2<<18 };
55 using BaseType::writeError;
65 if( xdr_double( xdrs(), &value ) == 0 )
72 if( xdr_float( xdrs(), &value ) == 0 )
79 if( xdr_int( xdrs(), &value ) == 0 )
86 if( xdr_char( xdrs(), &value ) == 0 )
94 char val = ( value == true ) ? 1 : 0;
101 assert( s.size() < maxStringSize );
102 const char *cs = s.c_str();
103 if( xdr_string( xdrs(), (
char **)&cs, maxStringSize ) == 0 )
110 if( xdr_u_int( xdrs(), &value ) == 0 )
117 #ifdef XDR_UINT64_FUNC 119 u_int64_t val = value ;
121 if( XDR_UINT64_FUNC( xdrs(), &val ) == 0 )
124 DUNE_THROW(NotImplemented,
"xdr_uint64_t is missing");
137 template<
class InStreamImp >
154 template<
class InStreamImp >
169 enum { maxStringSize = 2<<18 };
175 using BaseType::readError;
185 if( xdr_double( xdrs(), &value ) == 0 )
192 if( xdr_float( xdrs(), &value ) == 0 )
199 if( xdr_int( xdrs(), &value ) == 0 )
206 if( xdr_char( xdrs(), &value ) == 0 )
216 value = ( val == 1 ) ?
true :
false;
222 char data[ maxStringSize ];
223 char *cs = &(data[ 0 ]);
224 if( xdr_string( xdrs(), &cs, maxStringSize ) == 0 )
232 if( xdr_u_int( xdrs(), &value ) == 0 )
239 #ifdef XDR_UINT64_FUNC 243 if( XDR_UINT64_FUNC( xdrs(), &val ) == 0 )
248 DUNE_THROW(NotImplemented,
"xdr_uint64_t is missing");
275 using BaseType :: xdrs;
288 const bool append =
false )
290 const char * flags = ( append ) ?
"ab" :
"wb";
291 file_ = fopen( filename.c_str(), flags );
293 DUNE_THROW( IOError,
"XDRFileOutStream: Unable to open file '" << filename <<
"'." );
294 xdrstdio_create( xdrs(), file_, XDR_ENCODE );
300 xdr_destroy( xdrs() );
327 using BaseType :: xdrs;
340 const size_t pos = 0 )
342 file_ = fopen( filename.c_str(),
"rb" );
344 DUNE_THROW( IOError,
"XDRFileInStream: Unable to open file '" << filename <<
"'." );
347 fseek( file_, pos , SEEK_SET );
349 xdrstdio_create( xdrs(), file_, XDR_DECODE );
356 xdr_destroy( xdrs() );
365 #endif // #ifndef DUNE_FEM_XDRSTREAMS_HH void flush()
flush the stream
Definition: xdrstreams.hh:305
void writeInt(int value)
write an int to the stream
Definition: xdrstreams.hh:77
XDROutStreamTraits< OutStreamType > Traits
type of the traits
Definition: xdrstreams.hh:47
FILE * file_
Definition: xdrstreams.hh:330
XDRFileOutStream(const std::string &filename, const bool append=false)
constructor
Definition: xdrstreams.hh:287
void writeUnsignedInt64(uint64_t value)
write an uint64_t to the stream
Definition: xdrstreams.hh:115
~XDRFileOutStream()
destructor
Definition: xdrstreams.hh:298
InStreamImp InStreamType
Definition: xdrstreams.hh:140
FILE * file_
Definition: xdrstreams.hh:278
XDRBasicInStream()
Definition: xdrstreams.hh:178
void writeUnsignedInt(unsigned int value)
write an unsigned int to the stream
Definition: xdrstreams.hh:108
XDR xdrs_
Definition: xdrstreams.hh:52
XDRBasicOutStream()
Definition: xdrstreams.hh:58
XDR output stream reading from a file.
Definition: xdrstreams.hh:319
void writeString(const std::string &s)
write a string to the stream
Definition: xdrstreams.hh:99
void readInt(int &value)
read an int from the stream
Definition: xdrstreams.hh:197
Definition: xdrstreams.hh:18
void readFloat(float &value)
read a float from the stream
Definition: xdrstreams.hh:190
OutStreamImp OutStreamType
Definition: xdrstreams.hh:20
void readDouble(double &value)
read a double from the stream
Definition: xdrstreams.hh:183
void readUnsignedInt64(uint64_t &value)
read an uint64_t from the stream
Definition: xdrstreams.hh:237
Definition: coordinate.hh:4
base implementation for XDR output streams
Definition: xdrstreams.hh:36
void readBool(bool &value)
read a bool from the stream
Definition: xdrstreams.hh:211
void writeChar(char value)
write a char to the stream
Definition: xdrstreams.hh:84
InStreamImp InStreamType
type of the implementation (Barton-Nackman)
Definition: xdrstreams.hh:163
abstract interface for an input stream
Definition: streams.hh:177
XDRInStreamTraits< InStreamType > Traits
type of the traits
Definition: xdrstreams.hh:166
void writeFloat(float value)
write a float to the stream
Definition: xdrstreams.hh:70
void writeBool(const bool value)
write a bool to the stream
Definition: xdrstreams.hh:91
OutStreamImp OutStreamType
type of the implementaton (Barton-Nackman)
Definition: xdrstreams.hh:44
XDR xdrs_
Definition: xdrstreams.hh:172
Definition: xdrstreams.hh:138
void readString(std::string &s)
read a string from the stream
Definition: xdrstreams.hh:220
void writeDouble(double value)
write a double to the stream
Definition: xdrstreams.hh:63
XDR * xdrs()
Definition: xdrstreams.hh:129
XDR * xdrs()
Definition: xdrstreams.hh:253
base implementation for XDR input streams
Definition: xdrstreams.hh:155
void readChar(char &value)
read a char from the stream
Definition: xdrstreams.hh:204
XDR output stream writing into a file.
Definition: xdrstreams.hh:267
~XDRFileInStream()
destructor
Definition: xdrstreams.hh:354
abstract interface for an output stream
Definition: streams.hh:44
XDRFileInStream(const std::string &filename, const size_t pos=0)
constructor
Definition: xdrstreams.hh:339
void readUnsignedInt(unsigned int &value)
read an unsigned int from the stream
Definition: xdrstreams.hh:230