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

◆ ContainedLinks

◆ IdentifiedLinks

Definition of the identifiable link set.

Definition at line 144 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.

◆ SwapAction

Data Sawp actions.

Enumerator
SINGLE_BYTE 
SWAP 
NOSWAP 

Definition at line 119 of file StreamBuffer.h.

Constructor & Destructor Documentation

◆ StreamBuffer()

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:164

◆ ~StreamBuffer()

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:161

Member Function Documentation

◆ addContainedLink()

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

Definition at line 302 of file StreamBuffer.h.

302  {
303  m_containedLinks.push_back( ContainedLink( (ContainedObject*)pObject, hint, link ) );
304  }
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.

◆ addIdentifiedLink()

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

Definition at line 291 of file StreamBuffer.h.

291  {
292  m_identifiedLinks.push_back( IdentifiedLink( (DataObject*)pObject, hint ) );
293  }
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:40

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

213  {
214  char* ptr = m_buffer;
217  m_buffer = NULL; // char *
218  m_pointer = 0; // long
219  m_length = 0; // long
220  return ptr;
221  }
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

◆ buffPointer()

long StreamBuffer::buffPointer ( ) const
inline

Retrieve current buffer pointer.

Definition at line 265 of file StreamBuffer.h.

265 { return m_pointer; }
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:155

◆ containedLinks() [1/2]

ContainedLinks& StreamBuffer::containedLinks ( )
inline

Access to contained links.

Definition at line 242 of file StreamBuffer.h.

242 { return m_containedLinks; }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:167

◆ containedLinks() [2/2]

const ContainedLinks& StreamBuffer::containedLinks ( ) const
inline

CONST Access to contained links.

Definition at line 244 of file StreamBuffer.h.

244 { return m_containedLinks; }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:167

◆ data() [1/2]

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:161

◆ data() [2/2]

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:161

◆ erase()

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:155

◆ extend()

void StreamBuffer::extend ( long  len)
inline

Extend the buffer.

Definition at line 230 of file StreamBuffer.h.

230  {
231  if ( len + m_pointer > m_length ) {
232  // We have to be a bit generous here in order not to run too often
233  // into ::realloc().
234  long new_len = ( m_length < 16384 ) ? 16384 : 2 * m_length;
235  if ( m_length < len ) new_len += len;
236  reserve( new_len );
237  }
238  }
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:223
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:155

◆ getContainedLink()

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

Definition at line 295 of file StreamBuffer.h.

