22 #ifndef CO_DATAOSTREAM_H 23 #define CO_DATAOSTREAM_H 28 #include <lunchbox/array.h> 29 #include <lunchbox/stdExt.h> 31 #include <boost/noncopyable.hpp> 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;
82 template<
class T >
DataOStream& operator << (
const T& value )
83 { _write( value, boost::has_trivial_copy< T >( ));
return *
this; }
86 template<
class T >
DataOStream& operator << ( const Array< T > array )
87 { _writeArray( array, boost::has_trivial_copy<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 );
135 CO_API
static std::ostream& printStatistics( std::ostream& );
136 CO_API
static void clearStatistics();
140 explicit DataOStream( DataOStream& rhs );
141 virtual CO_API ~DataOStream();
144 CO_API lunchbox::Bufferb& getBuffer();
147 void _setCompressor(
const pression::data::CompressorInfo& info );
150 CO_API
void _enable();
153 void flush(
const bool last );
158 void _setupConnections(
const Nodes& receivers );
160 void _setupConnections(
const Connections& connections );
163 void _setupConnection(
NodePtr node,
const bool useMulticast );
167 friend class DataStreamTest::Sender;
172 void _clearConnections();
177 virtual void sendData(
const void* buffer,
const uint64_t size,
178 const bool last ) = 0;
182 virtual CO_API
void reset();
185 detail::DataOStream*
const _impl;
188 CO_API uint64_t _getCompressedData(
const uint8_t** chunks,
189 uint64_t* chunkSizes )
const;
192 CO_API
void _write(
const void* data, uint64_t size );
195 void _sendData(
const void* data,
const uint64_t size );
202 DataOStream& _writeFlatVector(
const std::vector< T >& value )
204 const uint64_t nElems = value.size();
205 _write( &nElems,
sizeof( nElems ));
207 _write( &value.front(), nElems *
sizeof( T ));
212 template<
class T >
void _write(
const T& value,
const boost::true_type& )
213 { _write( &value,
sizeof( value )); }
216 template<
class T >
void _write(
const T& value,
const boost::false_type& )
218 _writeSerializable( value,
219 boost::is_base_of< servus::Serializable, T >( ));
224 void _writeSerializable(
const T& value,
const boost::true_type& );
228 void _writeArray(
const Array< T > array,
const boost::true_type& )
229 { _write( array.data, array.getNumBytes( )); }
233 void _writeArray(
const Array< T > array,
const boost::false_type& )
235 for(
size_t i = 0; i < array.num; ++i )
236 *
this << array.data[ i ];
240 void _sendFooter(
const void* buffer,
const uint64_t size );
244 #include "dataOStream.ipp" 246 #endif //CO_DATAOSTREAM_H Defines export visibility macros for library Collage.
std::vector< ConnectionPtr > Connections
A vector of ConnectionPtr's.
lunchbox::RefPtr< Node > NodePtr
A reference pointer for Node pointers.
A std::ostream-like interface for object serialization.
Object-oriented network library.
std::vector< NodePtr > Nodes
A vector of NodePtr's.
lunchbox::RefPtr< Connection > ConnectionPtr
A reference pointer for Connection pointers.