1#ifndef DUNE_FEM_STANDARDSTREAMS_HH
2#define DUNE_FEM_STANDARDSTREAMS_HH
8#ifdef SYSTEM_ENDIAN_HEADER
9#include SYSTEM_ENDIAN_HEADER
12#include <dune/fem/io/streams/streams.hh>
23 static const char defaultEndian = 0;
24 static const char order =
25#if __BYTE_ORDER == __LITTLE_ENDIAN
27#elif __BYTE_ORDER == __BIG_ENDIAN
32 static inline size_t map(
const size_t pos,
36 return ( order == defaultEndian ) ? pos : (
size - pos - 1 );
40 class StandardOutStream;
41 class StandardInStream;
43 struct StandardOutStreamTraits
45 typedef StandardOutStream OutStreamType;
67 typedef StandardOutStreamTraits
Traits;
70 using BaseType::writeError;
85 std::ostream&
stream() {
return stream_; }
96 writePrimitive( value );
102 writePrimitive( value );
108 writePrimitive( value );
114 writePrimitive( value );
120 writePrimitive( value );
126 writePrimitive( value );
132 const unsigned int length = s.length();
133 writePrimitive( length );
134 for(
unsigned int i = 0; i < length; ++i )
135 writePrimitive( s[ i ] );
141 writePrimitive( value );
147 writePrimitive( value );
153 return bool( stream_ );
157 void writePrimitive (
const T &value )
159 const size_t tsize =
sizeof( T );
160 union { T value;
char bytes[ tsize ]; } convert;
163 convert.value = value;
166 assert(
sizeof(
char) == 1 ) ;
169 for(
size_t i=0; i<tsize; ++i )
171 stream_.put( convert.bytes[ ByteOrder :: map( i, tsize ) ] );
179 std::ostream& stream_;
183 struct StandardInStreamTraits
185 typedef StandardInStream InStreamType;
211 using BaseType::readError;
226 std::istream&
stream() {
return stream_; }
231 readPrimitive( value );
237 readPrimitive( value );
243 readPrimitive( value );
249 readPrimitive( value );
255 readPrimitive( value );
261 readPrimitive( value );
268 readPrimitive( length );
272 for(
unsigned int i = 0; i < length; ++i )
274 readPrimitive( s[ i ] );
281 readPrimitive( value );
287 readPrimitive( value );
293 return stream_.good() || stream_.eof();
297 void readPrimitive ( T &value )
299 const size_t tsize =
sizeof( T ) ;
300 union { T value;
char bytes[ tsize ]; } convert;
303 assert(
sizeof(
char) == 1 ) ;
306 for(
size_t i=0; i<tsize; ++i )
308 convert.bytes[ ByteOrder :: map( i, tsize ) ] = stream_.get();
312 value = convert.value;
319 std::istream& stream_;
abstract interface for an input stream
Definition: streams.hh:190
abstract interface for an output stream
Definition: streams.hh:48
input stream reading from a given std::istream
Definition: standardstreams.hh:202
void readUnsignedInt(unsigned int &value)
read an unsigned int from the stream
Definition: standardstreams.hh:279
void readDouble(double &value)
read a double from the stream
Definition: standardstreams.hh:229
std::istream & stream()
Definition: standardstreams.hh:226
void readInt(int &value)
read an int from the stream
Definition: standardstreams.hh:241
void readFloat(float &value)
read a float from the stream
Definition: standardstreams.hh:235
void readChar(char &value)
read a char from the stream
Definition: standardstreams.hh:253
StandardInStreamTraits Traits
type of the traits
Definition: standardstreams.hh:208
StandardInStream(std::istream &stream)
constructor
Definition: standardstreams.hh:218
void readString(std::string &s)
read a string from the stream
Definition: standardstreams.hh:265
void readUnsignedInt64(uint64_t &value)
read an uint64_t from the stream
Definition: standardstreams.hh:285
void readSignedInt64(int64_t &value)
read an int64_t from the stream
Definition: standardstreams.hh:247
void readBool(bool &value)
read a bool from the stream
Definition: standardstreams.hh:259
output stream writing into a given std::ostream
Definition: standardstreams.hh:61
void writeSignedInt64(int64_t value)
write an int64_t to the stream
Definition: standardstreams.hh:112
void flush()
flush the stream
Definition: standardstreams.hh:88
void writeUnsignedInt(unsigned int value)
write an unsigned int to the stream
Definition: standardstreams.hh:139
void writeString(const std::string &s)
write a string to the stream
Definition: standardstreams.hh:130
void writeFloat(const float value)
write a float to the stream
Definition: standardstreams.hh:100
void writeChar(const char value)
write a char to the stream
Definition: standardstreams.hh:118
void writeDouble(const double value)
write a double to the stream
Definition: standardstreams.hh:94
void writeBool(const bool value)
write a bool to the stream
Definition: standardstreams.hh:124
void writeUnsignedInt64(uint64_t value)
write an uint64_t to the stream
Definition: standardstreams.hh:145
StandardOutStreamTraits Traits
type of the traits
Definition: standardstreams.hh:67
void writeInt(const int value)
write an int to the stream
Definition: standardstreams.hh:106
std::ostream & stream()
Definition: standardstreams.hh:85
StandardOutStream(std::ostream &stream)
constructor
Definition: standardstreams.hh:77
Default exception class for I/O errors.
Definition: exceptions.hh:231
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75