1 #ifndef GAUDIKERNEL_STREAMBUFFER_H 2 #define GAUDIKERNEL_STREAMBUFFER_H 1 88 m_stream->
read( stream.
data(), len );
179 template <
class TYPE>
185 refpObject =
dynamic_cast<TYPE*
>( pObj );
191 template <
class TYPE>
197 refpObject =
dynamic_cast<TYPE*
>( pObj );
216 m_containedLinks.
erase( m_containedLinks.
begin(), m_containedLinks.
end() );
217 m_identifiedLinks.
erase( m_identifiedLinks.
begin(), m_identifiedLinks.
end() );
226 if ( len > m_length ) {
227 m_length = ( len < 16384 ) ? 16384 : len;
228 m_buffer = (
char*)::realloc( m_buffer, m_length );
234 if ( len + m_pointer > m_length ) {
237 long new_len = ( m_length < 16384 ) ? 16384 : 2 * m_length;
238 if ( m_length < len ) new_len += len;
259 m_containedLinks.
erase( m_containedLinks.
begin(), m_containedLinks.
end() );
260 m_identifiedLinks.
erase( m_identifiedLinks.
begin(), m_identifiedLinks.
end() );
283 extend( m_pointer + len + 4 );
315 #ifdef USE_STREAM_ANALYSER 316 #define STREAM_ANALYSE( data, len ) \ 317 if ( 0 != m_analyzer ) m_analyzer( &data, len, typeid( data ) ) 319 #define STREAM_ANALYSE( data, len ) 323 #define IMPLEMENT_STREAMER( TYPE ) \ 325 StreamBuffer& operator<<( TYPE data ) \ 327 swapToBuffer( &data, sizeof( data ) ); \ 328 STREAM_ANALYSE( data, sizeof( data ) ); \ 332 StreamBuffer& operator>>( TYPE& data ) \ 334 swapFromBuffer( &data, sizeof( data ) ); \ 339 #undef IMPLEMENT_STREAMER 489 for ( i = 0, data[0] = 0; i < len; i++ ) {
490 data[i] = m_buffer[m_pointer++];
497 const char* ptr = 0 == data ?
"" :
data;
498 int len = strlen( ptr ) + 1;
499 if ( 0 == m_analyzer )
511 for ( i = 0, data =
""; i < len; i++ ) {
512 data.
append( 1, m_buffer[m_pointer++] );
519 if ( 0 == m_analyzer ) {
520 const char* ptr = data.
c_str();
534 template <
class TYPE>
579 #undef STREAM_ANALYSE 588 #if defined( __alpha ) && !defined( __VMS ) 591 #elif defined( __sun ) && defined( __SVR4 ) && defined( __i386 ) 594 #elif defined( __APPLE__ ) 597 #elif defined( __linux ) && !defined( __powerpc ) 600 #elif defined( BORLAND ) || defined( _WIN32 ) || defined( WIN32 ) 613 char buff[8], *tar, *src = (
char *)source;
622 for (
int i = 0, j = siz - 1; i < siz; i++, j-- ) tar[j] = src[i];
638 char* tar = (
char*)target;
646 for (
int i = 0, j = siz - 1; i < siz; i++, j-- ) tar[j] = src[i];
660 inline StreamBuffer& operator<<( StreamBuffer& s, const std::vector<T>& v )
663 for (
const auto& i : v )
s << i;
674 for ( i = 0; i < len; i++ ) {
687 for (
const auto& i :
l )
s << i;
698 for (
long i = 0; i < len; i++ ) {
705 #endif // GAUDIKERNEL_STREAMBUFFER_H virtual void load(StreamBuffer &)
Template function to load stream data.
Definition of the contained link set.
Writer for standard output streams.
StreamBuffer(bool do_swap=true)
Standard constructor.
virtual void serialize(StreamBuffer &stream)
Serialization method: loads/dumps streambuffer content.
StreamBuffer & operator<<(const char *data)
Streamer to write strings in (char*) format.
long buffPointer() const
Retrieve current buffer pointer.
StreamBuffer & operator>>(long &data)
Input Streamer.
StreamBuffer & operator>>(unsigned short &data)
Input Streamer.
Ostream(std::ostream &str)
Standard constructor: pass reference to stream object.
StreamBuffer & operator<<(double data)
Output Streamer.
std::istream * m_stream
Reference to input stream.
DataIO()=default
Standard constructor.
StreamBuffer & operator<<(float data)
Output Streamer.
StreamBuffer & operator<<(const DataObject *pObject)
Streamer to write links to identified objects.
The stream buffer is a small object collecting object data.
StreamBuffer & operator>>(float &data)
Input Streamer.
SwapAction
Data Sawp actions.
ContainedLinks m_containedLinks
Container with links to contained objects.
ContainedLink(const ContainedLink ©)
Istream(std::istream &str)
Constructor.
AnalyzeFunction m_analyzer
Hook function for analysis of data to the stream.
virtual void dump(StreamBuffer &)
Template function to save stream data.
long m_length
Total buffer length.
IdentifiedLinks & identifiedLinks()
Access to identified links.
char * m_buffer
Pointer to heap buffer.
class MergingTransformer< Out(const vector_of_const_< In > void
void extend(long len)
Extend the buffer.
StreamBuffer & operator<<(const ContainedObject *pObject)
Streamer to write links to contained objects.
StreamBuffer & operator>>(char *data)
Streamer to read strings in (char*) format.
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
bool isReading() const
Get stream buffer state.
std::vector< ContainedLink > ContainedLinks
StreamBuffer & operator<<(unsigned long data)
Output Streamer.
StreamBuffer & operator<<(unsigned short data)
Output Streamer.
Reader for standard input streams.
const char * data() const
Read access to data buffer.
void setAnalyzer(AnalyzeFunction fun=nullptr)
Enable user analysis function.
char * data()
write access to data buffer
void setBuffPointer(long ptr)
Retrieve current buffer pointer.
StreamBuffer & operator>>(unsigned char &data)
Input Streamer.
StreamBuffer & operator<<(int data)
Output Streamer.
StreamBuffer & operator>>(longlong &data)
Input Streamer.
void(* AnalyzeFunction)(const void *data, int siz, const std::type_info &type)
Definition of the buffer analyzer.
void reserve(long len)
Reserve buffer space; Default: 16 k buffer size.
Mode m_mode
Boolean indicating wether the stream is in read or write mode.
#define STREAM_ANALYSE(data, len)
const IdentifiedLinks & identifiedLinks() const
CONST Access to identified links.
ContainedLinks & containedLinks()
Access to contained links.
StreamBuffer & operator<<(long data)
Output Streamer.
StreamBuffer & operator<<(unsigned char data)
Output Streamer.
StreamBuffer & operator<<(longlong data)
Output Streamer.
StreamBuffer & operator<<(short data)
Output Streamer.
StreamBuffer & getObjectPointer(const ContainedObject *, TYPE *&refpObject)
Helper to distinguish between identified pointers and contained pointers.
ContainedLink(ContainedObject *pObj, long hint, long link)
StreamBuffer & operator<<(const std::string &data)
Streamer to write strings in (std::string) format.
void badStreamMode()
Throw Exception.
void load(StreamBuffer &stream) override
Data load method.
StreamBuffer & operator>>(char &data)
Input Streamer.
StreamBuffer & operator>>(unsigned long &data)
Input Streamer.
#define _swab(source, target, radix)
void addIdentifiedLink(const DataObject *pObject, long hint)
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
virtual ~DataIO()=default
Standard destructor.
void dump(StreamBuffer &stream) override
Output dumper.
bool isWriting() const
Get stream buffer state.
long m_pointer
Current buffer pointer.
A small base class to handle generic data streaming.
double fun(const std::vector< double > &x)
State
Link state defintions.
StreamBuffer & writeBytes(const char *str, long len)
Write string to output stream.
virtual ~StreamBuffer()
Standard destructor.
void erase()
Reset the buffer.
StreamBuffer & operator<<(unsigned int data)
Output Streamer.
StreamBuffer & operator>>(std::string &data)
Streamer to read strings in (std::string) format.
Definition of the contained link set.
StreamBuffer & operator<<(char data)
Output Streamer.
void setMode(Mode m)
Set mode of the stream and allocate buffer.
char * adopt() const
Remove the data buffer and pass it to client. It's the client responsability to free the memory...
StreamBuffer & getObjectPointer(const DataObject *, TYPE *&refpObject)
Helper to distinguish between identified pointers and contained pointers.
StreamBuffer & operator>>(unsigned int &data)
Input Streamer.
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
A DataObject is the base class of any identifiable object on any data store.
SwapAction swapBuffer(int siz) const
Check for byte swapping.
StreamBuffer & operator>>(double &data)
Input Streamer.
void addContainedLink(const ContainedObject *pObject, long hint, long link)
void getContainedLink(ContainedObject *&pObject, long &hint, long &link)
long size() const
Total buffer size.
StreamBuffer & operator>>(int &data)
Input Streamer.
std::vector< IdentifiedLink > IdentifiedLinks
Definition of the identifiable link set.
void serialize(DataIO &ioObject)
Serialize the buffer using an IO object.
const ContainedLinks & containedLinks() const
CONST Access to contained links.
bool m_swapEnabled
Flag indicating swapping.
StreamBuffer & operator>>(short &data)
Input Streamer.
void getIdentifiedLink(DataObject *&pObject, long &hint)
StreamBuffer & operator>>(TYPE *&refpObject)
Streamer to read links to contained or identified objects.
IdentifiedLink(DataObject *pObj, long hint)
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.