295  {
296  ContainedLink& l = m_containedLinks.back();
297  pObject = l.first;
298  hint = l.second;
299  link = l.third;
301  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:167
T pop_back(T... args)
dictionary l
Definition: gaudirun.py:543
T back(T... args)

◆ getIdentifiedLink()

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

Definition at line 285 of file StreamBuffer.h.

285  {
286  IdentifiedLink& l = m_identifiedLinks.back();
287  pObject = l.first;
288  hint = l.second;
290  }
T pop_back(T... args)
dictionary l
Definition: gaudirun.py:543
T back(T... args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:170

◆ getObjectPointer() [1/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 182 of file StreamBuffer.h.

182  {
183  IdentifiedLink& link = m_identifiedLinks.back();
184  DataObject* pObj = link.first;
186  refpObject = dynamic_cast<TYPE*>( pObj );
187  return *this;
188  }
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:40

◆ getObjectPointer() [2/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 193 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: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() [1/2]

IdentifiedLinks& StreamBuffer::identifiedLinks ( )
inline

Access to identified links.

Definition at line 247 of file StreamBuffer.h.

247 { return m_identifiedLinks; }
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:170

◆ identifiedLinks() [2/2]

const IdentifiedLinks& StreamBuffer::identifiedLinks ( ) const
inline

CONST Access to identified links.

Definition at line 249 of file StreamBuffer.h.

249 { return m_identifiedLinks; }
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:170

◆ isReading()

bool StreamBuffer::isReading ( ) const
inline

Get stream buffer state.

Definition at line 260 of file StreamBuffer.h.

260 { return m_mode == READING; }
Mode m_mode
Boolean indicating wether the stream is in read or write mode.
Definition: StreamBuffer.h:152

◆ isWriting()

bool StreamBuffer::isWriting ( ) const
inline

Get stream buffer state.

Definition at line 263 of file StreamBuffer.h.

263 { return m_mode == WRITING; }
Mode m_mode
Boolean indicating wether the stream is in read or write mode.
Definition: StreamBuffer.h:152

◆ operator<<() [1/15]

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

Output Streamer.

Definition at line 331 of file StreamBuffer.h.

331  {
332  swapToBuffer( &data, sizeof( data ) );
333  STREAM_ANALYSE( data, sizeof( data ) );
334  return *this;
335  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:565
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:310
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207

◆ operator<<() [2/15]

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

Output Streamer.

Definition at line 342 of file StreamBuffer.h.

342  {
343  swapToBuffer( &data, sizeof( data ) );
344  STREAM_ANALYSE( data, sizeof( data ) );
345  return *this;
346  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:565
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:310
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207

◆ operator<<() [3/15]

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

Output Streamer.

Definition at line 353 of file StreamBuffer.h.

353  {
354  swapToBuffer( &data, sizeof( data ) );
355  STREAM_ANALYSE( data, sizeof( data ) );
356  return *this;
357  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:565
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:310
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207

◆ operator<<() [4/15]

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

Output Streamer.

Definition at line 364 of file StreamBuffer.h.

364  {
365  swapToBuffer( &data, sizeof( data ) );
366  STREAM_ANALYSE( data, sizeof( data ) );
367  return *this;
368  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:565
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:310
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207

◆ operator<<() [5/15]

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

Output Streamer.

Definition at line 375 of file StreamBuffer.h.

375  {
376  swapToBuffer( &data, sizeof( data ) );
377  STREAM_ANALYSE( data, sizeof( data ) );
378  return *this;
379  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:565
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:310
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207

◆ operator<<() [6/15]

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

Output Streamer.

Definition at line 386 of file StreamBuffer.h.

386  {
387  swapToBuffer( &data, sizeof( data ) );
388  STREAM_ANALYSE( data, sizeof( data ) );
389  return *this;
390  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:565
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:310
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207

◆ operator<<() [7/15]

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

Output Streamer.

Definition at line 397 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:565
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:310
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207

◆ operator<<() [8/15]

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

Output Streamer.

Definition at line 408 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:565
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:310
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207

◆ operator<<() [9/15]

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

Output Streamer.

Definition at line 419 of file StreamBuffer.h.

419  {
420  swapToBuffer( &data, sizeof( data ) );
421  STREAM_ANALYSE( data, sizeof( data ) );
422  return *this;
423  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:565
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:310
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207

◆ operator<<() [10/15]

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

Output Streamer.

Definition at line 430 of file StreamBuffer.h.

430  {
431  swapToBuffer( &data, sizeof( data ) );
432  STREAM_ANALYSE( data, sizeof( data ) );
433  return *this;
434  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:565
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:310
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207

◆ operator<<() [11/15]

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

Output Streamer.

Definition at line 441 of file StreamBuffer.h.

441  {
442  swapToBuffer( &data, sizeof( data ) );
443  STREAM_ANALYSE( data, sizeof( data ) );
444  return *this;
445  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:565
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:310
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207

◆ operator<<() [12/15]

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

Streamer to write strings in (char*) format.

Definition at line 459 of file StreamBuffer.h.

459  {
460  const char* ptr = 0 == data ? "" : data;
461  int len = strlen( ptr ) + 1;
462  if ( 0 == m_analyzer )
463  writeBytes( ptr, len );
464  else {
465  STREAM_ANALYSE( data, len );
466  }
467  return *this;
468  }
AnalyzeFunction m_analyzer
Hook function for analysis of data to the stream.
Definition: StreamBuffer.h:173
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:310
T strlen(T... args)
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
StreamBuffer & writeBytes(const char *str, long len)
Write string to output stream.
Definition: StreamBuffer.h:277

◆ operator<<() [13/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  }
AnalyzeFunction m_analyzer
Hook function for analysis of data to the stream.
Definition: StreamBuffer.h:173
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:310
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
StreamBuffer & writeBytes(const char *str, long len)
Write string to output stream.
Definition: StreamBuffer.h:277

◆ operator<<() [14/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  }
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:310
void addContainedLink(const ContainedObject *pObject, long hint, long link)
Definition: StreamBuffer.h:302

◆ operator<<() [15/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  }
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:310
void addIdentifiedLink(const DataObject *pObject, long hint)
Definition: StreamBuffer.h:291

◆ operator>>() [1/14]

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

Input Streamer.

Definition at line 337 of file StreamBuffer.h.

337  {
338  swapFromBuffer( &data, sizeof( data ) );
339  return *this;
340  }
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:591

◆ operator>>() [2/14]

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

Input Streamer.

Definition at line 348 of file StreamBuffer.h.

348  {
349  swapFromBuffer( &data, sizeof( data ) );
350  return *this;
351  }
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:591

◆ operator>>() [3/14]

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

Input Streamer.

Definition at line 359 of file StreamBuffer.h.

359  {
360  swapFromBuffer( &data, sizeof( data ) );
361  return *this;
362  }
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:591

◆ operator>>() [4/14]

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

Input Streamer.

Definition at line 370 of file StreamBuffer.h.

370  {
371  swapFromBuffer( &data, sizeof( data ) );
372  return *this;
373  }
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:591

◆ operator>>() [5/14]

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

Input Streamer.

Definition at line 381 of file StreamBuffer.h.

381  {
382  swapFromBuffer( &data, sizeof( data ) );
383  return *this;
384  }
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:591

◆ operator>>() [6/14]

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

Input Streamer.

Definition at line 392 of file StreamBuffer.h.

392  {
393  swapFromBuffer( &data, sizeof( data ) );
394  return *this;
395  }
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:591

◆ operator>>() [7/14]

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

Input Streamer.

Definition at line 403 of file StreamBuffer.h.

403  {
404  swapFromBuffer( &data, sizeof( data ) );
405  return *this;
406  }
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:591

◆ operator>>() [8/14]

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

Input Streamer.

Definition at line 414 of file StreamBuffer.h.

414  {
415  swapFromBuffer( &data, sizeof( data ) );
416  return *this;
417  }
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:591

◆ operator>>() [9/14]

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

Input Streamer.

Definition at line 425 of file StreamBuffer.h.

425  {
426  swapFromBuffer( &data, sizeof( data ) );
427  return *this;
428  }
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:591

◆ operator>>() [10/14]

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

Input Streamer.

Definition at line 436 of file StreamBuffer.h.

436  {
437  swapFromBuffer( &data, sizeof( data ) );
438  return *this;
439  }
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:591

◆ operator>>() [11/14]

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

Input Streamer.

Definition at line 447 of file StreamBuffer.h.

447  {
448  swapFromBuffer( &data, sizeof( data ) );
449  return *this;
450  }
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:591

◆ operator>>() [12/14]

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

Streamer to read strings in (char*) format.

Definition at line 452 of file StreamBuffer.h.

452  {
453  long i, len;
454  *this >> len;
455  for ( i = 0, data[0] = 0; i < len; i++ ) { data[i] = m_buffer[m_pointer++]; }
456  return *this;
457  }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:161
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:155

◆ operator>>() [13/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  }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:161
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:207
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:155

◆ operator>>() [14/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  }
StreamBuffer & getObjectPointer(const DataObject *, TYPE *&refpObject)
Helper to distinguish between identified pointers and contained pointers.
Definition: StreamBuffer.h:182

◆ reserve()

void StreamBuffer::reserve ( long  len)
inline

Reserve buffer space; Default: 16 k buffer size.

Definition at line 223 of file StreamBuffer.h.

223  {
224  if ( len > m_length ) {
225  m_length = ( len < 16384 ) ? 16384 : len;
226  m_buffer = (char*)::realloc( m_buffer, m_length );
227  }
228  }
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)

◆ 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  }
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:155

◆ setAnalyzer()

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

Enable user analysis function.

Definition at line 269 of file StreamBuffer.h.

269 { m_analyzer = fun; }
AnalyzeFunction m_analyzer
Hook function for analysis of data to the stream.
Definition: StreamBuffer.h:173

◆ setBuffPointer()

void StreamBuffer::setBuffPointer ( long  ptr)
inline

Retrieve current buffer pointer.

Definition at line 267 of file StreamBuffer.h.

267 { m_pointer = ptr; }
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:155

◆ setMode()

void StreamBuffer::setMode ( Mode  m)
inline

Set mode of the stream and allocate buffer.

Definition at line 252 of file StreamBuffer.h.

252  {
253  m_mode = m;
254  m_pointer = 0;
257  }
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
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

◆ size()

long StreamBuffer::size ( ) const
inline

Total buffer size.

Definition at line 240 of file StreamBuffer.h.

240 { return m_length; }
long m_length
Total buffer length.
Definition: StreamBuffer.h:158

◆ 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 }
bool m_swapEnabled
Flag indicating swapping.
Definition: StreamBuffer.h:164

◆ 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 }
SwapAction swapBuffer(int siz) const
Check for byte swapping.
Definition: StreamBuffer.h:537
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:161
T copy_n(T... args)
#define _swab(source, target, radix)
Definition: swab.h:17
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:155

◆ 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 }
SwapAction swapBuffer(int siz) const
Check for byte swapping.
Definition: StreamBuffer.h:537
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:161
void extend(long len)
Extend the buffer.
Definition: StreamBuffer.h:230
T copy_n(T... args)
#define _swab(source, target, radix)
Definition: swab.h:17
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:155

◆ writeBytes()

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

Write string to output stream.

Definition at line 277 of file StreamBuffer.h.

277  {
278  extend( m_pointer + len + 4 );
279  *this << len;
280  std::copy_n( str, len, data() + buffPointer() );
281  m_pointer += len;
282  return *this;
283  }
void extend(long len)
Extend the buffer.
Definition: StreamBuffer.h:230
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:155
long buffPointer() const
Retrieve current buffer pointer.
Definition: StreamBuffer.h:265

Friends And Related Function Documentation

◆ DataObject

friend class DataObject
friend

DataObject is friend.

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

◆ m_buffer

char* StreamBuffer::m_buffer = nullptr
mutableprotected

Pointer to heap buffer.

Definition at line 161 of file StreamBuffer.h.

◆ m_containedLinks

ContainedLinks StreamBuffer::m_containedLinks
mutableprotected

Container with links to contained objects.

Definition at line 167 of file StreamBuffer.h.

◆ m_identifiedLinks

IdentifiedLinks StreamBuffer::m_identifiedLinks
mutableprotected

Container with links to contained objects.

Definition at line 170 of file StreamBuffer.h.

◆ m_length

long StreamBuffer::m_length = 0
mutableprotected

Total buffer length.

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

◆ m_pointer

long StreamBuffer::m_pointer = 0
mutableprotected

Current buffer pointer.

Definition at line 155 of file StreamBuffer.h.

◆ m_swapEnabled

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: