00001
00002
00003
00004
00005 #ifndef EQNET_DATAISTREAM_H
00006 #define EQNET_DATAISTREAM_H
00007
00008 #include <eq/net/object.h>
00009 #include <eq/base/buffer.h>
00010
00011 #include <iostream>
00012 #include <vector>
00013
00014 namespace eq
00015 {
00016 namespace net
00017 {
00023 class EQ_EXPORT DataIStream
00024 {
00025 public:
00026 DataIStream();
00027 virtual ~DataIStream();
00028
00030
00032 template< typename T >
00033 DataIStream& operator >> ( T& value )
00034 { read( &value, sizeof( value )); return *this; }
00035
00037 template< typename T >
00038 DataIStream& operator >> ( std::vector< T >& value )
00039 {
00040 uint64_t nElems = 0;
00041 read( &nElems, sizeof( nElems ));
00042 value.resize( nElems );
00043 if( nElems > 0 )
00044 read( &value[0], nElems * sizeof( T ) );
00045 return *this;
00046 }
00047
00049 void read( void* data, uint64_t size );
00050
00052 const void* getRemainingBuffer();
00053
00055 uint64_t getRemainingBufferSize();
00056
00058 void advanceBuffer( const uint64_t offset );
00059
00061 virtual size_t nRemainingBuffers() const = 0;
00062
00063 virtual uint32_t getVersion() const { return Object::VERSION_NONE; }
00064
00065
00066 virtual void reset();
00067
00068 protected:
00069 virtual bool getNextBuffer( const uint8_t** buffer, uint64_t* size ) =0;
00070
00071 private:
00073 const uint8_t* _input;
00075 uint64_t _inputSize;
00077 uint64_t _position;
00078
00083 bool _checkBuffer();
00084 };
00085 }
00086 }
00087
00088 #include <eq/net/nodeID.h>
00089 namespace eq
00090 {
00091 namespace net
00092 {
00093
00094 template<>
00095 inline DataIStream& DataIStream::operator >> ( std::string& str )
00096 {
00097 uint64_t nElems = 0;
00098 read( &nElems, sizeof( nElems ));
00099 EQASSERT( nElems <= getRemainingBufferSize( ));
00100 if( nElems == 0 )
00101 str.clear();
00102 else
00103 {
00104 str.assign( static_cast< const char* >(getRemainingBuffer( )), nElems );
00105 advanceBuffer( nElems );
00106 }
00107 return *this;
00108 }
00109 template<>
00110 inline DataIStream& DataIStream::operator >> ( NodeID& nodeID )
00111 {
00112 read( &nodeID, sizeof( nodeID ));
00113 nodeID.convertToHost();
00114 return *this;
00115 }
00116 }
00117 }
00118
00119 #endif //EQNET_DATAISTREAM_H