The Gaudi Framework  v30r3 (a5ef0a68)
StreamBuffer Class Reference

The stream buffer is a small object collecting object data. More...

#include <GaudiKernel/StreamBuffer.h>

Collaboration diagram for StreamBuffer:

Classes

class  ContainedLink
 Definition of the contained link set. More...
 
class  DataIO
 A small base class to handle generic data streaming. More...
 
class  IdentifiedLink
 Definition of the contained link set. More...
 
class  Istream
 Reader for standard input streams. More...
 
class  Ostream
 Writer for standard output streams. More...
 

Public Types

enum  Mode { UNINITIALIZED, READING, WRITING }
 Streamer mode. More...
 
enum  SwapAction { SINGLE_BYTE, SWAP, NOSWAP }
 Data Sawp actions. More...
 
enum  State { INVALID = -1, VALID }
 Link state defintions. More...
 
typedef std::vector< ContainedLinkContainedLinks
 
typedef std::vector< IdentifiedLinkIdentifiedLinks
 Definition of the identifiable link set. More...
 
typedef void(* AnalyzeFunction) (const void *data, int siz, const std::type_info &type)
 Definition of the buffer analyzer. More...
 

Public Member Functions

 StreamBuffer (bool do_swap=true)
 Standard constructor. More...
 
virtual ~StreamBuffer ()
 Standard destructor. More...
 
const char * data () const
 Read access to data buffer. More...
 
char * data ()
 write access to data buffer More...
 
void erase ()
 Reset the buffer. More...
 
char * adopt () const
 Remove the data buffer and pass it to client. It's the client responsability to free the memory. More...
 
void reserve (long len)
 Reserve buffer space; Default: 16 k buffer size. More...
 
void extend (long len)
 Extend the buffer. More...
 
long size () const
 Total buffer size. More...
 
ContainedLinkscontainedLinks ()
 Access to contained links. More...
 
const ContainedLinkscontainedLinks () const
 CONST Access to contained links. More...
 
IdentifiedLinksidentifiedLinks ()
 Access to identified links. More...
 
const IdentifiedLinksidentifiedLinks () const
 CONST Access to identified links. More...
 
void setMode (Mode m)
 Set mode of the stream and allocate buffer. More...
 
bool isReading () const
 Get stream buffer state. More...
 
bool isWriting () const
 Get stream buffer state. More...
 
long buffPointer () const
 Retrieve current buffer pointer. More...
 
void setBuffPointer (long ptr)
 Retrieve current buffer pointer. More...
 
void setAnalyzer (AnalyzeFunction fun=nullptr)
 Enable user analysis function. More...
 
void swapToBuffer (const void *source, int siz)
 Swap buffers: int, long, short, float and double. More...
 
void swapFromBuffer (void *target, int siz)
 Swap buffers: int, long, short, float and double. More...
 
StreamBufferwriteBytes (const char *str, long len)
 Write string to output stream. More...
 
void getIdentifiedLink (DataObject *&pObject, long &hint)
 
void addIdentifiedLink (const DataObject *pObject, long hint)
 
void getContainedLink (ContainedObject *&pObject, long &hint, long &link)
 
void addContainedLink (const ContainedObject *pObject, long hint, long link)
 
StreamBufferoperator<< (longlong data)
 Output Streamer. More...
 
StreamBufferoperator>> (longlong &data)
 Input Streamer. More...
 
StreamBufferoperator<< (int data)
 Output Streamer. More...
 
StreamBufferoperator>> (int &data)
 Input Streamer. More...
 
StreamBufferoperator<< (unsigned int data)
 Output Streamer. More...
 
StreamBufferoperator>> (unsigned int &data)
 Input Streamer. More...
 
StreamBufferoperator<< (long data)
 Output Streamer. More...
 
StreamBufferoperator>> (long &data)
 Input Streamer. More...
 
StreamBufferoperator<< (unsigned long data)
 Output Streamer. More...
 
StreamBufferoperator>> (unsigned long &data)
 Input Streamer. More...
 
StreamBufferoperator<< (short data)
 Output Streamer. More...
 
StreamBufferoperator>> (short &data)
 Input Streamer. More...
 
