The Gaudi Framework  master (37c0b60a)
StreamBuffer Class Reference

#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<< (long long data)
 Output Streamer. More...
 
StreamBufferoperator>> (long long &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 51 of file StreamBuffer.h.

Member Typedef Documentation

◆ AnalyzeFunction

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

Definition of the buffer analyzer.

Definition at line 148 of file StreamBuffer.h.

◆ ContainedLinks

◆ IdentifiedLinks

Definition of the identifiable link set.

Definition at line 146 of file StreamBuffer.h.

Member Enumeration Documentation

◆ Mode

Streamer mode.

Enumerator
UNINITIALIZED 
READING 
WRITING 

Definition at line 117 of file StreamBuffer.h.

◆ State

Link state defintions.

Enumerator
INVALID 
VALID 

Definition at line 121 of file StreamBuffer.h.

121 { INVALID = -1, VALID };

◆ SwapAction

Data Sawp actions.

Enumerator
SINGLE_BYTE 
SWAP 
NOSWAP 

Definition at line 119 of file StreamBuffer.h.

119 { SINGLE_BYTE, SWAP, NOSWAP };

Constructor & Destructor Documentation

◆ StreamBuffer()

StreamBuffer::StreamBuffer ( bool  do_swap = true)
inline

Standard constructor.

Definition at line 205 of file StreamBuffer.h.

205 : m_swapEnabled( do_swap ) {}

◆ ~StreamBuffer()

virtual StreamBuffer::~StreamBuffer ( )
inlinevirtual

Standard destructor.

Definition at line 207 of file StreamBuffer.h.

207 { ::free( m_buffer ); }

Member Function Documentation

◆ addContainedLink()

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

Definition at line 304 of file StreamBuffer.h.

304  {
305  m_containedLinks.push_back( ContainedLink( (ContainedObject*)pObject, hint, link ) );
306  }

◆ addIdentifiedLink()

void StreamBuffer::addIdentifiedLink ( const DataObject pObject,
long  hint 
)
inline

Definition at line 293 of file StreamBuffer.h.

293  {
294  m_identifiedLinks.push_back( IdentifiedLink( (DataObject*)pObject, hint ) );
295  }

◆ adopt()

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.

215  {
216  char* ptr = m_buffer;
219  m_buffer = NULL; // char *
220  m_pointer = 0; // long
221  m_length = 0; // long
222  return ptr;
223  }

◆ buffPointer()

long StreamBuffer::buffPointer ( ) const
inline

Retrieve current buffer pointer.

Definition at line 267 of file StreamBuffer.h.

267 { return m_pointer; }

◆ containedLinks() [1/2]

ContainedLinks& StreamBuffer::containedLinks ( )
inline

Access to contained links.

Definition at line 244 of file StreamBuffer.h.

244 { return m_containedLinks; }

◆ containedLinks() [2/2]

const ContainedLinks& StreamBuffer::containedLinks ( ) const
inline

CONST Access to contained links.

Definition at line 246 of file StreamBuffer.h.

246 { return m_containedLinks; }

◆ data() [1/2]

char* StreamBuffer::data ( )
inline

write access to data buffer

Definition at line 211 of file StreamBuffer.h.

211 { return m_buffer; }

◆ data() [2/2]

const char* StreamBuffer::data ( ) const
inline

Read access to data buffer.

Definition at line 209 of file StreamBuffer.h.

209 { return m_buffer; }

◆ erase()

void StreamBuffer::erase ( )
inline

Reset the buffer.

Definition at line 213 of file StreamBuffer.h.

213 { m_pointer = 0; }

◆ extend()

void StreamBuffer::extend ( long  len)
inline

Extend the buffer.

Definition at line 232 of file StreamBuffer.h.

232  {
233  if ( len + m_pointer > m_length ) {
234  // We have to be a bit generous here in order not to run too often
235  // into ::realloc().
236  long new_len = ( m_length < 16384 ) ? 16384 : 2 * m_length;
237  if ( m_length < len ) new_len += len;
238  reserve( new_len );
239  }
240  }

◆ getContainedLink()

void StreamBuffer::getContainedLink ( ContainedObject *&  pObject,
long &  hint,
long &  link 
)
inline

Definition at line 297 of file StreamBuffer.h.

297  {
298  ContainedLink& l = m_containedLinks.back();
299  pObject = l.first;
300  hint = l.second;
301  link = l.third;
303  }

◆ getIdentifiedLink()

void StreamBuffer::getIdentifiedLink ( DataObject *&  pObject,
long &  hint 
)
inline

Definition at line 287 of file StreamBuffer.h.

287  {
288  IdentifiedLink& l = m_identifiedLinks.back();
289  pObject = l.first;
290  hint = l.second;
292  }

◆ getObjectPointer() [1/2]

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 195 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  }

◆ getObjectPointer() [2/2]

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 184 of file StreamBuffer.h.

184  {
185  IdentifiedLink& link = m_identifiedLinks.back();
186  DataObject* pObj = link.first;
188  refpObject = dynamic_cast<TYPE*>( pObj );
189  return *this;
190  }

◆ identifiedLinks() [1/2]

IdentifiedLinks& StreamBuffer::identifiedLinks ( )
inline

Access to identified links.

Definition at line 249 of file StreamBuffer.h.

249 { return m_identifiedLinks; }

◆ identifiedLinks() [2/2]

const IdentifiedLinks& StreamBuffer::identifiedLinks ( ) const
inline

CONST Access to identified links.

Definition at line 251 of file StreamBuffer.h.

251 { return m_identifiedLinks; }

◆ isReading()

bool StreamBuffer::isReading ( ) const
inline

Get stream buffer state.

Definition at line 262 of file StreamBuffer.h.

262 { return m_mode == READING; }

◆ isWriting()

bool StreamBuffer::isWriting ( ) const
inline

Get stream buffer state.

Definition at line 265 of file StreamBuffer.h.

265 { return m_mode == WRITING; }

◆ operator<<() [1/15]

StreamBuffer& StreamBuffer::operator<< ( char  data)
inline

Output Streamer.

Definition at line 410 of file StreamBuffer.h.

410  {
411  swapToBuffer( &data, sizeof( data ) );
412  STREAM_ANALYSE( data, sizeof( data ) );
413  return *this;
414  }

◆ operator<<() [2/15]

StreamBuffer& StreamBuffer::operator<< ( const char *  data)
inline

Streamer to write strings in (char*) format.

Definition at line 461 of file StreamBuffer.h.

461  {
462  const char* ptr = 0 == data ? "" : data;
463  size_t len = strlen( ptr ) + 1;
464  if ( 0 == m_analyzer )
465  writeBytes( ptr, len );
466  else { STREAM_ANALYSE( data, len ); }
467  return *this;
468  }

◆ operator<<() [3/15]

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 504 of file StreamBuffer.h.

504  {
505  STREAM_ANALYSE( pObject, sizeof( pObject ) );
506  addContainedLink( pObject, INVALID, INVALID );
507  return *this;
508  }

◆ operator<<() [4/15]

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 516 of file StreamBuffer.h.

516  {
517  STREAM_ANALYSE( pObject, sizeof( pObject ) );
518  addIdentifiedLink( pObject, INVALID );
519  return *this;
520  }

◆ operator<<() [5/15]

StreamBuffer& StreamBuffer::operator<< ( const std::string data)
inline

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

Definition at line 477 of file StreamBuffer.h.

477  {
478  if ( 0 == m_analyzer ) {
479  const char* ptr = data.c_str();
480  long len = data.length();
481  writeBytes( ptr, len );
482  } else {
483  STREAM_ANALYSE( data, sizeof( data ) );
484  }
485  return *this;
486  }

◆ operator<<() [6/15]

StreamBuffer& StreamBuffer::operator<< ( double  data)
inline

Output Streamer.

Definition at line 443 of file StreamBuffer.h.

443  {
444  swapToBuffer( &data, sizeof( data ) );
445  STREAM_ANALYSE( data, sizeof( data ) );
446  return *this;
447  }

◆ operator<<() [7/15]

StreamBuffer& StreamBuffer::operator<< ( float  data)
inline

Output Streamer.

Definition at line 432 of file StreamBuffer.h.

