The Gaudi Framework  v31r0 (aeb156f0)
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 41 of file StreamBuffer.h.

Member Typedef Documentation

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

Definition of the buffer analyzer.

Definition at line 136 of file StreamBuffer.h.

Definition of the identifiable link set.

Definition at line 134 of file StreamBuffer.h.

Member Enumeration Documentation

Streamer mode.

Enumerator
UNINITIALIZED 
READING 
WRITING 

Definition at line 107 of file StreamBuffer.h.

Link state defintions.

Enumerator
INVALID 
VALID 

Definition at line 111 of file StreamBuffer.h.

Data Sawp actions.

Enumerator
SINGLE_BYTE 
SWAP 
NOSWAP 

Definition at line 109 of file StreamBuffer.h.

Constructor & Destructor Documentation

StreamBuffer::StreamBuffer ( bool  do_swap = true)
inline

Standard constructor.

Definition at line 193 of file StreamBuffer.h.

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

Standard destructor.

Definition at line 195 of file StreamBuffer.h.

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

Member Function Documentation

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

Definition at line 292 of file StreamBuffer.h.

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

Definition at line 281 of file StreamBuffer.h.

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

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

Definition at line 203 of file StreamBuffer.h.

203  {
204  char* ptr = m_buffer;
207  m_buffer = NULL; // char *
208  m_pointer = 0; // long
209  m_length = 0; // long
210  return ptr;
211  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:157
long m_length
Total buffer length.
Definition: StreamBuffer.h:148
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:151
T end(T...args)
T erase(T...args)
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:145
T begin(T...args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:160
long StreamBuffer::buffPointer ( ) const
inline

Retrieve current buffer pointer.

Definition at line 255 of file StreamBuffer.h.

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

Access to contained links.

Definition at line 232 of file StreamBuffer.h.

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

CONST Access to contained links.

Definition at line 234 of file StreamBuffer.h.

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

Read access to data buffer.

Definition at line 197 of file StreamBuffer.h.

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

write access to data buffer

Definition at line 199 of file StreamBuffer.h.

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

Reset the buffer.

Definition at line 201 of file StreamBuffer.h.

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

Extend the buffer.

Definition at line 220 of file StreamBuffer.h.

220  {
221  if ( len + m_pointer > m_length ) {
222  // We have to be a bit generous here in order not to run too often
223  // into ::realloc().
224  long new_len = ( m_length < 16384 ) ? 16384 : 2 * m_length;
225  if ( m_length < len ) new_len += len;
226  reserve( new_len );
227  }
228  }
long m_length
Total buffer length.
Definition: StreamBuffer.h:148
void reserve(long len)
Reserve buffer space; Default: 16 k buffer size.
Definition: StreamBuffer.h:213
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:145
void StreamBuffer::getContainedLink ( ContainedObject *&  pObject,
long &  hint,
long &  link 
)
inline

Definition at line 285 of file StreamBuffer.h.

285  {
286  ContainedLink& l = m_containedLinks.back();
287  pObject = l.first;
288  hint = l.second;
289  link = l.third;
291  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:157
T pop_back(T...args)
dictionary l
Definition: gaudirun.py:517
T back(T...args)
void StreamBuffer::getIdentifiedLink ( DataObject *&  pObject,
long &  hint 
)
inline

Definition at line 275 of file StreamBuffer.h.

275  {
276  IdentifiedLink& l = m_identifiedLinks.back();
277  pObject = l.first;
278  hint = l.second;
280  }
T pop_back(T...args)
dictionary l
Definition: gaudirun.py:517
T back(T...args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:160
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 172 of file StreamBuffer.h.

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

Helper to distinguish between identified pointers and contained pointers.

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

Definition at line 183 of file StreamBuffer.h.

183  {
184  ContainedLink& link = m_containedLinks.back();
185  ContainedObject* pObj = link.first;
187  refpObject = dynamic_cast<TYPE*>( pObj );
188  return *this;
189  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:157
T pop_back(T...args)
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
T back(T...args)
IdentifiedLinks& StreamBuffer::identifiedLinks ( )
inline

Access to identified links.

Definition at line 237 of file StreamBuffer.h.

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

CONST Access to identified links.

Definition at line 239 of file StreamBuffer.h.

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

Get stream buffer state.

Definition at line 250 of file StreamBuffer.h.

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

Get stream buffer state.

Definition at line 253 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 321 of file StreamBuffer.h.

321  {
322  swapToBuffer( &data, sizeof( data ) );
323  STREAM_ANALYSE( data, sizeof( data ) );
324  return *this;
325  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:555
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:197
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:300
StreamBuffer& StreamBuffer::operator<< ( int  data)
inline

Output Streamer.

Definition at line 332 of file StreamBuffer.h.

332  {
333  swapToBuffer( &data, sizeof( data ) );
334  STREAM_ANALYSE( data, sizeof( data ) );
335  return *this;
336  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:555
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:197
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:300
StreamBuffer& StreamBuffer::operator<< ( unsigned int  data)
inline

Output Streamer.

Definition at line 343 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 354 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 365 of file StreamBuffer.h.

365  {
366  swapToBuffer( &data, sizeof( data ) );
367  STREAM_ANALYSE( data, sizeof( data ) );
368  return *this;
369  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:555
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:197
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:300
StreamBuffer& StreamBuffer::operator<< ( short  data)
inline

Output Streamer.

Definition at line 376 of file StreamBuffer.h.

376  {
377  swapToBuffer( &data, sizeof( data ) );
378  STREAM_ANALYSE( data, sizeof( data ) );
379  return *this;
380  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:555
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:197
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:300
StreamBuffer& StreamBuffer::operator<< ( unsigned short  data)
inline

Output Streamer.

Definition at line 387 of file StreamBuffer.h.

387  {
388  swapToBuffer( &data, sizeof( data ) );
389  STREAM_ANALYSE( data, sizeof( data ) );
390  return *this;
391  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:555
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:197
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:300
StreamBuffer& StreamBuffer::operator<< ( char  data)
inline

Output Streamer.

Definition at line 398 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 409 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 420 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 431 of file StreamBuffer.h.

431  {
432  swapToBuffer( &data, sizeof( data ) );
433  STREAM_ANALYSE( data, sizeof( data ) );
434  return *this;
435  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:555
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:197
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:300
StreamBuffer& StreamBuffer::operator<< ( const char *  data)
inline

Streamer to write strings in (char*) format.

Definition at line 449 of file StreamBuffer.h.

449  {
450  const char* ptr = 0 == data ? "" : data;
451  int len = strlen( ptr ) + 1;
452  if ( 0 == m_analyzer )
453  writeBytes( ptr, len );
454  else {
455  STREAM_ANALYSE( data, len );
456  }
457  return *this;
458  }
AnalyzeFunction m_analyzer
Hook function for analysis of data to the stream.
Definition: StreamBuffer.h:163
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:197
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:300
T strlen(T...args)
StreamBuffer & writeBytes(const char *str, long len)
Write string to output stream.
Definition: StreamBuffer.h:267
StreamBuffer& StreamBuffer::operator<< ( const std::string data)
inline

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

Definition at line 467 of file StreamBuffer.h.

467  {
468  if ( 0 == m_analyzer ) {
469  const char* ptr = data.c_str();
470  long len = data.length();
471  writeBytes( ptr, len );
472  } else {
473  STREAM_ANALYSE( data, sizeof( data ) );
474  }
475  return *this;
476  }
AnalyzeFunction m_analyzer
Hook function for analysis of data to the stream.
Definition: StreamBuffer.h:163
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:300
T length(T...args)
T c_str(T...args)
StreamBuffer & writeBytes(const char *str, long len)
Write string to output stream.
Definition: StreamBuffer.h:267
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 494 of file StreamBuffer.h.

494  {
495  STREAM_ANALYSE( pObject, sizeof( pObject ) );
496  addContainedLink( pObject, INVALID, INVALID );
497  return *this;
498  }
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:300
void addContainedLink(const ContainedObject *pObject, long hint, long link)
Definition: StreamBuffer.h:292
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 506 of file StreamBuffer.h.

506  {
507  STREAM_ANALYSE( pObject, sizeof( pObject ) );
508  addIdentifiedLink( pObject, INVALID );
509  return *this;
510  }
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:300
void addIdentifiedLink(const DataObject *pObject, long hint)
Definition: StreamBuffer.h:281
StreamBuffer& StreamBuffer::operator>> ( long long &  data)
inline

Input Streamer.

Definition at line 327 of file StreamBuffer.h.

327  {
328  swapFromBuffer( &data, sizeof( data ) );
329  return *this;
330  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:197
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:581
StreamBuffer& StreamBuffer::operator>> ( int &  data)
inline

Input Streamer.

Definition at line 338 of file StreamBuffer.h.

338  {
339  swapFromBuffer( &data, sizeof( data ) );
340  return *this;
341  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:197
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:581
StreamBuffer& StreamBuffer::operator>> ( unsigned int &  data)
inline

Input Streamer.

Definition at line 349 of file StreamBuffer.h.

349  {
350  swapFromBuffer( &data, sizeof( data ) );
351  return *this;
352  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:197
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:581
StreamBuffer& StreamBuffer::operator>> ( long &  data)
inline

Input Streamer.

Definition at line 360 of file StreamBuffer.h.

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

Input Streamer.

Definition at line 371 of file StreamBuffer.h.

371  {
372  swapFromBuffer( &data, sizeof( data ) );
373  return *this;
374  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:197
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:581
StreamBuffer& StreamBuffer::operator>> ( short &  data)
inline

Input Streamer.

Definition at line 382 of file StreamBuffer.h.

382  {
383  swapFromBuffer( &data, sizeof( data ) );
384  return *this;
385  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:197
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:581
StreamBuffer& StreamBuffer::operator>> ( unsigned short &  data)
inline

Input Streamer.

Definition at line 393 of file StreamBuffer.h.

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

Input Streamer.

Definition at line 404 of file StreamBuffer.h.

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

Input Streamer.

Definition at line 415 of file StreamBuffer.h.

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

Input Streamer.

Definition at line 426 of file StreamBuffer.h.

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

Input Streamer.

Definition at line 437 of file StreamBuffer.h.

437  {
438  swapFromBuffer( &data, sizeof( data ) );
439  return *this;
440  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:197
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:581
StreamBuffer& StreamBuffer::operator>> ( char *  data)
inline

Streamer to read strings in (char*) format.

Definition at line 442 of file StreamBuffer.h.

442  {
443  long i, len;
444  *this >> len;
445  for ( i = 0, data[0] = 0; i < len; i++ ) { data[i] = m_buffer[m_pointer++]; }
446  return *this;
447  }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:151
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:197
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:145
StreamBuffer& StreamBuffer::operator>> ( std::string data)
inline

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

Definition at line 460 of file StreamBuffer.h.

460  {
461  long i, len;
462  *this >> len;
463  for ( i = 0, data = ""; i < len; i++ ) { data.append( 1, m_buffer[m_pointer++] ); }
464  return *this;
465  }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:151
T append(T...args)
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:145
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 484 of file StreamBuffer.h.

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

Reserve buffer space; Default: 16 k buffer size.

Definition at line 213 of file StreamBuffer.h.

213  {
214  if ( len > m_length ) {
215  m_length = ( len < 16384 ) ? 16384 : len;
216  m_buffer = (char*)::realloc( m_buffer, m_length );
217  }
218  }
long m_length
Total buffer length.
Definition: StreamBuffer.h:148
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:151
T realloc(T...args)
void StreamBuffer::serialize ( DataIO ioObject)
inline

Serialize the buffer using an IO object.

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

Parameters
ioObjectReference to data IO object.

Definition at line 518 of file StreamBuffer.h.

518  {
519  ioObject.serialize( *this );
520  m_pointer = 0;
521  }
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:145
void StreamBuffer::setAnalyzer ( AnalyzeFunction  fun = nullptr)
inline

Enable user analysis function.

Definition at line 259 of file StreamBuffer.h.

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

Retrieve current buffer pointer.

Definition at line 257 of file StreamBuffer.h.

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

Set mode of the stream and allocate buffer.

Definition at line 242 of file StreamBuffer.h.

242  {
243  m_mode = m;
244  m_pointer = 0;
247  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:157
T end(T...args)
Mode m_mode
Boolean indicating wether the stream is in read or write mode.
Definition: StreamBuffer.h:142
constexpr double m
Definition: SystemOfUnits.h:92
T erase(T...args)
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:145
T begin(T...args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:160
long StreamBuffer::size ( ) const
inline

Total buffer size.

Definition at line 230 of file StreamBuffer.h.

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

Check for byte swapping.

Definition at line 527 of file StreamBuffer.h.

527  {
528  switch ( siz ) {
529  case 1:
530  return SINGLE_BYTE;
531  default:
532 #if defined( __alpha ) && !defined( __VMS )
533  // return m_swapEnabled ? SWAP : NOSWAP;
534  return NOSWAP;
535 #elif defined( __sun ) && defined( __SVR4 ) && defined( __i386 )
536  // return m_swapEnabled ? SWAP : NOSWAP;
537  return NOSWAP;
538 #elif defined( __APPLE__ )
539  // return m_swapEnabled ? SWAP : NOSWAP;
540  return SWAP;
541 #elif defined( __linux ) && !defined( __powerpc )
542  // return m_swapEnabled ? SWAP : NOSWAP;
543  return NOSWAP;
544 #elif defined( BORLAND ) || defined( _WIN32 ) || defined( WIN32 )
545  // return m_swapEnabled ? SWAP : NOSWAP;
546  return NOSWAP;
547 #else
548  return m_swapEnabled ? SWAP : NOSWAP;
549 // return NOSWAP;
550 #endif
551  }
552 }
bool m_swapEnabled
Flag indicating swapping.
Definition: StreamBuffer.h:154
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 581 of file StreamBuffer.h.

581  {
582  char* tar = (char*)target;
583  char* src = m_buffer + m_pointer;
584  switch ( swapBuffer( siz ) ) {
585  case SINGLE_BYTE:
586  *tar = *src;
587  break;
588  case SWAP:
589 #ifdef __APPLE__
590  for ( int i = 0, j = siz - 1; i < siz; i++, j-- ) tar[j] = src[i];
591 #else
592  ::_swab( src, tar, siz );
593 #endif
594  break;
595  case NOSWAP:
596  std::copy_n( src, siz, tar );
597  break;
598  default:
599  break;
600  }
601  m_pointer += siz;
602 }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:151
T copy_n(T...args)
#define _swab(source, target, radix)
Definition: swab.h:7
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:145
SwapAction swapBuffer(int siz) const
Check for byte swapping.
Definition: StreamBuffer.h:527
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 555 of file StreamBuffer.h.

555  {
556  char buff[8], *tar, *src = (char*)source;
557  extend( m_pointer + siz );
558  tar = m_buffer + m_pointer;
559  switch ( swapBuffer( siz ) ) {
560  case SINGLE_BYTE:
561  *tar = *src;
562  break;
563  case SWAP:
564 #ifdef __APPLE__
565  for ( int i = 0, j = siz - 1; i < siz; i++, j-- ) tar[j] = src[i];
566 #else
567  ::_swab( src, buff, siz );
568 #endif
569  src = buff;
570  /* FALLTHROUGH */
571  case NOSWAP:
572  std::copy_n( src, siz, tar );
573  break;
574  default:
575  break;
576  }
577  m_pointer += siz;
578 }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:151
void extend(long len)
Extend the buffer.
Definition: StreamBuffer.h:220
T copy_n(T...args)
#define _swab(source, target, radix)
Definition: swab.h:7
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:145
SwapAction swapBuffer(int siz) const
Check for byte swapping.
Definition: StreamBuffer.h:527
StreamBuffer& StreamBuffer::writeBytes ( const char *  str,
long  len 
)
inline

Write string to output stream.

Definition at line 267 of file StreamBuffer.h.

267  {
268  extend( m_pointer + len + 4 );
269  *this << len;
270  std::copy_n( str, len, data() + buffPointer() );
271  m_pointer += len;
272  return *this;
273  }
long buffPointer() const
Retrieve current buffer pointer.
Definition: StreamBuffer.h:255
void extend(long len)
Extend the buffer.
Definition: StreamBuffer.h:220
T copy_n(T...args)
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:197
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:145

Friends And Related Function Documentation

friend class DataObject
friend

DataObject is friend.

Definition at line 138 of file StreamBuffer.h.

Member Data Documentation

AnalyzeFunction StreamBuffer::m_analyzer = nullptr
protected

Hook function for analysis of data to the stream.

Definition at line 163 of file StreamBuffer.h.

char* StreamBuffer::m_buffer = nullptr
mutableprotected

Pointer to heap buffer.

Definition at line 151 of file StreamBuffer.h.

ContainedLinks StreamBuffer::m_containedLinks
mutableprotected

Container with links to contained objects.

Definition at line 157 of file StreamBuffer.h.

IdentifiedLinks StreamBuffer::m_identifiedLinks
mutableprotected

Container with links to contained objects.

Definition at line 160 of file StreamBuffer.h.

long StreamBuffer::m_length = 0
mutableprotected

Total buffer length.

Definition at line 148 of file StreamBuffer.h.

Mode StreamBuffer::m_mode = UNINITIALIZED
protected

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

Definition at line 142 of file StreamBuffer.h.

long StreamBuffer::m_pointer = 0
mutableprotected

Current buffer pointer.

Definition at line 145 of file StreamBuffer.h.

bool StreamBuffer::m_swapEnabled = true
protected

Flag indicating swapping.

Definition at line 154 of file StreamBuffer.h.


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