StreamBufferoperator<< (unsigned short data)
 Output Streamer. More...
 
StreamBufferoperator>> (unsigned short &data)
 Input Streamer. More...
 
StreamBufferoperator<< (char data)
 Output Streamer. More...
 
StreamBufferoperator>> (char &data)
 Input Streamer. More...
 
StreamBufferoperator<< (unsigned char data)
 Output Streamer. More...
 
StreamBufferoperator>> (unsigned char &data)
 Input Streamer. More...
 
StreamBufferoperator<< (float data)
 Output Streamer. More...
 
StreamBufferoperator>> (float &data)
 Input Streamer. More...
 
StreamBufferoperator<< (double data)
 Output Streamer. More...
 
StreamBufferoperator>> (double &data)
 Input Streamer. More...
 
StreamBufferoperator>> (char *data)
 Streamer to read strings in (char*) format. More...
 
StreamBufferoperator<< (const char *data)
 Streamer to write strings in (char*) format. More...
 
StreamBufferoperator>> (std::string &data)
 Streamer to read strings in (std::string) format. More...
 
StreamBufferoperator<< (const std::string &data)
 Streamer to write strings in (std::string) format. More...
 
template<class TYPE >
StreamBufferoperator>> (TYPE *&refpObject)
 Streamer to read links to contained or identified objects. More...
 
StreamBufferoperator<< (const ContainedObject *pObject)
 Streamer to write links to contained objects. More...
 
StreamBufferoperator<< (const DataObject *pObject)
 Streamer to write links to identified objects. More...
 
void serialize (DataIO &ioObject)
 Serialize the buffer using an IO object. More...
 

Protected Member Functions

SwapAction swapBuffer (int siz) const
 Check for byte swapping. More...
 
template<class TYPE >
StreamBuffergetObjectPointer (const DataObject *, TYPE *&refpObject)
 Helper to distinguish between identified pointers and contained pointers. More...
 
template<class TYPE >
StreamBuffergetObjectPointer (const ContainedObject *, TYPE *&refpObject)
 Helper to distinguish between identified pointers and contained pointers. More...
 

Protected Attributes

Mode m_mode = UNINITIALIZED
 Boolean indicating wether the stream is in read or write mode. More...
 
long m_pointer = 0
 Current buffer pointer. More...
 
long m_length = 0
 Total buffer length. More...
 
char * m_buffer = nullptr
 Pointer to heap buffer. More...
 
bool m_swapEnabled = true
 Flag indicating swapping. More...
 
ContainedLinks m_containedLinks
 Container with links to contained objects. More...
 
IdentifiedLinks m_identifiedLinks
 Container with links to contained objects. More...
 
AnalyzeFunction m_analyzer = nullptr
 Hook function for analysis of data to the stream. More...
 

Friends

class DataObject
 DataObject is friend. More...
 

Detailed Description

The stream buffer is a small object collecting object data.

The basic idea behind the StreamBuffer is generic object conversion. The StreamBuffer acts as a byte stream (hence inheriting from a std::string: DP: this is not true anymore and it is not a bad thing in my opinion) and stores any information streamed to the buffer. Since the information must be represented in a generic way on the fly byte swapping is performed. However, not only primitive data can be stored in the buffer, but also pointers to DataObjects (symbolic links) and pointers to contained objects. Automatically during serialization the persistent references to the corresponding objects and containers must be stored. These objects are accessible from the StreamBuffer object.

"On the fly" data conversion to non persistent

Author
M.Frank

Definition at line 41 of file StreamBuffer.h.

Member Typedef Documentation

typedef void( * StreamBuffer::AnalyzeFunction) (const void *data, int siz, const std::type_info &type)

Definition of the buffer analyzer.

Definition at line 144 of file StreamBuffer.h.

Definition of the identifiable link set.

Definition at line 142 of file StreamBuffer.h.

Member Enumeration Documentation

Streamer mode.

Enumerator
UNINITIALIZED 
READING 
WRITING 

Definition at line 113 of file StreamBuffer.h.

Link state defintions.

Enumerator
INVALID 
VALID 

Definition at line 117 of file StreamBuffer.h.

Data Sawp actions.

Enumerator
SINGLE_BYTE 
SWAP 
NOSWAP 