432  {
433  swapToBuffer( &data, sizeof( data ) );
434  STREAM_ANALYSE( data, sizeof( data ) );
435  return *this;
436  }

◆ operator<<() [8/15]

StreamBuffer& StreamBuffer::operator<< ( int  data)
inline

Output Streamer.

Definition at line 344 of file StreamBuffer.h.

344  {
345  swapToBuffer( &data, sizeof( data ) );
346  STREAM_ANALYSE( data, sizeof( data ) );
347  return *this;
348  }

◆ operator<<() [9/15]

StreamBuffer& StreamBuffer::operator<< ( long  data)
inline

Output Streamer.

Definition at line 366 of file StreamBuffer.h.

366  {
367  swapToBuffer( &data, sizeof( data ) );
368  STREAM_ANALYSE( data, sizeof( data ) );
369  return *this;
370  }

◆ operator<<() [10/15]

StreamBuffer& StreamBuffer::operator<< ( long long  data)
inline

Output Streamer.

Definition at line 333 of file StreamBuffer.h.

333  {
334  swapToBuffer( &data, sizeof( data ) );
335  STREAM_ANALYSE( data, sizeof( data ) );
336  return *this;
337  }

◆ operator<<() [11/15]

StreamBuffer& StreamBuffer::operator<< ( short  data)
inline

Output Streamer.

Definition at line 388 of file StreamBuffer.h.

388  {
389  swapToBuffer( &data, sizeof( data ) );
390  STREAM_ANALYSE( data, sizeof( data ) );
391  return *this;
392  }

◆ operator<<() [12/15]

StreamBuffer& StreamBuffer::operator<< ( unsigned char  data)
inline

Output Streamer.

Definition at line 421 of file StreamBuffer.h.

421  {
422  swapToBuffer( &data, sizeof( data ) );
423  STREAM_ANALYSE( data, sizeof( data ) );
424  return *this;
425  }

◆ operator<<() [13/15]

StreamBuffer& StreamBuffer::operator<< ( unsigned int  data)
inline

Output Streamer.

Definition at line 355 of file StreamBuffer.h.

355  {
356  swapToBuffer( &data, sizeof( data ) );
357  STREAM_ANALYSE( data, sizeof( data ) );
358  return *this;
359  }

◆ operator<<() [14/15]

StreamBuffer& StreamBuffer::operator<< ( unsigned long  data)
inline

Output Streamer.

Definition at line 377 of file StreamBuffer.h.

377  {
378  swapToBuffer( &data, sizeof( data ) );
379  STREAM_ANALYSE( data, sizeof( data ) );
380  return *this;
381  }

◆ operator<<() [15/15]

StreamBuffer& StreamBuffer::operator<< ( unsigned short  data)
inline

Output Streamer.

Definition at line 399 of file StreamBuffer.h.

399  {
400  swapToBuffer( &data, sizeof( data ) );
401  STREAM_ANALYSE( data, sizeof( data ) );
402  return *this;
403  }

◆ operator>>() [1/14]

StreamBuffer& StreamBuffer::operator>> ( char &  data)
inline

Input Streamer.

Definition at line 416 of file StreamBuffer.h.

416  {
417  swapFromBuffer( &data, sizeof( data ) );
418  return *this;
419  }

◆ operator>>() [2/14]

StreamBuffer& StreamBuffer::operator>> ( char *  data)
inline

Streamer to read strings in (char*) format.

Definition at line 454 of file StreamBuffer.h.

454  {
455  long i, len;
456  *this >> len;
457  for ( i = 0, data[0] = 0; i < len; i++ ) { data[i] = m_buffer[m_pointer++]; }
458  return *this;
459  }

◆ operator>>() [3/14]

StreamBuffer& StreamBuffer::operator>> ( double &  data)
inline

Input Streamer.

Definition at line 449 of file StreamBuffer.h.

449  {
450  swapFromBuffer( &data, sizeof( data ) );
451  return *this;
452  }

◆ operator>>() [4/14]

StreamBuffer& StreamBuffer::operator>> ( float &  data)
inline

Input Streamer.

Definition at line 438 of file StreamBuffer.h.

438  {
439  swapFromBuffer( &data, sizeof( data ) );
440  return *this;
441  }

