22 #ifndef CO_DATAISTREAM_H
23 #define CO_DATAISTREAM_H
27 #include <lunchbox/array.h>
28 #include <lunchbox/bitOperation.h>
29 #include <lunchbox/stdExt.h>
31 #include <boost/type_traits.hpp>
38 namespace detail {
class DataIStream; }
47 virtual size_t nRemainingBuffers()
const = 0;
49 virtual uint128_t getVersion()
const = 0;
50 virtual void reset() { _reset(); }
51 void setSwapping(
const bool onOff );
52 CO_API
bool isSwapping()
const;
59 template<
typename T > T
read()
60 { T value; *
this >> value;
return value; }
64 { _read( value, boost::has_trivial_copy< T >( ));
return *
this; }
68 { _readArray( array, boost::has_trivial_copy< T >( ));
return *
this; }
83 template<
class K,
class V >
90 template<
class K,
class V >
101 # ifdef CO_IGNORE_BYTESWAP
103 template<
class T >
static void swap( T& ) { }
106 template<
class T >
static void swap( T& v ) { lunchbox::byteswap(v); }
120 template<
typename O,
typename C >
121 void deserializeChildren( O*
object,
const std::vector< C* >& old,
122 std::vector< C* >& result );
152 bool wasUsed()
const;
171 virtual bool getNextBuffer( uint32_t& compressor, uint32_t& nChunks,
172 const void** chunkData, uint64_t& size )=0;
176 detail::DataIStream*
const _impl;
179 CO_API
void _read(
void* data, uint64_t size );
185 CO_API
bool _checkBuffer();
186 CO_API
void _reset();
188 const uint8_t* _decompress(
const void* data,
const uint32_t name,
189 const uint32_t nChunks,
190 const uint64_t dataSize );
194 DataIStream& _readFlatVector ( std::vector< T >& value )
198 LBASSERTINFO( nElems < LB_BIT48,
199 "Out-of-sync DataIStream: " << nElems <<
" elements?" );
200 value.resize(
size_t( nElems ));
202 *
this >> Array< T >( &value.front(), nElems );
207 template<
class T >
void _swap( T& value )
const
208 {
if( isSwapping( ))
swap( value ); }
211 template<
class T >
void _read( T& value,
const boost::true_type& )
212 { _read( &value,
sizeof( value )); _swap( value ); }
215 template<
class T >
void _read( T& value,
const boost::false_type& )
216 { _readSerializable( value, boost::is_base_of< servus::Serializable, T >( ));}
219 template<
class T >
void _readSerializable(T& value,
const boost::true_type&);
222 template<
class T >
void _readArray( Array< T >,
const boost::true_type& );
225 template<
class T >
void _readArray( Array< T >,
const boost::false_type& );
228 template<
class T >
void _swap( Array< T > array )
const
232 #pragma omp parallel for
233 for( ssize_t i = 0; i < ssize_t( array.num ); ++i )
234 swap( array.data[i] );
239 #include "dataIStream.ipp"
241 #endif //CO_DATAISTREAM_H
Defines export visibility macros for library Collage.
static void swap(T &v)
Byte-swap a plain data item.
virtual CO_API LocalNodePtr getLocalNode() const =0
lunchbox::RefPtr< LocalNode > LocalNodePtr
A reference pointer for LocalNode pointers.
lunchbox::RefPtr< Node > NodePtr
A reference pointer for Node pointers.
Object-oriented network library.
CO_API const void * getRemainingBuffer(const uint64_t size)
DataIStream & operator>>(T &value)
Read a plain data item.
CO_API uint64_t getRemainingBufferSize()
A std::istream-like input data stream for binary data.
virtual CO_API NodePtr getRemoteNode() const =0