22 #ifndef CO_DATAOSTREAM_H
23 #define CO_DATAOSTREAM_H
28 #include <lunchbox/array.h>
29 #include <lunchbox/nonCopyable.h>
30 #include <lunchbox/stdExt.h>
32 #include <boost/type_traits.hpp>
39 namespace detail {
class DataOStream; }
40 namespace DataStreamTest {
class Sender; }
54 CO_API
void disable();
63 CO_API
bool hasSentData()
const;
73 const uint64_t dataSize );
76 uint64_t getCompressedDataSize()
const;
83 { _write( &value,
sizeof( value ));
return *
this; }
86 template<
class T >
DataOStream& operator << ( const Array< T > array )
87 { _writeArray( array, boost::is_pod<T>( ));
return *
this; }
94 DataOStream& operator << ( const lunchbox::RefPtr< T >& ptr );
98 DataOStream& operator << ( const lunchbox::Buffer< T >& buffer );
103 {
return (*
this) << request.getID(); }
107 DataOStream& operator << ( const std::vector< T >& value );
110 template<
class K,
class V >
111 DataOStream& operator << ( const std::map< K, V >& value );
115 DataOStream& operator << ( const std::set< T >& value );
118 template<
class K,
class V >
119 DataOStream& operator << ( const stde::hash_map< K, V >& value );
123 DataOStream& operator << ( const stde::hash_set< T >& value );
131 template<
typename C >
132 void serializeChildren(
const std::vector< C* >& children );
141 CO_API lunchbox::Bufferb& getBuffer();
144 void _initCompressor(
const uint32_t compressor );
147 CO_API
void _enable();
150 void flush(
const bool last );
155 void _setupConnections(
const Nodes& receivers );
157 void _setupConnections(
const Connections& connections );
160 void _setupConnection(
NodePtr node,
const bool useMulticast );
164 friend class DataStreamTest::Sender;
169 void _clearConnections();
174 virtual void sendData(
const void* buffer,
const uint64_t size,
175 const bool last ) = 0;
179 virtual CO_API
void reset();
182 detail::DataOStream*
const _impl;
185 CO_API uint64_t _getCompressedData(
void** chunks,
186 uint64_t* chunkSizes )
const;
189 CO_API
void _write(
const void* data, uint64_t size );
192 void _sendData(
const void* data,
const uint64_t size );
199 DataOStream& _writeFlatVector(
const std::vector< T >& value )
201 const uint64_t nElems = value.size();
202 _write( &nElems,
sizeof( nElems ));
204 _write( &value.front(), nElems *
sizeof( T ));
210 void _writeArray(
const Array< T > array,
const boost::true_type& )
211 { _write( array.data, array.getNumBytes( )); }
215 void _writeArray(
const Array< T > array,
const boost::false_type& )
217 for(
size_t i = 0; i < array.num; ++i )
218 *
this << array.data[ i ];
222 void _sendFooter(
const void* buffer,
const uint64_t size );
225 std::ostream& operator << ( std::ostream&,
const DataOStream& );
228 #include "dataOStream.ipp"
230 #endif //CO_DATAOSTREAM_H
Defines export visibility macros for Collage.
std::vector< ConnectionPtr > Connections
A vector of ConnectionPtr's.
DataOStream & operator<<(const T &value)
Write a plain data item by copying it to the stream.
lunchbox::RefPtr< Node > NodePtr
A reference pointer for Node pointers.
A std::ostream-like interface for object serialization.
std::vector< NodePtr > Nodes
A vector of NodePtr's.
lunchbox::RefPtr< Connection > ConnectionPtr
A reference pointer for Connection pointers.