◆ operator>>() [5/14]

StreamBuffer& StreamBuffer::operator>> ( int &  data)
inline

Input Streamer.

Definition at line 350 of file StreamBuffer.h.

350  {
351  swapFromBuffer( &data, sizeof( data ) );
352  return *this;
353  }

◆ operator>>() [6/14]

StreamBuffer& StreamBuffer::operator>> ( long &  data)
inline

Input Streamer.

Definition at line 372 of file StreamBuffer.h.

372  {
373  swapFromBuffer( &data, sizeof( data ) );
374  return *this;
375  }

◆ operator>>() [7/14]

StreamBuffer& StreamBuffer::operator>> ( long long &  data)
inline

Input Streamer.

Definition at line 339 of file StreamBuffer.h.

339  {
340  swapFromBuffer( &data, sizeof( data ) );
341  return *this;
342  }

◆ operator>>() [8/14]

StreamBuffer& StreamBuffer::operator>> ( short &  data)
inline

Input Streamer.

Definition at line 394 of file StreamBuffer.h.

394  {
395  swapFromBuffer( &data, sizeof( data ) );
396  return *this;
397  }

◆ operator>>() [9/14]

StreamBuffer& StreamBuffer::operator>> ( std::string data)
inline

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

Definition at line 470 of file StreamBuffer.h.

470  {
471  long i, len;
472  *this >> len;
473  for ( i = 0, data = ""; i < len; i++ ) { data.append( 1, m_buffer[m_pointer++] ); }
474  return *this;
475  }

◆ operator>>() [10/14]

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 494 of file StreamBuffer.h.

494  {
495  return getObjectPointer( refpObject, refpObject );
496  }

◆ operator>>() [11/14]

StreamBuffer& StreamBuffer::operator>> ( unsigned char &  data)
inline

Input Streamer.

Definition at line 427 of file StreamBuffer.h.

427  {
428  swapFromBuffer( &data, sizeof( data ) );
429  return *this;
430  }

◆ operator>>() [12/14]

StreamBuffer& StreamBuffer::operator>> ( unsigned int &  data)
inline

Input Streamer.

Definition at line 361 of file StreamBuffer.h.

361  {
362  swapFromBuffer( &data, sizeof( data ) );
363  return *this;
364  }

◆ operator>>() [13/14]

StreamBuffer& StreamBuffer::operator>> ( unsigned long &  data)
inline

Input Streamer.

Definition at line 383 of file StreamBuffer.h.

383  {
384  swapFromBuffer( &data, sizeof( data ) );
385  return *this;
386  }

◆ operator>>() [14/14]

StreamBuffer& StreamBuffer::operator>> ( unsigned short &  data)
inline

Input Streamer.

Definition at line 405 of file StreamBuffer.h.

405  {
406  swapFromBuffer( &data, sizeof( data ) );
407  return *this;
408  }

◆ reserve()

void StreamBuffer::reserve ( long  len)
inline

Reserve buffer space; Default: 16 k buffer size.

Definition at line 225 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  }

◆ serialize()

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 528 of file StreamBuffer.h.

528  {
529  ioObject.serialize( *this );
530  m_pointer = 0;
531  }

◆ setAnalyzer()

void StreamBuffer::setAnalyzer ( AnalyzeFunction  fun = nullptr)
inline

Enable user analysis function.

Definition at line 271 of file StreamBuffer.h.

271 { m_analyzer = fun; }

◆ setBuffPointer()

void StreamBuffer::setBuffPointer ( long  ptr)
inline

Retrieve current buffer pointer.

Definition at line 269 of file StreamBuffer.h.

269 { m_pointer = ptr; }

◆ setMode()

void StreamBuffer::setMode ( Mode  m)
inline

Set mode of the stream and allocate buffer.

Definition at line 254 of file StreamBuffer.h.

◆ size()

long StreamBuffer::size ( ) const
inline

Total buffer size.

Definition at line 242 of file StreamBuffer.h.

242 { return m_length; }

◆ swapBuffer()

StreamBuffer::SwapAction StreamBuffer::swapBuffer ( int  siz) const
inlineprotected

Check for byte swapping.

