The Gaudi Framework  v29r0 (ff2e7097)
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 146 of file StreamBuffer.h.

Definition of the identifiable link set.

Definition at line 144 of file StreamBuffer.h.

Member Enumeration Documentation

Streamer mode.

Enumerator
UNINITIALIZED 
READING 
WRITING 

Definition at line 115 of file StreamBuffer.h.

Link state defintions.

Enumerator
INVALID 
VALID 

Definition at line 119 of file StreamBuffer.h.

Data Sawp actions.

Enumerator
SINGLE_BYTE 
SWAP 
NOSWAP 

Definition at line 117 of file StreamBuffer.h.

Constructor & Destructor Documentation

StreamBuffer::StreamBuffer ( bool  do_swap = true)
inline

Standard constructor.

Definition at line 205 of file StreamBuffer.h.

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

Standard destructor.

Definition at line 207 of file StreamBuffer.h.

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

Member Function Documentation

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

Definition at line 312 of file StreamBuffer.h.

313  {
314  m_containedLinks.push_back( ContainedLink( (ContainedObject*)pObject, hint, link ) );
315  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:167
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 299 of file StreamBuffer.h.

300  {
301  m_identifiedLinks.push_back( IdentifiedLink( (DataObject*)pObject, hint ) );
302  }
T push_back(T...args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:170
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:29
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 215 of file StreamBuffer.h.

216  {
217  char* ptr = m_buffer;
220  m_buffer = NULL; // char *
221  m_pointer = 0; // long
222  m_length = 0; // long
223  return ptr;
224  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:167
long m_length
Total buffer length.
Definition: StreamBuffer.h:158
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:161
T end(T...args)
T erase(T...args)
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:155
T begin(T...args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:170
long StreamBuffer::buffPointer ( ) const
inline

Retrieve current buffer pointer.

Definition at line 271 of file StreamBuffer.h.

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

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:167
const ContainedLinks& StreamBuffer::containedLinks ( ) const
inline

CONST Access to contained links.

Definition at line 249 of file StreamBuffer.h.

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

Read 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:161
char* StreamBuffer::data ( )
inline

write access to data buffer

Definition at line 211 of file StreamBuffer.h.

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

Reset the buffer.

Definition at line 213 of file StreamBuffer.h.

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

Extend the buffer.

Definition at line 234 of file StreamBuffer.h.

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

Definition at line 304 of file StreamBuffer.h.

305  {
306  ContainedLink& l = m_containedLinks.back();
307  pObject = l.first;
308  hint = l.second;
309  link = l.third;
311  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:167
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 292 of file StreamBuffer.h.

293  {
294  IdentifiedLink& l = m_identifiedLinks.back();
295  pObject = l.first;
296  hint = l.second;
298  }
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:170
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 182 of file StreamBuffer.h.

183  {
184  IdentifiedLink& link = m_identifiedLinks.back();
185  DataObject* pObj = link.first;
187  refpObject = dynamic_cast<TYPE*>( pObj );
188  return *this;
189  }
T pop_back(T...args)
T back(T...args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:170
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:29
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 194 of file StreamBuffer.h.

195  {
196  ContainedLink& link = m_containedLinks.back();
197  ContainedObject* pObj = link.first;
199  refpObject = dynamic_cast<TYPE*>( pObj );
200  return *this;
201  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:167
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 252 of file StreamBuffer.h.

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

CONST Access to identified links.

Definition at line 254 of file StreamBuffer.h.

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

Get stream buffer state.

Definition at line 266 of file StreamBuffer.h.

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

Get stream buffer state.

Definition at line 269 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 344 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 357 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 370 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 383 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 396 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 409 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 422 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 435 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 448 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 461 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 474 of file StreamBuffer.h.

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

Streamer to write strings in (char*) format.

Definition at line 497 of file StreamBuffer.h.

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

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

Definition at line 519 of file StreamBuffer.h.

520  {
521  if ( 0 == m_analyzer ) {
522  const char* ptr = data.c_str();
523  long len = data.length();
524  writeBytes( ptr, len );
525  } else {
526  STREAM_ANALYSE( data, sizeof( data ) );
527  }
528  return *this;
529  }
AnalyzeFunction m_analyzer
Hook function for analysis of data to the stream.
Definition: StreamBuffer.h:173
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:321
T length(T...args)
T c_str(T...args)
StreamBuffer & writeBytes(const char *str, long len)
Write string to output stream.
Definition: StreamBuffer.h:283
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 548 of file StreamBuffer.h.

549  {
550  STREAM_ANALYSE( pObject, sizeof( pObject ) );
551  addContainedLink( pObject, INVALID, INVALID );
552  return *this;
553  }
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:321
void addContainedLink(const ContainedObject *pObject, long hint, long link)
Definition: StreamBuffer.h:312
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 561 of file StreamBuffer.h.

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

Input Streamer.

Definition at line 351 of file StreamBuffer.h.

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

Input Streamer.

Definition at line 364 of file StreamBuffer.h.

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

Input Streamer.

Definition at line 377 of file StreamBuffer.h.

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

Input Streamer.

Definition at line 390 of file StreamBuffer.h.

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

Input Streamer.

Definition at line 403 of file StreamBuffer.h.

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

Input Streamer.

Definition at line 416 of file StreamBuffer.h.

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

Input Streamer.

Definition at line 429 of file StreamBuffer.h.

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

Input Streamer.

Definition at line 442 of file StreamBuffer.h.

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

Input Streamer.

Definition at line 455 of file StreamBuffer.h.

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

Input Streamer.

Definition at line 468 of file StreamBuffer.h.

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

Input Streamer.

Definition at line 481 of file StreamBuffer.h.

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

Streamer to read strings in (char*) format.

Definition at line 487 of file StreamBuffer.h.

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

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

Definition at line 509 of file StreamBuffer.h.

510  {
511  long i, len;
512  *this >> len;
513  for ( i = 0, data = ""; i < len; i++ ) {
514  data.append( 1, m_buffer[m_pointer++] );
515  }
516  return *this;
517  }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:161
T append(T...args)
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:155
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 537 of file StreamBuffer.h.

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

Reserve buffer space; Default: 16 k buffer size.

Definition at line 226 of file StreamBuffer.h.

227  {
228  if ( len > m_length ) {
229  m_length = ( len < 16384 ) ? 16384 : len;
230  m_buffer = (char*)::realloc( m_buffer, m_length );
231  }
232  }
long m_length
Total buffer length.
Definition: StreamBuffer.h:158
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:161
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 574 of file StreamBuffer.h.

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

Enable user analysis function.

Definition at line 275 of file StreamBuffer.h.

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

Retrieve current buffer pointer.

Definition at line 273 of file StreamBuffer.h.

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

Set mode of the stream and allocate buffer.

Definition at line 257 of file StreamBuffer.h.

258  {
259  m_mode = m;
260  m_pointer = 0;
263  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:167
T end(T...args)
Mode m_mode
Boolean indicating wether the stream is in read or write mode.
Definition: StreamBuffer.h:152
constexpr double m
Definition: SystemOfUnits.h:94
T erase(T...args)
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:155
T begin(T...args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:170
long StreamBuffer::size ( ) const
inline

Total buffer size.

Definition at line 245 of file StreamBuffer.h.

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

Check for byte swapping.

Definition at line 584 of file StreamBuffer.h.

585 {
586  switch ( siz ) {
587  case 1:
588  return SINGLE_BYTE;
589  default:
590 #if defined( __alpha ) && !defined( __VMS )
591  // return m_swapEnabled ? SWAP : NOSWAP;
592  return NOSWAP;
593 #elif defined( __sun ) && defined( __SVR4 ) && defined( __i386 )
594  // return m_swapEnabled ? SWAP : NOSWAP;
595  return NOSWAP;
596 #elif defined( __APPLE__ )
597  // return m_swapEnabled ? SWAP : NOSWAP;
598  return SWAP;
599 #elif defined( __linux ) && !defined( __powerpc )
600  // return m_swapEnabled ? SWAP : NOSWAP;
601  return NOSWAP;
602 #elif defined( BORLAND ) || defined( _WIN32 ) || defined( WIN32 )
603  // return m_swapEnabled ? SWAP : NOSWAP;
604  return NOSWAP;
605 #else
606  return m_swapEnabled ? SWAP : NOSWAP;
607 // return NOSWAP;
608 #endif
609  }
610 }
bool m_swapEnabled
Flag indicating swapping.
Definition: StreamBuffer.h:164
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 638 of file StreamBuffer.h.

639 {
640  char* tar = (char*)target;
641  char* src = (char*)m_buffer + m_pointer;
642  switch ( swapBuffer( siz ) ) {
643  case SINGLE_BYTE:
644  *tar = *src;
645  break;
646  case SWAP:
647 #ifdef __APPLE__
648  for ( int i = 0, j = siz - 1; i < siz; i++, j-- ) tar[j] = src[i];
649 #else
650  ::_swab( src, tar, siz );
651 #endif
652  break;
653  case NOSWAP:
654  std::copy_n( src, siz, tar );
655  break;
656  }
657  m_pointer += siz;
658 }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:161
T copy_n(T...args)
#define _swab(source, target, radix)
Definition: swab.h:7
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:155
SwapAction swapBuffer(int siz) const
Check for byte swapping.
Definition: StreamBuffer.h:584
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 613 of file StreamBuffer.h.

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

Write string to output stream.

Definition at line 283 of file StreamBuffer.h.

284  {
285  extend( m_pointer + len + 4 );
286  *this << len;
287  std::copy_n( str, len, data() + buffPointer() );
288  m_pointer += len;
289  return *this;
290  }
long buffPointer() const
Retrieve current buffer pointer.
Definition: StreamBuffer.h:271
void extend(long len)
Extend the buffer.
Definition: StreamBuffer.h:234
T copy_n(T...args)
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:209
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:155

Friends And Related Function Documentation

friend class DataObject
friend

DataObject is friend.

Definition at line 148 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 173 of file StreamBuffer.h.

char* StreamBuffer::m_buffer = nullptr
mutableprotected

Pointer to heap buffer.

Definition at line 161 of file StreamBuffer.h.

ContainedLinks StreamBuffer::m_containedLinks
mutableprotected

Container with links to contained objects.

Definition at line 167 of file StreamBuffer.h.

IdentifiedLinks StreamBuffer::m_identifiedLinks
mutableprotected

Container with links to contained objects.

Definition at line 170 of file StreamBuffer.h.

long StreamBuffer::m_length = 0
mutableprotected

Total buffer length.

Definition at line 158 of file StreamBuffer.h.

Mode StreamBuffer::m_mode = UNINITIALIZED
protected

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

Definition at line 152 of file StreamBuffer.h.

long StreamBuffer::m_pointer = 0
mutableprotected

Current buffer pointer.

Definition at line 155 of file StreamBuffer.h.

bool StreamBuffer::m_swapEnabled = true
protected

Flag indicating swapping.

Definition at line 164 of file StreamBuffer.h.


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