Definition at line 115 of file StreamBuffer.h.

Constructor & Destructor Documentation

StreamBuffer::StreamBuffer ( bool  do_swap = true)
inline

Standard constructor.

Definition at line 203 of file StreamBuffer.h.

203 : m_swapEnabled( do_swap ) {}
bool m_swapEnabled
Flag indicating swapping.
Definition: StreamBuffer.h:162
virtual StreamBuffer::~StreamBuffer ( )
inlinevirtual

Standard destructor.

Definition at line 205 of file StreamBuffer.h.

205 { ::free( m_buffer ); }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:159

Member Function Documentation

void StreamBuffer::addContainedLink ( const ContainedObject pObject,
long  hint,
long  link 
)
inline

Definition at line 310 of file StreamBuffer.h.

311  {
312  m_containedLinks.push_back( ContainedLink( (ContainedObject*)pObject, hint, link ) );
313  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:165
T push_back(T...args)
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
void StreamBuffer::addIdentifiedLink ( const DataObject pObject,
long  hint 
)
inline

Definition at line 297 of file StreamBuffer.h.

298  {
299  m_identifiedLinks.push_back( IdentifiedLink( (DataObject*)pObject, hint ) );
300  }
T push_back(T...args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:168
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
char* StreamBuffer::adopt ( ) const
inline

Remove the data buffer and pass it to client. It's the client responsability to free the memory.

Definition at line 213 of file StreamBuffer.h.

214  {
215  char* ptr = m_buffer;
218  m_buffer = NULL; // char *
219  m_pointer = 0; // long
220  m_length = 0; // long
221  return ptr;
222  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:165
long m_length
Total buffer length.
Definition: StreamBuffer.h:156
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:159
T end(T...args)
T erase(T...args)
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:153
T begin(T...args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:168
long StreamBuffer::buffPointer ( ) const
inline

Retrieve current buffer pointer.

Definition at line 269 of file StreamBuffer.h.

269 { return m_pointer; }
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:153
ContainedLinks& StreamBuffer::containedLinks ( )
inline

Access to contained links.

Definition at line 245 of file StreamBuffer.h.

245 { return m_containedLinks; }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:165
const ContainedLinks& StreamBuffer::containedLinks ( ) const
inline

CONST Access to contained links.

Definition at line 247 of file StreamBuffer.h.

247 { return m_containedLinks; }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:165
const char* StreamBuffer::data ( ) const
inline

Read access to data buffer.

Definition at line 207 of file StreamBuffer.h.

207 { return m_buffer; }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:159
char* StreamBuffer::data ( )
inline

write access to data buffer

Definition at line 209 of file StreamBuffer.h.

209 { return m_buffer; }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:159
void StreamBuffer::erase ( )
inline

Reset the buffer.

Definition at line 211 of file StreamBuffer.h.

211 { m_pointer = 0; }
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:153
void StreamBuffer::extend ( long  len)
inline

Extend the buffer.

Definition at line 232 of file StreamBuffer.h.

233  {
234  if ( len + m_pointer > m_length ) {
235  // We have to be a bit generous here in order not to run too often
236  // into ::realloc().
237  long new_len = ( m_length < 16384 ) ? 16384 : 2 * m_length;
238  if ( m_length < len ) new_len += len;
239  reserve( new_len );
240  }
241  }
long m_length
Total buffer length.
Definition: StreamBuffer.h:156
void reserve(long len)
Reserve buffer space; Default: 16 k buffer size.
Definition: StreamBuffer.h:224
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:153
void StreamBuffer::getContainedLink ( ContainedObject *&  pObject,
long &  hint,
long &  link 
)
inline

Definition at line 302 of file StreamBuffer.h.

303  {
304  ContainedLink& l = m_containedLinks.back();
305  pObject = l.first;
306  hint = l.second;
307  link = l.third;
309  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:165
T pop_back(T...args)
dictionary l
Definition: gaudirun.py:440
T back(T...args)
void StreamBuffer::getIdentifiedLink ( DataObject *&  pObject,
long &  hint 
)
inline

Definition at line 290 of file StreamBuffer.h.

291  {
292  IdentifiedLink& l = m_identifiedLinks.back();
293  pObject = l.first;
294  hint = l.second;
296  }
T pop_back(T...args)
dictionary l
Definition: gaudirun.py:440
T back(T...args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:168
template<class TYPE >
StreamBuffer& StreamBuffer::getObjectPointer ( const DataObject ,
TYPE *&  refpObject 
)
inlineprotected

Helper to distinguish between identified pointers and contained pointers.

This entry resolves identified pointers (= Pointers to DataObject instances.)

Definition at line 180 of file StreamBuffer.h.

181  {
182  IdentifiedLink& link = m_identifiedLinks.back();
183  DataObject* pObj = link.first;
185  refpObject = dynamic_cast<TYPE*>( pObj );
186  return *this;
187  }
T pop_back(T...args)
T back(T...args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:168
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
template<class TYPE >
StreamBuffer& StreamBuffer::getObjectPointer ( const ContainedObject ,
TYPE *&  refpObject 
)
inlineprotected

Helper to distinguish between identified pointers and contained pointers.

This entry resolves contained pointers (= Pointers to ContainedObject instances.)

Definition at line 192 of file StreamBuffer.h.

193  {
194  ContainedLink& link = m_containedLinks.back();
195  ContainedObject* pObj = link.first;
197  refpObject = dynamic_cast<TYPE*>( pObj );
198  return *this;
199  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:165
T pop_back(T...args)
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
T back(T...args)
IdentifiedLinks& StreamBuffer::identifiedLinks ( )
inline

Access to identified links.

Definition at line 250 of file StreamBuffer.h.

250 { return m_identifiedLinks; }
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:168
const IdentifiedLinks& StreamBuffer::identifiedLinks ( ) const
inline

CONST Access to identified links.

Definition at line 252 of file StreamBuffer.h.

252 { return m_identifiedLinks; }
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:168
bool StreamBuffer::isReading ( ) const
inline

Get stream buffer state.

Definition at line 264 of file StreamBuffer.h.

264 { return m_mode == READING; }
Mode m_mode
Boolean indicating wether the stream is in read or write mode.
Definition: StreamBuffer.h:150
bool StreamBuffer::isWriting ( ) const
inline

Get stream buffer state.

Definition at line 267 of file StreamBuffer.h.

267 { return m_mode == WRITING; }
Mode m_mode
Boolean indicating wether the stream is in read or write mode.
Definition: StreamBuffer.h:150
StreamBuffer& StreamBuffer::operator<< ( longlong  data)
inline

Output Streamer.

Definition at line 342 of file StreamBuffer.h.

343  {
344  swapToBuffer( &data, sizeof( data ) );
345  STREAM_ANALYSE( data, sizeof( data ) );
346  return *this;
347  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:611
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:319
StreamBuffer& StreamBuffer::operator<< ( int  data)
inline

Output Streamer.

Definition at line 355 of file StreamBuffer.h.

356  {
357  swapToBuffer( &data, sizeof( data ) );
358  STREAM_ANALYSE( data, sizeof( data ) );
359  return *this;
360  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:611
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:319
StreamBuffer& StreamBuffer::operator<< ( unsigned int  data)
inline

Output Streamer.

Definition at line 368 of file StreamBuffer.h.

369  {
370  swapToBuffer( &data, sizeof( data ) );
371  STREAM_ANALYSE( data, sizeof( data ) );
372  return *this;
373  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:611
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:319
StreamBuffer& StreamBuffer::operator<< ( long  data)
inline

Output Streamer.

Definition at line 381 of file StreamBuffer.h.

382  {
383  swapToBuffer( &data, sizeof( data ) );
384  STREAM_ANALYSE( data, sizeof( data ) );
385  return *this;
386  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:611
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:319
StreamBuffer& StreamBuffer::operator<< ( unsigned long  data)
inline

Output Streamer.

Definition at line 394 of file StreamBuffer.h.

395  {
396  swapToBuffer( &data, sizeof( data ) );
397  STREAM_ANALYSE( data, sizeof( data ) );
398  return *this;
399  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:611
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:319
StreamBuffer& StreamBuffer::operator<< ( short  data)
inline

Output Streamer.

Definition at line 407 of file StreamBuffer.h.

408  {
409  swapToBuffer( &data, sizeof( data ) );
410  STREAM_ANALYSE( data, sizeof( data ) );
411  return *this;
412  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:611
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:319
StreamBuffer& StreamBuffer::operator<< ( unsigned short  data)
inline

Output Streamer.

Definition at line 420 of file StreamBuffer.h.

421  {
422  swapToBuffer( &data, sizeof( data ) );
423  STREAM_ANALYSE( data, sizeof( data ) );
424  return *this;
425  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:611
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:319
StreamBuffer& StreamBuffer::operator<< ( char  data)
inline

Output Streamer.

Definition at line 433 of file StreamBuffer.h.

434  {
435  swapToBuffer( &data, sizeof( data ) );
436  STREAM_ANALYSE( data, sizeof( data ) );
437  return *this;
438  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:611
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:319
StreamBuffer& StreamBuffer::operator<< ( unsigned char  data)
inline

Output Streamer.

Definition at line 446 of file StreamBuffer.h.

447  {
448  swapToBuffer( &data, sizeof( data ) );
449  STREAM_ANALYSE( data, sizeof( data ) );
450  return *this;
451  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:611
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:319
StreamBuffer& StreamBuffer::operator<< ( float  data)
inline

Output Streamer.

Definition at line 459 of file StreamBuffer.h.

460  {
461  swapToBuffer( &data, sizeof( data ) );
462  STREAM_ANALYSE( data, sizeof( data ) );
463  return *this;
464  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:611
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:319
StreamBuffer& StreamBuffer::operator<< ( double  data)
inline

Output Streamer.

Definition at line 472 of file StreamBuffer.h.

473  {
474  swapToBuffer( &data, sizeof( data ) );
475  STREAM_ANALYSE( data, sizeof( data ) );
476  return *this;
477  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:611
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:319
StreamBuffer& StreamBuffer::operator<< ( const char *  data)
inline

Streamer to write strings in (char*) format.

Definition at line 495 of file StreamBuffer.h.

496  {
497  const char* ptr = 0 == data ? "" : data;
498  int len = strlen( ptr ) + 1;
499  if ( 0 == m_analyzer )
500  writeBytes( ptr, len );
501  else {
502  STREAM_ANALYSE( data, len );
503  }
504  return *this;
505  }
AnalyzeFunction m_analyzer
Hook function for analysis of data to the stream.
Definition: StreamBuffer.h:171
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:319
T strlen(T...args)
StreamBuffer & writeBytes(const char *str, long len)
Write string to output stream.
Definition: StreamBuffer.h:281
StreamBuffer& StreamBuffer::operator<< ( const std::string data)
inline

Streamer to write strings in (std::string) format.

Definition at line 517 of file StreamBuffer.h.

518  {
519  if ( 0 == m_analyzer ) {
520  const char* ptr = data.c_str();
521  long len = data.length();
522  writeBytes( ptr, len );
523  } else {
524  STREAM_ANALYSE( data, sizeof( data ) );
525  }
526  return *this;
527  }
AnalyzeFunction m_analyzer
Hook function for analysis of data to the stream.
Definition: StreamBuffer.h:171
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:319
T length(T...args)
T c_str(T...args)
StreamBuffer & writeBytes(const char *str, long len)
Write string to output stream.
Definition: StreamBuffer.h:281
StreamBuffer& StreamBuffer::operator<< ( const ContainedObject pObject)
inline

Streamer to write links to contained objects.

Links to contained objects are not stored immediately, but collected instead and analyzed later.

Parameters
pObjectPointer to object to be loaded.
Returns
Reference to StreamBuffer object

Definition at line 546 of file StreamBuffer.h.

547  {
548  STREAM_ANALYSE( pObject, sizeof( pObject ) );
549  addContainedLink( pObject, INVALID, INVALID );
550  return *this;
551  }
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:319
void addContainedLink(const ContainedObject *pObject, long hint, long link)
Definition: StreamBuffer.h:310
StreamBuffer& StreamBuffer::operator<< ( const DataObject pObject)
inline

Streamer to write links to identified objects.

Links to identified objects are not stored immediately, but collected instead and analyzed later.

Parameters
pObjectPointer to object to be loaded.
Returns
Reference to StreamBuffer object

Definition at line 559 of file StreamBuffer.h.

560  {
561  STREAM_ANALYSE( pObject, sizeof( pObject ) );
562  addIdentifiedLink( pObject, INVALID );
563  return *this;
564  }
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:319
void addIdentifiedLink(const DataObject *pObject, long hint)
Definition: StreamBuffer.h:297
StreamBuffer& StreamBuffer::operator>> ( longlong data)
inline

Input Streamer.

Definition at line 349 of file StreamBuffer.h.

350  {
351  swapFromBuffer( &data, sizeof( data ) );
352  return *this;
353  }
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:636
StreamBuffer& StreamBuffer::operator>> ( int &  data)
inline

Input Streamer.

Definition at line 362 of file StreamBuffer.h.

363  {
364  swapFromBuffer( &data, sizeof( data ) );
365  return *this;
366  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:636
StreamBuffer& StreamBuffer::operator>> ( unsigned int &  data)
inline

Input Streamer.

Definition at line 375 of file StreamBuffer.h.

376  {
377  swapFromBuffer( &data, sizeof( data ) );
378  return *this;
379  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:636
StreamBuffer& StreamBuffer::operator>> ( long &  data)
inline

Input Streamer.

Definition at line 388 of file StreamBuffer.h.

389  {
390  swapFromBuffer( &data, sizeof( data ) );
391  return *this;
392  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:636
StreamBuffer& StreamBuffer::operator>> ( unsigned long &  data)
inline

Input Streamer.

Definition at line 401 of file StreamBuffer.h.

402  {
403  swapFromBuffer( &data, sizeof( data ) );
404  return *this;
405  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:636
StreamBuffer& StreamBuffer::operator>> ( short &  data)
inline

Input Streamer.

Definition at line 414 of file StreamBuffer.h.

415  {
416  swapFromBuffer( &data, sizeof( data ) );
417  return *this;
418  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:636
StreamBuffer& StreamBuffer::operator>> ( unsigned short &  data)
inline

Input Streamer.

Definition at line 427 of file StreamBuffer.h.

428  {
429  swapFromBuffer( &data, sizeof( data ) );
430  return *this;
431  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:636
StreamBuffer& StreamBuffer::operator>> ( char &  data)
inline

Input Streamer.

Definition at line 440 of file StreamBuffer.h.

441  {
442  swapFromBuffer( &data, sizeof( data ) );
443  return *this;
444  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:636
StreamBuffer& StreamBuffer::operator>> ( unsigned char &  data)
inline

Input Streamer.

Definition at line 453 of file StreamBuffer.h.

454  {
455  swapFromBuffer( &data, sizeof( data ) );
456  return *this;
457  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:636
StreamBuffer& StreamBuffer::operator>> ( float &  data)
inline

Input Streamer.

Definition at line 466 of file StreamBuffer.h.

467  {
468  swapFromBuffer( &data, sizeof( data ) );
469  return *this;
470  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:636
StreamBuffer& StreamBuffer::operator>> ( double &  data)
inline

Input Streamer.

Definition at line 479 of file StreamBuffer.h.

480  {
481  swapFromBuffer( &data, sizeof( data ) );
482  return *this;
483  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:636
StreamBuffer& StreamBuffer::operator>> ( char *  data)
inline

Streamer to read strings in (char*) format.

Definition at line 485 of file StreamBuffer.h.

486  {
487  long i, len;
488  *this >> len;
489  for ( i = 0, data[0] = 0; i < len; i++ ) {
490  data[i] = m_buffer[m_pointer++];
491  }
492  return *this;
493  }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:159
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:153
StreamBuffer& StreamBuffer::operator>> ( std::string data)
inline

Streamer to read strings in (std::string) format.

Definition at line 507 of file StreamBuffer.h.

508  {
509  long i, len;
510  *this >> len;
511  for ( i = 0, data = ""; i < len; i++ ) {
512  data.append( 1, m_buffer[m_pointer++] );
513  }
514  return *this;
515  }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:159
T append(T...args)
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:153
template<class TYPE >
StreamBuffer& StreamBuffer::operator>> ( TYPE *&  refpObject)
inline

Streamer to read links to contained or identified objects.

The specified internal function call distinguishes between contained and identified objects.

Parameters
refpObjectReference to pointer to object to be loaded.
Returns
Reference to StreamBuffer object

Definition at line 535 of file StreamBuffer.h.

536  {
537  return getObjectPointer( refpObject, refpObject );
538  }
StreamBuffer & getObjectPointer(const DataObject *, TYPE *&refpObject)
Helper to distinguish between identified pointers and contained pointers.
Definition: StreamBuffer.h:180
void StreamBuffer::reserve ( long  len)
inline

Reserve buffer space; Default: 16 k buffer size.

Definition at line 224 of file StreamBuffer.h.

225  {
226  if ( len > m_length ) {
227  m_length = ( len < 16384 ) ? 16384 : len;
228  m_buffer = (char*)::realloc( m_buffer, m_length );
229  }
230  }
long m_length
Total buffer length.
Definition: StreamBuffer.h:156
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:159
T realloc(T...args)
void StreamBuffer::serialize ( DataIO ioObject)
inline

Serialize the buffer using an IO object.

The streambuffer object will make use of a DataIO object, which can be specialized for streaming to any representation like e.g. disk files, Root files, Objectivity etc.

Parameters
ioObjectReference to data IO object.

Definition at line 572 of file StreamBuffer.h.

573  {
574  ioObject.serialize( *this );
575  m_pointer = 0;
576  }
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:153
void StreamBuffer::setAnalyzer ( AnalyzeFunction  fun = nullptr)
inline

Enable user analysis function.

Definition at line 273 of file StreamBuffer.h.

273 { m_analyzer = fun; }
AnalyzeFunction m_analyzer
Hook function for analysis of data to the stream.
Definition: StreamBuffer.h:171
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
void StreamBuffer::setBuffPointer ( long  ptr)
inline

Retrieve current buffer pointer.

Definition at line 271 of file StreamBuffer.h.

271 { m_pointer = ptr; }
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:153
void StreamBuffer::setMode ( Mode  m)
inline

Set mode of the stream and allocate buffer.

Definition at line 255 of file StreamBuffer.h.

256  {
257  m_mode = m;
258  m_pointer = 0;
261  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:165
T end(T...args)
Mode m_mode
Boolean indicating wether the stream is in read or write mode.
Definition: StreamBuffer.h:150
constexpr double m
Definition: SystemOfUnits.h:94
T erase(T...args)
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:153
T begin(T...args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:168
long StreamBuffer::size ( ) const
inline

Total buffer size.

Definition at line 243 of file StreamBuffer.h.

243 { return m_length; }
long m_length
Total buffer length.
Definition: StreamBuffer.h:156
StreamBuffer::SwapAction StreamBuffer::swapBuffer ( int  siz) const
inlineprotected

Check for byte swapping.

Definition at line 582 of file StreamBuffer.h.

583 {
584  switch ( siz ) {
585  case 1:
586  return SINGLE_BYTE;
587  default:
588 #if defined( __alpha ) && !defined( __VMS )
589  // return m_swapEnabled ? SWAP : NOSWAP;
590  return NOSWAP;
591 #elif defined( __sun ) && defined( __SVR4 ) && defined( __i386 )
592  // return m_swapEnabled ? SWAP : NOSWAP;
593  return NOSWAP;
594 #elif defined( __APPLE__ )
595  // return m_swapEnabled ? SWAP : NOSWAP;
596  return SWAP;
597 #elif defined( __linux ) && !defined( __powerpc )
598  // return m_swapEnabled ? SWAP : NOSWAP;
599  return NOSWAP;
600 #elif defined( BORLAND ) || defined( _WIN32 ) || defined( WIN32 )
601  // return m_swapEnabled ? SWAP : NOSWAP;
602  return NOSWAP;
603 #else
604  return m_swapEnabled ? SWAP : NOSWAP;
605 // return NOSWAP;
606 #endif
607  }
608 }
bool m_swapEnabled
Flag indicating swapping.
Definition: StreamBuffer.h:162
void StreamBuffer::swapFromBuffer ( void *  target,
int  siz 
)
inline

Swap buffers: int, long, short, float and double.

Swap bytes from the stream buffer to target buffer with arbitray size.

Definition at line 636 of file StreamBuffer.h.

637 {
638  char* tar = (char*)target;
639  char* src = (char*)m_buffer + m_pointer;
640  switch ( swapBuffer( siz ) ) {
641  case SINGLE_BYTE:
642  *tar = *src;
643  break;
644  case SWAP:
645 #ifdef __APPLE__
646  for ( int i = 0, j = siz - 1; i < siz; i++, j-- ) tar[j] = src[i];
647 #else
648  ::_swab( src, tar, siz );
649 #endif
650  break;
651  case NOSWAP:
652  std::copy_n( src, siz, tar );
653  break;
654  }
655  m_pointer += siz;
656 }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:159
T copy_n(T...args)
#define _swab(source, target, radix)
Definition: swab.h:7
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:153
SwapAction swapBuffer(int siz) const
Check for byte swapping.
Definition: StreamBuffer.h:582
void StreamBuffer::swapToBuffer ( const void *  source,
int  siz 
)
inline

Swap buffers: int, long, short, float and double.

Swap bytes from a source buffer to the stream buffer with arbitray size.

Definition at line 611 of file StreamBuffer.h.

612 {
613  char buff[8], *tar, *src = (char *)source;
614  extend( m_pointer + siz );
615  tar = (char*)m_buffer + m_pointer;
616  switch ( swapBuffer( siz ) ) {
617  case SINGLE_BYTE:
618  *tar = *src;
619  break;
620  case SWAP:
621 #ifdef __APPLE__
622  for ( int i = 0, j = siz - 1; i < siz; i++, j-- ) tar[j] = src[i];
623 #else
624  ::_swab( src, buff, siz );
625 #endif
626  src = buff;
627  /* FALLTHROUGH */
628  case NOSWAP:
629  std::copy_n( src, siz, tar );
630  break;
631  }
632  m_pointer += siz;
633 }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:159
void extend(long len)
Extend the buffer.
Definition: StreamBuffer.h:232
T copy_n(T...args)
#define _swab(source, target, radix)
Definition: swab.h:7
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:153
SwapAction swapBuffer(int siz) const
Check for byte swapping.
Definition: StreamBuffer.h:582
StreamBuffer& StreamBuffer::writeBytes ( const char *  str,
long  len 
)
inline

Write string to output stream.

Definition at line 281 of file StreamBuffer.h.

282  {
283  extend( m_pointer + len + 4 );
284  *this << len;
285  std::copy_n( str, len, data() + buffPointer() );
286  m_pointer += len;
287  return *this;
288  }
long buffPointer() const
Retrieve current buffer pointer.
Definition: StreamBuffer.h:269
void extend(long len)
Extend the buffer.
Definition: StreamBuffer.h:232
T copy_n(T...args)
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:153

Friends And Related Function Documentation

friend class DataObject
friend

DataObject is friend.

Definition at line 146 of file StreamBuffer.h.

Member Data Documentation

AnalyzeFunction StreamBuffer::m_analyzer = nullptr
protected

Hook function for analysis of data to the stream.

Definition at line 171 of file StreamBuffer.h.

char* StreamBuffer::m_buffer = nullptr
mutableprotected

Pointer to heap buffer.

Definition at line 159 of file StreamBuffer.h.

ContainedLinks StreamBuffer::m_containedLinks
mutableprotected

Container with links to contained objects.

Definition at line 165 of file StreamBuffer.h.

IdentifiedLinks StreamBuffer::m_identifiedLinks
mutableprotected

Container with links to contained objects.

Definition at line 168 of file StreamBuffer.h.

long StreamBuffer::m_length = 0
mutableprotected

Total buffer length.

Definition at line 156 of file StreamBuffer.h.

Mode StreamBuffer::m_mode = UNINITIALIZED
protected

Boolean indicating wether the stream is in read or write mode.

Definition at line 150 of file StreamBuffer.h.

long StreamBuffer::m_pointer = 0
mutableprotected

Current buffer pointer.

Definition at line 153 of file StreamBuffer.h.

bool StreamBuffer::m_swapEnabled = true
protected

Flag indicating swapping.

Definition at line 162 of file StreamBuffer.h.


The documentation for this class was generated from the following file: