61 if ( stream.isReading() )
63 else if ( stream.isWriting() )
89 stream.reserve( len );
90 m_stream->read( stream.data(), len );
106 ( *m_stream ) << stream.buffPointer();
107 m_stream->write( stream.data(), stream.buffPointer() );
179 template <
class TYPE>
184 refpObject =
dynamic_cast<TYPE*
>( pObj );
190 template <
class TYPE>
195 refpObject =
dynamic_cast<TYPE*
>( pObj );
223 m_length = ( len < 16384 ) ? 16384 : len;
233 if (
m_length < len ) new_len += len;
304#ifdef USE_STREAM_ANALYSER
305# define STREAM_ANALYSE( data, len ) \
306 if ( 0 != m_analyzer ) m_analyzer( &data, len, typeid( data ) )
308# define STREAM_ANALYSE( data, len )
312#define IMPLEMENT_STREAMER( TYPE ) \
314 StreamBuffer& operator<<( TYPE data ) { \
315 swapToBuffer( &data, sizeof( data ) ); \
316 STREAM_ANALYSE( data, sizeof( data ) ); \
320 StreamBuffer& operator>>( TYPE& data ) { \
321 swapFromBuffer( &data, sizeof( data ) ); \
326#undef IMPLEMENT_STREAMER
458 const char* ptr = 0 ==
data ?
"" :
data;
459 size_t len = strlen( ptr ) + 1;
475 const char* ptr =
data.c_str();
476 long len =
data.length();
489 template <
class TYPE>
538#if defined( __alpha ) && !defined( __VMS )
541#elif defined( __sun ) && defined( __SVR4 ) && defined( __i386 )
544#elif defined( __APPLE__ )
547#elif defined( __linux ) && !defined( __powerpc )
559 char buff[8], *tar, *src = (
char*)source;
568 for (
int i = 0, j = siz - 1; i < siz; i++, j-- ) tar[j] = src[i];
570 ::swab( src, buff, siz );
575 std::copy_n( src, siz, tar );
585 char* tar = (
char*)target;
593 for (
int i = 0, j = siz - 1; i < siz; i++, j-- ) tar[j] = src[i];
595 ::swab( src, tar, siz );
599 std::copy_n( src, siz, tar );
611 for (
const auto& i : v ) s << i;
621 for ( i = 0; i < len; i++ ) {
633 for (
const auto& i : l ) s << i;
643 for (
long i = 0; i < len; i++ ) {
StreamBuffer & operator>>(StreamBuffer &s, std::vector< T > &v)
StreamBuffer & operator<<(StreamBuffer &s, const std::vector< T > &v)
#define STREAM_ANALYSE(data, len)
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
A DataObject is the base class of any identifiable object on any data store.
Definition of the contained link set.
ContainedLink(ContainedObject *pObj, long hint, long link)
ContainedLink(const ContainedLink ©)=default
ContainedLink & operator=(const ContainedLink ©)=default
A small base class to handle generic data streaming.
void badStreamMode()
Throw Exception.
DataIO()=default
Standard constructor.
virtual ~DataIO()=default
Standard destructor.
virtual void dump(StreamBuffer &)
Template function to save stream data.
virtual void serialize(StreamBuffer &stream)
Serialization method: loads/dumps streambuffer content.
virtual void load(StreamBuffer &)
Template function to load stream data.
Definition of the contained link set.
IdentifiedLink & operator=(const IdentifiedLink ©)=default
IdentifiedLink(DataObject *pObj, long hint)
IdentifiedLink(const IdentifiedLink ©)=default
Istream(std::istream &str)
Constructor.
std::istream * m_stream
Reference to input stream.
void load(StreamBuffer &stream) override
Data load method.
virtual ~Ostream()=default
Standard Destructor.
Ostream(std::ostream &str)
Standard constructor: pass reference to stream object.
void dump(StreamBuffer &stream) override
Output dumper.
The stream buffer is a small object collecting object data.
char * data()
write access to data buffer
virtual ~StreamBuffer()
Standard destructor.
StreamBuffer(bool do_swap=true)
Standard constructor.
IdentifiedLinks & identifiedLinks()
Access to identified links.
StreamBuffer & operator<<(short data)
Output Streamer.
StreamBuffer & operator>>(char &data)
Input Streamer.
StreamBuffer & operator<<(char data)
Output Streamer.
void erase()
Reset the buffer.
long m_pointer
Current buffer pointer.
StreamBuffer & operator>>(char *data)
Streamer to read strings in (char*) format.
const ContainedLinks & containedLinks() const
CONST Access to contained links.
StreamBuffer & operator>>(std::string &data)
Streamer to read strings in (std::string) format.
void setAnalyzer(AnalyzeFunction fun=nullptr)
Enable user analysis function.
void getIdentifiedLink(DataObject *&pObject, long &hint)
std::vector< ContainedLink > ContainedLinks
StreamBuffer & operator<<(int data)
Output Streamer.
StreamBuffer & operator>>(float &data)
Input Streamer.
StreamBuffer & getObjectPointer(const ContainedObject *, TYPE *&refpObject)
Helper to distinguish between identified pointers and contained pointers.
bool m_swapEnabled
Flag indicating swapping.
long size() const
Total buffer size.
SwapAction
Data Sawp actions.
char * adopt() const
Remove the data buffer and pass it to client. It's the client responsability to free the memory.
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
StreamBuffer & operator>>(short &data)
Input Streamer.
StreamBuffer & operator>>(unsigned short &data)
Input Streamer.
void serialize(DataIO &ioObject)
Serialize the buffer using an IO object.
StreamBuffer & operator<<(const DataObject *pObject)
Streamer to write links to identified objects.
long buffPointer() const
Retrieve current buffer pointer.
StreamBuffer & operator<<(const std::string &data)
Streamer to write strings in (std::string) format.
const char * data() const
Read access to data buffer.
StreamBuffer & operator>>(long long &data)
Input Streamer.
void addIdentifiedLink(const DataObject *pObject, long hint)
void setMode(Mode m)
Set mode of the stream and allocate buffer.
StreamBuffer & operator<<(unsigned int data)
Output Streamer.
SwapAction swapBuffer(int siz) const
Check for byte swapping.
StreamBuffer & operator>>(long &data)
Input Streamer.
void extend(long len)
Extend the buffer.
std::vector< IdentifiedLink > IdentifiedLinks
Definition of the identifiable link set.
StreamBuffer & operator<<(const ContainedObject *pObject)
Streamer to write links to contained objects.
void(* AnalyzeFunction)(const void *data, int siz, const std::type_info &type)
Definition of the buffer analyzer.
bool isReading() const
Get stream buffer state.
StreamBuffer & operator>>(unsigned long &data)
Input Streamer.
StreamBuffer & getObjectPointer(const DataObject *, TYPE *&refpObject)
Helper to distinguish between identified pointers and contained pointers.
StreamBuffer & operator<<(unsigned char data)
Output Streamer.
StreamBuffer & operator>>(unsigned int &data)
Input Streamer.
AnalyzeFunction m_analyzer
Hook function for analysis of data to the stream.
StreamBuffer & operator>>(unsigned char &data)
Input Streamer.
void getContainedLink(ContainedObject *&pObject, long &hint, long &link)
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
void reserve(long len)
Reserve buffer space; Default: 16 k buffer size.
StreamBuffer & operator<<(double data)
Output Streamer.
const IdentifiedLinks & identifiedLinks() const
CONST Access to identified links.
void setBuffPointer(long ptr)
Retrieve current buffer pointer.
StreamBuffer & operator<<(const char *data)
Streamer to write strings in (char*) format.
StreamBuffer & writeBytes(const char *str, long len)
Write string to output stream.
StreamBuffer & operator>>(double &data)
Input Streamer.
State
Link state defintions.
bool isWriting() const
Get stream buffer state.
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
StreamBuffer & operator<<(long long data)
Output Streamer.
ContainedLinks m_containedLinks
Container with links to contained objects.
StreamBuffer & operator<<(long data)
Output Streamer.
ContainedLinks & containedLinks()
Access to contained links.
StreamBuffer & operator<<(unsigned short data)
Output Streamer.
char * m_buffer
Pointer to heap buffer.
StreamBuffer & operator<<(float data)
Output Streamer.
long m_length
Total buffer length.
void addContainedLink(const ContainedObject *pObject, long hint, long link)
StreamBuffer & operator>>(TYPE *&refpObject)
Streamer to read links to contained or identified objects.
StreamBuffer & operator>>(int &data)
Input Streamer.
StreamBuffer & operator<<(unsigned long data)
Output Streamer.
friend class DataObject
DataObject is friend.
Mode m_mode
Boolean indicating wether the stream is in read or write mode.