Definition at line 537 of file StreamBuffer.h.

537  {
538  switch ( siz ) {
539  case 1:
540  return SINGLE_BYTE;
541  default:
542 #if defined( __alpha ) && !defined( __VMS )
543  // return m_swapEnabled ? SWAP : NOSWAP;
544  return NOSWAP;
545 #elif defined( __sun ) && defined( __SVR4 ) && defined( __i386 )
546  // return m_swapEnabled ? SWAP : NOSWAP;
547  return NOSWAP;
548 #elif defined( __APPLE__ )
549  // return m_swapEnabled ? SWAP : NOSWAP;
550  return SWAP;
551 #elif defined( __linux ) && !defined( __powerpc )
552  // return m_swapEnabled ? SWAP : NOSWAP;
553  return NOSWAP;
554 #elif defined( BORLAND ) || defined( _WIN32 ) || defined( WIN32 )
555  // return m_swapEnabled ? SWAP : NOSWAP;
556  return NOSWAP;
557 #else
558  return m_swapEnabled ? SWAP : NOSWAP;
559 // return NOSWAP;
560 #endif
561  }
562 }

◆ swapFromBuffer()

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 591 of file StreamBuffer.h.

591  {
592  char* tar = (char*)target;
593  char* src = m_buffer + m_pointer;
594  switch ( swapBuffer( siz ) ) {
595  case SINGLE_BYTE:
596  *tar = *src;
597  break;
598  case SWAP:
599 #ifdef __APPLE__
600  for ( int i = 0, j = siz - 1; i < siz; i++, j-- ) tar[j] = src[i];
601 #else
602  ::_swab( src, tar, siz );
603 #endif
604  break;
605  case NOSWAP:
606  std::copy_n( src, siz, tar );
607  break;
608  default:
609  break;
610  }
611  m_pointer += siz;
612 }

◆ swapToBuffer()

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 565 of file StreamBuffer.h.

565  {
566  char buff[8], *tar, *src = (char*)source;
567  extend( m_pointer + siz );
568  tar = m_buffer + m_pointer;
569  switch ( swapBuffer( siz ) ) {
570  case SINGLE_BYTE:
571  *tar = *src;
572  break;
573  case SWAP:
574 #ifdef __APPLE__
575  for ( int i = 0, j = siz - 1; i < siz; i++, j-- ) tar[j] = src[i];
576 #else
577  ::_swab( src, buff, siz );
578 #endif
579  src = buff;
580  [[fallthrough]];
581  case NOSWAP:
582  std::copy_n( src, siz, tar );
583  break;
584  default:
585  break;
586  }
587  m_pointer += siz;
588 }

◆ writeBytes()

StreamBuffer& StreamBuffer::writeBytes ( const char *  str,
long  len 
)
inline

Write string to output stream.

Definition at line 279 of file StreamBuffer.h.

279  {
280  extend( m_pointer + len + 4 );
281  *this << len;
282  std::copy_n( str, len, data() + buffPointer() );
283  m_pointer += len;
284  return *this;
285  }

Friends And Related Function Documentation

◆ DataObject

friend class DataObject
friend

DataObject is friend.

Definition at line 150 of file StreamBuffer.h.

Member Data Documentation

◆ m_analyzer

AnalyzeFunction StreamBuffer::m_analyzer = nullptr
protected

Hook function for analysis of data to the stream.

Definition at line 175 of file StreamBuffer.h.

◆ m_buffer

char* StreamBuffer::m_buffer = nullptr
mutableprotected

Pointer to heap buffer.

Definition at line 163 of file StreamBuffer.h.

◆ m_containedLinks

ContainedLinks StreamBuffer::m_containedLinks
mutableprotected

Container with links to contained objects.

Definition at line 169 of file StreamBuffer.h.

◆ m_identifiedLinks

IdentifiedLinks StreamBuffer::m_identifiedLinks
mutableprotected

Container with links to contained objects.

Definition at line 172 of file StreamBuffer.h.

◆ m_length

long StreamBuffer::m_length = 0
mutableprotected

Total buffer length.

Definition at line 160 of file StreamBuffer.h.

◆ m_mode

Mode StreamBuffer::m_mode = UNINITIALIZED
protected

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

