The Gaudi Framework  v33r2 (a6f0ec87)
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 145 of file StreamBuffer.h.

◆ ContainedLinks

◆ IdentifiedLinks

Definition of the identifiable link set.

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

202 : m_swapEnabled( do_swap ) {}
bool m_swapEnabled
Flag indicating swapping.
Definition: StreamBuffer.h:163

◆ ~StreamBuffer()

virtual StreamBuffer::~StreamBuffer ( )
inlinevirtual

Standard destructor.

Definition at line 204 of file StreamBuffer.h.

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

Member Function Documentation

◆ addContainedLink()

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

Definition at line 301 of file StreamBuffer.h.

301  {
302  m_containedLinks.push_back( ContainedLink( (ContainedObject*)pObject, hint, link ) );
303  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:166
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 290 of file StreamBuffer.h.

290  {
291  m_identifiedLinks.push_back( IdentifiedLink( (DataObject*)pObject, hint ) );
292  }
T push_back(T... args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:169
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 212 of file StreamBuffer.h.

212  {
213  char* ptr = m_buffer;
216  m_buffer = NULL; // char *
217  m_pointer = 0; // long
218  m_length = 0; // long
219  return ptr;
220  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:166
long m_length
Total buffer length.
Definition: StreamBuffer.h:157
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:160
T end(T... args)
T erase(T... args)
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:154
T begin(T... args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:169

◆ buffPointer()

long StreamBuffer::buffPointer ( ) const
inline

Retrieve current buffer pointer.

Definition at line 264 of file StreamBuffer.h.

264 { return m_pointer; }
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:154

◆ containedLinks() [1/2]

ContainedLinks& StreamBuffer::containedLinks ( )
inline

Access to contained links.

Definition at line 241 of file StreamBuffer.h.

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

◆ containedLinks() [2/2]

const ContainedLinks& StreamBuffer::containedLinks ( ) const
inline

CONST Access to contained links.

Definition at line 243 of file StreamBuffer.h.

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

◆ data() [1/2]

const char* StreamBuffer::data ( ) const
inline

Read access to data buffer.

Definition at line 206 of file StreamBuffer.h.

206 { return m_buffer; }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:160

◆ data() [2/2]

char* StreamBuffer::data ( )
inline

write access to data buffer

Definition at line 208 of file StreamBuffer.h.

208 { return m_buffer; }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:160

◆ erase()

void StreamBuffer::erase ( )
inline

Reset the buffer.

Definition at line 210 of file StreamBuffer.h.

210 { m_pointer = 0; }
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:154

◆ extend()

void StreamBuffer::extend ( long  len)
inline

Extend the buffer.

Definition at line 229 of file StreamBuffer.h.

229  {
230  if ( len + m_pointer > m_length ) {
231  // We have to be a bit generous here in order not to run too often
232  // into ::realloc().
233  long new_len = ( m_length < 16384 ) ? 16384 : 2 * m_length;
234  if ( m_length < len ) new_len += len;
235  reserve( new_len );
236  }
237  }
long m_length
Total buffer length.
Definition: StreamBuffer.h:157
void reserve(long len)
Reserve buffer space; Default: 16 k buffer size.
Definition: StreamBuffer.h:222
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:154

◆ getContainedLink()

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

Definition at line 294 of file StreamBuffer.h.

294  {
295  ContainedLink& l = m_containedLinks.back();
296  pObject = l.first;
297  hint = l.second;
298  link = l.third;
300  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:166
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 284 of file StreamBuffer.h.

284  {
285  IdentifiedLink& l = m_identifiedLinks.back();
286  pObject = l.first;
287  hint = l.second;
289  }
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:169

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

181  {
182  IdentifiedLink& link = m_identifiedLinks.back();
183  DataObject* pObj = link.first;
185  refpObject = dynamic_cast<TYPE*>( pObj );
186  return *this;
187  }
T pop_back(T... args)
T back(T... args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:169
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 192 of file StreamBuffer.h.

192  {
193  ContainedLink& link = m_containedLinks.back();
194  ContainedObject* pObj = link.first;
196  refpObject = dynamic_cast<TYPE*>( pObj );
197  return *this;
198  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:166
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 246 of file StreamBuffer.h.

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

◆ identifiedLinks() [2/2]

const IdentifiedLinks& StreamBuffer::identifiedLinks ( ) const
inline

CONST Access to identified links.

Definition at line 248 of file StreamBuffer.h.

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

◆ isReading()

bool StreamBuffer::isReading ( ) const
inline

Get stream buffer state.

Definition at line 259 of file StreamBuffer.h.

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

◆ isWriting()

bool StreamBuffer::isWriting ( ) const
inline

Get stream buffer state.

Definition at line 262 of file StreamBuffer.h.

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

◆ operator<<() [1/15]

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

Output Streamer.

Definition at line 330 of file StreamBuffer.h.

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

◆ operator<<() [2/15]

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

Output Streamer.

Definition at line 341 of file StreamBuffer.h.

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

◆ operator<<() [3/15]

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

Output Streamer.

Definition at line 352 of file StreamBuffer.h.

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

◆ operator<<() [4/15]

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

Output Streamer.

Definition at line 363 of file StreamBuffer.h.

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

◆ operator<<() [5/15]

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

Output Streamer.

Definition at line 374 of file StreamBuffer.h.

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

◆ operator<<() [6/15]

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

Output Streamer.

Definition at line 385 of file StreamBuffer.h.

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

◆ operator<<() [7/15]

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

Output Streamer.

Definition at line 396 of file StreamBuffer.h.

396  {
397  swapToBuffer( &data, sizeof( data ) );
398  STREAM_ANALYSE( data, sizeof( data ) );
399  return *this;
400  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:564
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:309
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:206

◆ operator<<() [8/15]

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

Output Streamer.

Definition at line 407 of file StreamBuffer.h.

407  {
408  swapToBuffer( &data, sizeof( data ) );
409  STREAM_ANALYSE( data, sizeof( data ) );
410  return *this;
411  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:564
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:309
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:206

◆ operator<<() [9/15]

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

Output Streamer.

Definition at line 418 of file StreamBuffer.h.

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

◆ operator<<() [10/15]

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

Output Streamer.

Definition at line 429 of file StreamBuffer.h.

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

◆ operator<<() [11/15]

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

Output Streamer.

Definition at line 440 of file StreamBuffer.h.

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

◆ operator<<() [12/15]

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

Streamer to write strings in (char*) format.

Definition at line 458 of file StreamBuffer.h.

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

◆ operator<<() [13/15]

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

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

Definition at line 476 of file StreamBuffer.h.

476  {
477  if ( 0 == m_analyzer ) {
478  const char* ptr = data.c_str();
479  long len = data.length();
480  writeBytes( ptr, len );
481  } else {
482  STREAM_ANALYSE( data, sizeof( data ) );
483  }
484  return *this;
485  }
AnalyzeFunction m_analyzer
Hook function for analysis of data to the stream.
Definition: StreamBuffer.h:172
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:309
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:206
StreamBuffer & writeBytes(const char *str, long len)
Write string to output stream.
Definition: StreamBuffer.h:276

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

503  {
504  STREAM_ANALYSE( pObject, sizeof( pObject ) );
505  addContainedLink( pObject, INVALID, INVALID );
506  return *this;
507  }
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:309
void addContainedLink(const ContainedObject *pObject, long hint, long link)
Definition: StreamBuffer.h:301

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

515  {
516  STREAM_ANALYSE( pObject, sizeof( pObject ) );
517  addIdentifiedLink( pObject, INVALID );
518  return *this;
519  }
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:309
void addIdentifiedLink(const DataObject *pObject, long hint)
Definition: StreamBuffer.h:290

◆ operator>>() [1/14]

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

Input Streamer.

Definition at line 336 of file StreamBuffer.h.

336  {
337  swapFromBuffer( &data, sizeof( data ) );
338  return *this;
339  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:206
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:590

◆ operator>>() [2/14]

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

Input Streamer.

Definition at line 347 of file StreamBuffer.h.

347  {
348  swapFromBuffer( &data, sizeof( data ) );
349  return *this;
350  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:206
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:590

◆ operator>>() [3/14]

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

Input Streamer.

Definition at line 358 of file StreamBuffer.h.

358  {
359  swapFromBuffer( &data, sizeof( data ) );
360  return *this;
361  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:206
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:590

◆ operator>>() [4/14]

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

Input Streamer.

Definition at line 369 of file StreamBuffer.h.

369  {
370  swapFromBuffer( &data, sizeof( data ) );
371  return *this;
372  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:206
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:590

◆ operator>>() [5/14]

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

Input Streamer.

Definition at line 380 of file StreamBuffer.h.

380  {
381  swapFromBuffer( &data, sizeof( data ) );
382  return *this;
383  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:206
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:590

◆ operator>>() [6/14]

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

Input Streamer.

Definition at line 391 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:206
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:590

◆ operator>>() [7/14]

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

Input Streamer.

Definition at line 402 of file StreamBuffer.h.

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

◆ operator>>() [8/14]

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

Input Streamer.

Definition at line 413 of file StreamBuffer.h.

413  {
414  swapFromBuffer( &data, sizeof( data ) );
415  return *this;
416  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:206
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:590

◆ operator>>() [9/14]

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

Input Streamer.

Definition at line 424 of file StreamBuffer.h.

424  {
425  swapFromBuffer( &data, sizeof( data ) );
426  return *this;
427  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:206
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:590

◆ operator>>() [10/14]

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

Input Streamer.

Definition at line 435 of file StreamBuffer.h.

435  {
436  swapFromBuffer( &data, sizeof( data ) );
437  return *this;
438  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:206
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:590

◆ operator>>() [11/14]

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

Input Streamer.

Definition at line 446 of file StreamBuffer.h.

446  {
447  swapFromBuffer( &data, sizeof( data ) );
448  return *this;
449  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:206
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:590

◆ operator>>() [12/14]

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

Streamer to read strings in (char*) format.

Definition at line 451 of file StreamBuffer.h.

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

◆ operator>>() [13/14]

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

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

Definition at line 469 of file StreamBuffer.h.

469  {
470  long i, len;
471  *this >> len;
472  for ( i = 0, data = ""; i < len; i++ ) { data.append( 1, m_buffer[m_pointer++] ); }
473  return *this;
474  }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:160
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:206
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:154

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

493  {
494  return getObjectPointer( refpObject, refpObject );
495  }
StreamBuffer & getObjectPointer(const DataObject *, TYPE *&refpObject)
Helper to distinguish between identified pointers and contained pointers.
Definition: StreamBuffer.h:181

◆ reserve()

void StreamBuffer::reserve ( long  len)
inline

Reserve buffer space; Default: 16 k buffer size.

Definition at line 222 of file StreamBuffer.h.

222  {
223  if ( len > m_length ) {
224  m_length = ( len < 16384 ) ? 16384 : len;
225  m_buffer = (char*)::realloc( m_buffer, m_length );
226  }
227  }
long m_length
Total buffer length.
Definition: StreamBuffer.h:157
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:160
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 527 of file StreamBuffer.h.

527  {
528  ioObject.serialize( *this );
529  m_pointer = 0;
530  }
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:154

◆ setAnalyzer()

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

Enable user analysis function.

Definition at line 268 of file StreamBuffer.h.

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

◆ setBuffPointer()

void StreamBuffer::setBuffPointer ( long  ptr)
inline

Retrieve current buffer pointer.

Definition at line 266 of file StreamBuffer.h.

266 { m_pointer = ptr; }
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:154

◆ setMode()

void StreamBuffer::setMode ( Mode  m)
inline

Set mode of the stream and allocate buffer.

Definition at line 251 of file StreamBuffer.h.

251  {
252  m_mode = m;
253  m_pointer = 0;
256  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:166
T end(T... args)
Mode m_mode
Boolean indicating wether the stream is in read or write mode.
Definition: StreamBuffer.h:151
constexpr double m
T erase(T... args)
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:154
T begin(T... args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:169

◆ size()

long StreamBuffer::size ( ) const
inline

Total buffer size.

Definition at line 239 of file StreamBuffer.h.

239 { return m_length; }
long m_length
Total buffer length.
Definition: StreamBuffer.h:157

◆ swapBuffer()

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

Check for byte swapping.

Definition at line 536 of file StreamBuffer.h.

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

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

590  {
591  char* tar = (char*)target;
592  char* src = m_buffer + m_pointer;
593  switch ( swapBuffer( siz ) ) {
594  case SINGLE_BYTE:
595  *tar = *src;
596  break;
597  case SWAP:
598 #ifdef __APPLE__
599  for ( int i = 0, j = siz - 1; i < siz; i++, j-- ) tar[j] = src[i];
600 #else
601  ::_swab( src, tar, siz );
602 #endif
603  break;
604  case NOSWAP:
605  std::copy_n( src, siz, tar );
606  break;
607  default:
608  break;
609  }
610  m_pointer += siz;
611 }
SwapAction swapBuffer(int siz) const
Check for byte swapping.
Definition: StreamBuffer.h:536
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:160
T copy_n(T... args)
#define _swab(source, target, radix)
Definition: swab.h:17
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:154

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

564  {
565  char buff[8], *tar, *src = (char*)source;
566  extend( m_pointer + siz );
567  tar = m_buffer + m_pointer;
568  switch ( swapBuffer( siz ) ) {
569  case SINGLE_BYTE:
570  *tar = *src;
571  break;
572  case SWAP:
573 #ifdef __APPLE__
574  for ( int i = 0, j = siz - 1; i < siz; i++, j-- ) tar[j] = src[i];
575 #else
576  ::_swab( src, buff, siz );
577 #endif
578  src = buff;
579  [[fallthrough]];
580  case NOSWAP:
581  std::copy_n( src, siz, tar );
582  break;
583  default:
584  break;
585  }
586  m_pointer += siz;
587 }
SwapAction swapBuffer(int siz) const
Check for byte swapping.
Definition: StreamBuffer.h:536
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:160
void extend(long len)
Extend the buffer.
Definition: StreamBuffer.h:229
T copy_n(T... args)
#define _swab(source, target, radix)
Definition: swab.h:17
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:154

◆ writeBytes()

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

Write string to output stream.

Definition at line 276 of file StreamBuffer.h.

276  {
277  extend( m_pointer + len + 4 );
278  *this << len;
279  std::copy_n( str, len, data() + buffPointer() );
280  m_pointer += len;
281  return *this;
282  }
void extend(long len)
Extend the buffer.
Definition: StreamBuffer.h:229
T copy_n(T... args)
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:206
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:154
long buffPointer() const
Retrieve current buffer pointer.
Definition: StreamBuffer.h:264

Friends And Related Function Documentation

◆ DataObject

friend class DataObject
friend

DataObject is friend.

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

◆ m_buffer

char* StreamBuffer::m_buffer = nullptr
mutableprotected

Pointer to heap buffer.

Definition at line 160 of file StreamBuffer.h.

◆ m_containedLinks

ContainedLinks StreamBuffer::m_containedLinks
mutableprotected

Container with links to contained objects.

Definition at line 166 of file StreamBuffer.h.

◆ m_identifiedLinks

IdentifiedLinks StreamBuffer::m_identifiedLinks
mutableprotected

Container with links to contained objects.

Definition at line 169 of file StreamBuffer.h.

◆ m_length

long StreamBuffer::m_length = 0
mutableprotected

Total buffer length.

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

◆ m_pointer

long StreamBuffer::m_pointer = 0
mutableprotected

Current buffer pointer.

Definition at line 154 of file StreamBuffer.h.

◆ m_swapEnabled

bool StreamBuffer::m_swapEnabled = true
protected

Flag indicating swapping.

Definition at line 163 of file StreamBuffer.h.


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