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; }
67 template<
class T >
DataIStream& operator >> ( Array< T > array )
68 { _readArray( array, boost::has_trivial_copy< T >( ));
return *
this; }
74 template<
class T >
DataIStream& operator >> ( lunchbox::RefPtr< T >& );
77 template<
class T >
DataIStream& operator >> ( lunchbox::Buffer< T >& );
80 template<
class T >
DataIStream& operator >> ( std::vector< T >& );
83 template<
class K,
class V >
87 template<
class T >
DataIStream& operator >> ( std::set< T >& );
90 template<
class K,
class V >
91 DataIStream& operator >> ( stde::hash_map< K, V >& );
94 template<
class T >
DataIStream& operator >> ( stde::hash_set< T >& );
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 );
143 CO_API
const void* getRemainingBuffer(
const uint64_t size );
149 CO_API uint64_t getRemainingBufferSize();
152 bool wasUsed()
const;
158 CO_API
virtual NodePtr getRemoteNode()
const = 0;
168 explicit DataIStream(
const DataIStream& );
169 CO_API
virtual ~DataIStream();
171 virtual bool getNextBuffer( CompressorInfo& info, 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 CompressorInfo& info,
189 uint32_t nChunks, uint64_t dataSize );
193 DataIStream& _readFlatVector ( std::vector< T >& value )
197 LBASSERTINFO( nElems < LB_BIT48,
198 "Out-of-sync DataIStream: " << nElems <<
" elements?" );
199 value.resize(
size_t( nElems ));
201 *
this >> Array< T >( &value.front(), nElems );
206 template<
class T >
void _swap( T& value )
const 207 {
if( isSwapping( )) swap( value ); }
210 template<
class T >
void _read( T& value,
const boost::true_type& )
211 { _read( &value,
sizeof( value )); _swap( value ); }
214 template<
class T >
void _read( T& value,
const boost::false_type& )
215 { _readSerializable( value, boost::is_base_of< servus::Serializable, T >( ));}
218 template<
class T >
void _readSerializable(T& value,
const boost::true_type&);
221 template<
class T >
void _readArray( Array< T >,
const boost::true_type& );
224 template<
class T >
void _readArray( Array< T >,
const boost::false_type& );
227 template<
class T >
void _swap( Array< T > array )
const 231 #pragma omp parallel for 232 for( ssize_t i = 0; i < ssize_t( array.num ); ++i )
233 swap( array.data[i] );
238 #include "dataIStream.ipp" 240 #endif //CO_DATAISTREAM_H
Defines export visibility macros for library Collage.
static void swap(T &v)
Byte-swap a plain data item.
lunchbox::RefPtr< LocalNode > LocalNodePtr
A reference pointer for LocalNode pointers.
lunchbox::RefPtr< Node > NodePtr
A reference pointer for Node pointers.
Object-oriented network library.
A std::istream-like input data stream for binary data.