Definition at line 154 of file StreamBuffer.h.

◆ m_pointer

long StreamBuffer::m_pointer = 0
mutableprotected

Current buffer pointer.

Definition at line 157 of file StreamBuffer.h.

◆ m_swapEnabled

bool StreamBuffer::m_swapEnabled = true
protected

Flag indicating swapping.

Definition at line 166 of file StreamBuffer.h.


The documentation for this class was generated from the following file:
std::strlen
T strlen(T... args)
StreamBuffer::addIdentifiedLink
void addIdentifiedLink(const DataObject *pObject, long hint)
Definition: StreamBuffer.h:293
StreamBuffer::m_buffer
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:163
StreamBuffer::SWAP
@ SWAP
Definition: StreamBuffer.h:119
StreamBuffer::m_containedLinks
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:169
StreamBuffer::swapBuffer
SwapAction swapBuffer(int siz) const
Check for byte swapping.
Definition: StreamBuffer.h:537
StreamBuffer::extend
void extend(long len)
Extend the buffer.
Definition: StreamBuffer.h:232
StreamBuffer::m_mode
Mode m_mode
Boolean indicating wether the stream is in read or write mode.
Definition: StreamBuffer.h:154
StreamBuffer::buffPointer
long buffPointer() const
Retrieve current buffer pointer.
Definition: StreamBuffer.h:267
StreamBuffer::m_analyzer
AnalyzeFunction m_analyzer
Hook function for analysis of data to the stream.
Definition: StreamBuffer.h:175
std::vector::back
T back(T... args)
StreamBuffer::swapFromBuffer
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:591
StreamBuffer::m_swapEnabled
bool m_swapEnabled
Flag indicating swapping.
Definition: StreamBuffer.h:166
StreamBuffer::READING
@ READING
Definition: StreamBuffer.h:117
std::vector::push_back
T push_back(T... args)
compareOutputFiles.target
target
Definition: compareOutputFiles.py:489
std::copy_n
T copy_n(T... args)
StreamBuffer::swapToBuffer
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:565
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:108
ProduceConsume.j
j
Definition: ProduceConsume.py:104
StreamBuffer::SINGLE_BYTE
@ SINGLE_BYTE
Definition: StreamBuffer.h:119
StreamBuffer::writeBytes
StreamBuffer & writeBytes(const char *str, long len)
Write string to output stream.
Definition: StreamBuffer.h:279
StreamBuffer::getObjectPointer
StreamBuffer & getObjectPointer(const DataObject *, TYPE *&refpObject)
Helper to distinguish between identified pointers and contained pointers.
Definition: StreamBuffer.h:184
std::vector::erase
T erase(T... args)
StreamBuffer::data
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:209
std::vector::pop_back
T pop_back(T... args)
StreamBuffer::reserve
void reserve(long len)
Reserve buffer space; Default: 16 k buffer size.
Definition: StreamBuffer.h:225
StreamBuffer::UNINITIALIZED
@ UNINITIALIZED
Definition: StreamBuffer.h:117
std::realloc
T realloc(T... args)
gaudirun.l
dictionary l
Definition: gaudirun.py:583
std::vector::begin
T begin(T... args)
StreamBuffer::m_length
long m_length
Total buffer length.
Definition: StreamBuffer.h:160
StreamBuffer::m_pointer
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:157
StreamBuffer::VALID
@ VALID
Definition: StreamBuffer.h:121
DataObject
Definition: DataObject.h:36
std::vector::end
T end(T... args)
_swab
#define _swab(source, target, radix)
Definition: swab.h:17
StreamBuffer::addContainedLink
void addContainedLink(const ContainedObject *pObject, long hint, long link)
Definition: StreamBuffer.h:304
StreamBuffer::NOSWAP
@ NOSWAP
Definition: StreamBuffer.h:119
STREAM_ANALYSE
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:312
StreamBuffer::WRITING
@ WRITING
Definition: StreamBuffer.h:117
ContainedObject
Definition: ContainedObject.h:41
StreamBuffer::m_identifiedLinks
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:172
StreamBuffer::INVALID
@ INVALID
Definition: StreamBuffer.h:121