StreamBuffer Class Reference

The stream buffer is a small object collecting object data. More...

#include <GaudiKernel/StreamBuffer.h>

Collaboration diagram for StreamBuffer:

Classes

class  ContainedLink
 Definition of the contained link set. More...
 
class  DataIO
 A small base class to handle generic data streaming. More...
 
class  IdentifiedLink
 Definition of the contained link set. More...
 
class  Istream
 Reader for standard input streams. More...
 
class  Ostream
 Writer for standard output streams. More...
 

Public Types

enum  Mode { UNINITIALIZED, READING, WRITING }
 Streamer mode. More...
 
enum  SwapAction { SINGLE_BYTE, SWAP, NOSWAP }
 Data Sawp actions. More...
 
enum  State { INVALID =-1, VALID }
 Link state defintions. More...
 
typedef std::vector< ContainedLinkContainedLinks
 
typedef std::vector< IdentifiedLinkIdentifiedLinks
 Definition of the identifiable link set. More...
 
typedef void(* AnalyzeFunction) (const void *data, int siz, const std::type_info &type)
 Definition of the buffer analyzer. More...
 

Public Member Functions

 StreamBuffer (bool do_swap=true)
 Standard constructor. More...
 
virtual ~StreamBuffer ()
 Standard destructor. More...
 
const char * data () const
 Read access to data buffer. More...
 
char * data ()
 write access to data buffer More...
 
void erase ()
 Reset the buffer. More...
 
char * adopt () const
 Remove the data buffer and pass it to client. It's the client responsability to free the memory. More...
 
void reserve (long len)
 Reserve buffer space; Default: 16 k buffer size. More...
 
void extend (long len)
 Extend the buffer. More...
 
long size () const
 Total buffer size. More...
 
ContainedLinkscontainedLinks ()
 Access to contained links. More...
 
const ContainedLinkscontainedLinks () const
 CONST Access to contained links. More...
 
IdentifiedLinksidentifiedLinks ()
 Access to identified links. More...
 
const IdentifiedLinksidentifiedLinks () const
 CONST Access to identified links. More...
 
void setMode (Mode m)
 Set mode of the stream and allocate buffer. More...
 
bool isReading () const
 Get stream buffer state. More...
 
bool isWriting () const
 Get stream buffer state. More...
 
long buffPointer () const
 Retrieve current buffer pointer. More...
 
void setBuffPointer (long ptr)
 Retrieve current buffer pointer. More...
 
void setAnalyzer (AnalyzeFunction fun=nullptr)
 Enable user analysis function. More...
 
void swapToBuffer (const void *source, int siz)
 Swap buffers: int, long, short, float and double. More...
 
void swapFromBuffer (void *target, int siz)
 Swap buffers: int, long, short, float and double. More...
 
StreamBufferwriteBytes (const char *str, long len)
 Write string to output stream. More...
 
void getIdentifiedLink (DataObject *&pObject, long &hint)
 
void addIdentifiedLink (const DataObject *pObject, long hint)
 
void getContainedLink (ContainedObject *&pObject, long &hint, long &link)
 
void addContainedLink (const ContainedObject *pObject, long hint, long link)
 
StreamBufferoperator<< (longlong data)
 Output Streamer. More...
 
StreamBufferoperator>> (longlong &data)
 Input Streamer. More...
 
StreamBufferoperator<< (int data)
 Output Streamer. More...
 
StreamBufferoperator>> (int &data)
 Input Streamer. More...
 
StreamBufferoperator<< (unsigned int data)
 Output Streamer. More...
 
StreamBufferoperator>> (unsigned int &data)
 Input Streamer. More...
 
StreamBufferoperator<< (long data)
 Output Streamer. More...
 
StreamBufferoperator>> (long &data)
 Input Streamer. More...
 
StreamBufferoperator<< (unsigned long data)
 Output Streamer. More...
 
StreamBufferoperator>> (unsigned long &data)
 Input Streamer. More...
 
StreamBufferoperator<< (short data)
 Output Streamer. More...
 
StreamBufferoperator>> (short &data)
 Input Streamer. More...
 
StreamBufferoperator<< (unsigned short data)
 Output Streamer. More...
 
StreamBufferoperator>> (unsigned short &data)
 Input Streamer. More...
 
StreamBufferoperator<< (char data)
 Output Streamer. More...
 
StreamBufferoperator>> (char &data)
 Input Streamer. More...
 
StreamBufferoperator<< (unsigned char data)
 Output Streamer. More...
 
StreamBufferoperator>> (unsigned char &data)
 Input Streamer. More...
 
StreamBufferoperator<< (float data)
 Output Streamer. More...
 
StreamBufferoperator>> (float &data)
 Input Streamer. More...
 
StreamBufferoperator<< (double data)
 Output Streamer. More...
 
StreamBufferoperator>> (double &data)
 Input Streamer. More...
 
StreamBufferoperator>> (char *data)
 Streamer to read strings in (char*) format. More...
 
StreamBufferoperator<< (const char *data)
 Streamer to write strings in (char*) format. More...
 
StreamBufferoperator>> (std::string &data)
 Streamer to read strings in (std::string) format. More...
 
StreamBufferoperator<< (const std::string &data)
 Streamer to write strings in (std::string) format. More...
 
template<class TYPE >
StreamBufferoperator>> (TYPE *&refpObject)
 Streamer to read links to contained or identified objects. More...
 
StreamBufferoperator<< (const ContainedObject *pObject)
 Streamer to write links to contained objects. More...
 
StreamBufferoperator<< (const DataObject *pObject)
 Streamer to write links to identified objects. More...
 
void serialize (DataIO &ioObject)
 Serialize the buffer using an IO object. More...
 

Protected Member Functions

SwapAction swapBuffer (int siz) const
 Check for byte swapping. More...
 
template<class TYPE >
StreamBuffergetObjectPointer (const DataObject *, TYPE *&refpObject)
 Helper to distinguish between identified pointers and contained pointers. More...
 
template<class TYPE >
StreamBuffergetObjectPointer (const ContainedObject *, TYPE *&refpObject)
 Helper to distinguish between identified pointers and contained pointers. More...
 

Protected Attributes

Mode m_mode = UNINITIALIZED
 Boolean indicating wether the stream is in read or write mode. More...
 
long m_pointer = 0
 Current buffer pointer. More...
 
long m_length = 0
 Total buffer length. More...
 
char * m_buffer = nullptr
 Pointer to heap buffer. More...
 
bool m_swapEnabled = true
 Flag indicating swapping. More...
 
ContainedLinks m_containedLinks
 Container with links to contained objects. More...
 
IdentifiedLinks m_identifiedLinks
 Container with links to contained objects. More...
 
AnalyzeFunction m_analyzer = nullptr
 Hook function for analysis of data to the stream. More...
 

Friends

class DataObject
 DataObject is friend. More...
 

Detailed Description

The stream buffer is a small object collecting object data.

The basic idea behind the StreamBuffer is generic object conversion. The StreamBuffer acts as a byte stream (hence inheriting from a std::string: DP: this is not true anymore and it is not a bad thing in my opinion) and stores any information streamed to the buffer. Since the information must be represented in a generic way on the fly byte swapping is performed. However, not only primitive data can be stored in the buffer, but also pointers to DataObjects (symbolic links) and pointers to contained objects. Automatically during serialization the persistent references to the corresponding objects and containers must be stored. These objects are accessible from the StreamBuffer object.

"On the fly" data conversion to non persistent

Author
M.Frank

Definition at line 41 of file StreamBuffer.h.

Member Typedef Documentation

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

Definition of the buffer analyzer.

Definition at line 149 of file StreamBuffer.h.

Definition of the identifiable link set.

Definition at line 147 of file StreamBuffer.h.

Member Enumeration Documentation

Streamer mode.

Enumerator
UNINITIALIZED 
READING 
WRITING 

Definition at line 113 of file StreamBuffer.h.

Link state defintions.

Enumerator
INVALID 
VALID 

Definition at line 117 of file StreamBuffer.h.

Data Sawp actions.

Enumerator
SINGLE_BYTE 
SWAP 
NOSWAP 

Definition at line 115 of file StreamBuffer.h.

Constructor & Destructor Documentation

StreamBuffer::StreamBuffer ( bool  do_swap = true)
inline

Standard constructor.

Definition at line 203 of file StreamBuffer.h.

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

Standard destructor.

Definition at line 207 of file StreamBuffer.h.

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

Member Function Documentation

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

Definition at line 332 of file StreamBuffer.h.

332  {
333  m_containedLinks.push_back( ContainedLink((ContainedObject*)pObject, hint, link) );
334  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:170
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 321 of file StreamBuffer.h.

321  {
322  m_identifiedLinks.push_back( IdentifiedLink((DataObject*)pObject, hint) );
323  }
T push_back(T...args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:173
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 223 of file StreamBuffer.h.

223  {
224  char* ptr = m_buffer;
227  m_buffer = NULL; //char *
228  m_pointer = 0; // long
229  m_length = 0; // long
230  return ptr;
231  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:170
long m_length
Total buffer length.
Definition: StreamBuffer.h:161
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:164
T end(T...args)
T erase(T...args)
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:158
T begin(T...args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:173
long StreamBuffer::buffPointer ( ) const
inline

Retrieve current buffer pointer.

Definition at line 289 of file StreamBuffer.h.

289  {
290  return m_pointer;
291  }
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:158
ContainedLinks& StreamBuffer::containedLinks ( )
inline

Access to contained links.

Definition at line 254 of file StreamBuffer.h.

254  {
255  return m_containedLinks;
256  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:170
const ContainedLinks& StreamBuffer::containedLinks ( ) const
inline

CONST Access to contained links.

Definition at line 258 of file StreamBuffer.h.

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

Read access to data buffer.

Definition at line 211 of file StreamBuffer.h.

211  {
212  return m_buffer;
213  }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:164
char* StreamBuffer::data ( )
inline

write access to data buffer

Definition at line 215 of file StreamBuffer.h.

215  {
216  return m_buffer;
217  }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:164
void StreamBuffer::erase ( )
inline

Reset the buffer.

Definition at line 219 of file StreamBuffer.h.

219  {
220  m_pointer = 0;
221  }
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:158
void StreamBuffer::extend ( long  len)
inline

Extend the buffer.

Definition at line 240 of file StreamBuffer.h.

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

Definition at line 325 of file StreamBuffer.h.

325  {
326  ContainedLink& l = m_containedLinks.back();
327  pObject = l.first;
328  hint = l.second;
329  link = l.third;
331  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:170
T pop_back(T...args)
dictionary l
Definition: gaudirun.py:421
T back(T...args)
void StreamBuffer::getIdentifiedLink ( DataObject *&  pObject,
long &  hint 
)
inline

Definition at line 315 of file StreamBuffer.h.

315  {
316  IdentifiedLink& l = m_identifiedLinks.back();
317  pObject = l.first;
318  hint = l.second;
320  }
T pop_back(T...args)
dictionary l
Definition: gaudirun.py:421
T back(T...args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:173
template<class TYPE >
StreamBuffer& StreamBuffer::getObjectPointer ( const DataObject ,
TYPE *&  refpObject 
)
inlineprotected

Helper to distinguish between identified pointers and contained pointers.

This entry resolves identified pointers (= Pointers to DataObject instances.)

Definition at line 184 of file StreamBuffer.h.

184  {
185  IdentifiedLink& link = m_identifiedLinks.back();
186  DataObject* pObj = link.first;
188  refpObject = dynamic_cast<TYPE*>(pObj);
189  return *this;
190  }
T pop_back(T...args)
T back(T...args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:173
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 194 of file StreamBuffer.h.

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

263  {
264  return m_identifiedLinks;
265  }
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:173
const IdentifiedLinks& StreamBuffer::identifiedLinks ( ) const
inline

CONST Access to identified links.

Definition at line 267 of file StreamBuffer.h.

267  {
268  return m_identifiedLinks;
269  }
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:173
bool StreamBuffer::isReading ( ) const
inline

Get stream buffer state.

Definition at line 280 of file StreamBuffer.h.

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

Get stream buffer state.

Definition at line 285 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 360 of file StreamBuffer.h.

360  {
361  swapToBuffer(&data, sizeof(data));
362  STREAM_ANALYSE(data, sizeof(data));
363  return *this;
364  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:598
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:339
StreamBuffer& StreamBuffer::operator<< ( int  data)
inline

Output Streamer.

Definition at line 371 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 382 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 393 of file StreamBuffer.h.

393  {
394  swapToBuffer(&data, sizeof(data));
395  STREAM_ANALYSE(data, sizeof(data));
396  return *this;
397  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:598
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:211
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:339
StreamBuffer& StreamBuffer::operator<< ( unsigned long  data)
inline

Output Streamer.

Definition at line 404 of file StreamBuffer.h.

404  {
405  swapToBuffer(&data, sizeof(data));
406  STREAM_ANALYSE(data, sizeof(data));
407  return *this;
408  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:598
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:211
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:339
StreamBuffer& StreamBuffer::operator<< ( short  data)
inline

Output Streamer.

Definition at line 415 of file StreamBuffer.h.

415  {
416  swapToBuffer(&data, sizeof(data));
417  STREAM_ANALYSE(data, sizeof(data));
418  return *this;
419  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:598
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:211
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:339
StreamBuffer& StreamBuffer::operator<< ( unsigned short  data)
inline

Output Streamer.

Definition at line 426 of file StreamBuffer.h.

426  {
427  swapToBuffer(&data, sizeof(data));
428  STREAM_ANALYSE(data, sizeof(data));
429  return *this;
430  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:598
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:211
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:339
StreamBuffer& StreamBuffer::operator<< ( char  data)
inline

Output Streamer.

Definition at line 437 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 448 of file StreamBuffer.h.

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

Output Streamer.

Definition at line 459 of file StreamBuffer.h.

459  {
460  swapToBuffer(&data, sizeof(data));
461  STREAM_ANALYSE(data, sizeof(data));
462  return *this;
463  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:598
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:211
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:339
StreamBuffer& StreamBuffer::operator<< ( double  data)
inline

Output Streamer.

Definition at line 470 of file StreamBuffer.h.

470  {
471  swapToBuffer(&data, sizeof(data));
472  STREAM_ANALYSE(data, sizeof(data));
473  return *this;
474  }
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:598
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:211
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:339
StreamBuffer& StreamBuffer::operator<< ( const char *  data)
inline

Streamer to write strings in (char*) format.

Definition at line 490 of file StreamBuffer.h.

490  {
491  const char* ptr = 0 == data ? "" : data;
492  int len = strlen(ptr)+1;
493  if ( 0 == m_analyzer )
494  writeBytes(ptr, len);
495  else {
496  STREAM_ANALYSE(data, len);
497  }
498  return *this;
499  }
AnalyzeFunction m_analyzer
Hook function for analysis of data to the stream.
Definition: StreamBuffer.h:176
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:211
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:339
T strlen(T...args)
StreamBuffer & writeBytes(const char *str, long len)
Write string to output stream.
Definition: StreamBuffer.h:307
StreamBuffer& StreamBuffer::operator<< ( const std::string data)
inline

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

Definition at line 510 of file StreamBuffer.h.

510  {
511  if ( 0 == m_analyzer) {
512  const char* ptr = data.c_str();
513  long len = data.length();
514  writeBytes(ptr, len);
515  }
516  else {
517  STREAM_ANALYSE(data, sizeof(data));
518  }
519  return *this;
520  }
AnalyzeFunction m_analyzer
Hook function for analysis of data to the stream.
Definition: StreamBuffer.h:176
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:339
T length(T...args)
T c_str(T...args)
StreamBuffer & writeBytes(const char *str, long len)
Write string to output stream.
Definition: StreamBuffer.h:307
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 537 of file StreamBuffer.h.

537  {
538  STREAM_ANALYSE(pObject, sizeof(pObject));
539  addContainedLink(pObject, INVALID, INVALID);
540  return *this;
541  }
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:339
void addContainedLink(const ContainedObject *pObject, long hint, long link)
Definition: StreamBuffer.h:332
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 549 of file StreamBuffer.h.

549  {
550  STREAM_ANALYSE(pObject, sizeof(pObject));
551  addIdentifiedLink(pObject, INVALID);
552  return *this;
553  }
#define STREAM_ANALYSE(data, len)
Definition: StreamBuffer.h:339
void addIdentifiedLink(const DataObject *pObject, long hint)
Definition: StreamBuffer.h:321
StreamBuffer& StreamBuffer::operator>> ( longlong data)
inline

Input Streamer.

Definition at line 366 of file StreamBuffer.h.

366  {
367  swapFromBuffer(&data, sizeof(data));
368  return *this;
369  }
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:622
StreamBuffer& StreamBuffer::operator>> ( int &  data)
inline

Input Streamer.

Definition at line 377 of file StreamBuffer.h.

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

Input Streamer.

Definition at line 388 of file StreamBuffer.h.

388  {
389  swapFromBuffer(&data, sizeof(data));
390  return *this;
391  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:211
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:622
StreamBuffer& StreamBuffer::operator>> ( long &  data)
inline

Input Streamer.

Definition at line 399 of file StreamBuffer.h.

399  {
400  swapFromBuffer(&data, sizeof(data));
401  return *this;
402  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:211
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:622
StreamBuffer& StreamBuffer::operator>> ( unsigned long &  data)
inline

Input Streamer.

Definition at line 410 of file StreamBuffer.h.

410  {
411  swapFromBuffer(&data, sizeof(data));
412  return *this;
413  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:211
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:622
StreamBuffer& StreamBuffer::operator>> ( short &  data)
inline

Input Streamer.

Definition at line 421 of file StreamBuffer.h.

421  {
422  swapFromBuffer(&data, sizeof(data));
423  return *this;
424  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:211
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:622
StreamBuffer& StreamBuffer::operator>> ( unsigned short &  data)
inline

Input Streamer.

Definition at line 432 of file StreamBuffer.h.

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

Input Streamer.

Definition at line 443 of file StreamBuffer.h.

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

Input Streamer.

Definition at line 454 of file StreamBuffer.h.

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

Input Streamer.

Definition at line 465 of file StreamBuffer.h.

465  {
466  swapFromBuffer(&data, sizeof(data));
467  return *this;
468  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:211
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:622
StreamBuffer& StreamBuffer::operator>> ( double &  data)
inline

Input Streamer.

Definition at line 476 of file StreamBuffer.h.

476  {
477  swapFromBuffer(&data, sizeof(data));
478  return *this;
479  }
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:211
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: StreamBuffer.h:622
StreamBuffer& StreamBuffer::operator>> ( char *  data)
inline

Streamer to read strings in (char*) format.

Definition at line 481 of file StreamBuffer.h.

481  {
482  long i, len;
483  *this >> len;
484  for ( i = 0, data[0]=0; i < len; i++ ) {
485  data[i] = m_buffer[m_pointer++];
486  }
487  return *this;
488  }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:164
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:211
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:158
StreamBuffer& StreamBuffer::operator>> ( std::string data)
inline

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

Definition at line 501 of file StreamBuffer.h.

501  {
502  long i, len;
503  *this >> len;
504  for ( i = 0, data = ""; i < len; i++ ) {
505  data.append( 1, m_buffer[m_pointer++] );
506  }
507  return *this;
508  }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:164
T append(T...args)
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:158
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 527 of file StreamBuffer.h.

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

Reserve buffer space; Default: 16 k buffer size.

Definition at line 233 of file StreamBuffer.h.

233  {
234  if ( len > m_length ) {
235  m_length = (len < 16384) ? 16384 : len;
236  m_buffer = (char*)::realloc (m_buffer,m_length);
237  }
238  }
long m_length
Total buffer length.
Definition: StreamBuffer.h:161
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:164
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 561 of file StreamBuffer.h.

561  {
562  ioObject.serialize ( *this );
563  m_pointer = 0;
564  }
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:158
void StreamBuffer::setAnalyzer ( AnalyzeFunction  fun = nullptr)
inline

Enable user analysis function.

Definition at line 297 of file StreamBuffer.h.

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

Retrieve current buffer pointer.

Definition at line 293 of file StreamBuffer.h.

293  {
294  m_pointer = ptr;
295  }
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:158
void StreamBuffer::setMode ( Mode  m)
inline

Set mode of the stream and allocate buffer.

Definition at line 272 of file StreamBuffer.h.

272  {
273  m_mode = m;
274  m_pointer = 0;
277  }
ContainedLinks m_containedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:170
T end(T...args)
Mode m_mode
Boolean indicating wether the stream is in read or write mode.
Definition: StreamBuffer.h:155
constexpr double m
Definition: SystemOfUnits.h:93
T erase(T...args)
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:158
T begin(T...args)
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
Definition: StreamBuffer.h:173
long StreamBuffer::size ( ) const
inline

Total buffer size.

Definition at line 250 of file StreamBuffer.h.

250  {
251  return m_length;
252  }
long m_length
Total buffer length.
Definition: StreamBuffer.h:161
StreamBuffer::SwapAction StreamBuffer::swapBuffer ( int  siz) const
inlineprotected

Check for byte swapping.

Definition at line 570 of file StreamBuffer.h.

570  {
571  switch(siz) {
572  case 1:
573  return SINGLE_BYTE;
574  default:
575 #if defined(__alpha) && !defined(__VMS)
576 // return m_swapEnabled ? SWAP : NOSWAP;
577  return NOSWAP;
578 #elif defined(__sun) && defined(__SVR4) && defined(__i386)
579 // return m_swapEnabled ? SWAP : NOSWAP;
580  return NOSWAP;
581 #elif defined(__APPLE__)
582 // return m_swapEnabled ? SWAP : NOSWAP;
583  return SWAP;
584 #elif defined(__linux) && !defined(__powerpc)
585 // return m_swapEnabled ? SWAP : NOSWAP;
586  return NOSWAP;
587 #elif defined(BORLAND) || defined(_WIN32) || defined(WIN32)
588 // return m_swapEnabled ? SWAP : NOSWAP;
589  return NOSWAP;
590 #else
591  return m_swapEnabled ? SWAP : NOSWAP;
592 // return NOSWAP;
593 #endif
594  }
595 }
bool m_swapEnabled
Flag indicating swapping.
Definition: StreamBuffer.h:167
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 622 of file StreamBuffer.h.

622  {
623  char* tar = (char*)target;
624  char* src = (char*)m_buffer+m_pointer;
625  switch ( swapBuffer(siz) ) {
626  case SINGLE_BYTE:
627  *tar = *src;
628  break;
629  case SWAP:
630 #ifdef __APPLE__
631  for(int i = 0,j = siz-1;i<siz;i++,j--) tar[j] = src[i];
632 #else
633  ::_swab (src, tar, siz);
634 #endif
635  break;
636  case NOSWAP:
637  std::copy_n(src,siz,tar);
638  break;
639  }
640  m_pointer += siz;
641 }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:164
T copy_n(T...args)
#define _swab(source, target, radix)
Definition: swab.h:7
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:158
SwapAction swapBuffer(int siz) const
Check for byte swapping.
Definition: StreamBuffer.h:570
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 598 of file StreamBuffer.h.

598  {
599  char buff[8], *tar, *src = (char*)source;
600  extend (m_pointer+siz);
601  tar = (char*)m_buffer+m_pointer;
602  switch ( swapBuffer(siz) ) {
603  case SINGLE_BYTE:
604  *tar = *src;
605  break;
606  case SWAP:
607 #ifdef __APPLE__
608  for(int i = 0,j = siz-1;i<siz;i++,j--) tar[j] = src[i];
609 #else
610  ::_swab (src, buff, siz);
611 #endif
612  src = buff;
613  /* no break */
614  case NOSWAP:
615  std::copy_n(src,siz,tar);
616  break;
617  }
618  m_pointer += siz;
619 }
char * m_buffer
Pointer to heap buffer.
Definition: StreamBuffer.h:164
void extend(long len)
Extend the buffer.
Definition: StreamBuffer.h:240
T copy_n(T...args)
#define _swab(source, target, radix)
Definition: swab.h:7
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:158
SwapAction swapBuffer(int siz) const
Check for byte swapping.
Definition: StreamBuffer.h:570
StreamBuffer& StreamBuffer::writeBytes ( const char *  str,
long  len 
)
inline

Write string to output stream.

Definition at line 307 of file StreamBuffer.h.

307  {
308  extend( m_pointer+len+4 );
309  *this << len;
310  std::copy_n(str,len, data()+buffPointer());
311  m_pointer += len;
312  return *this;
313  }
long buffPointer() const
Retrieve current buffer pointer.
Definition: StreamBuffer.h:289
void extend(long len)
Extend the buffer.
Definition: StreamBuffer.h:240
T copy_n(T...args)
const char * data() const
Read access to data buffer.
Definition: StreamBuffer.h:211
long m_pointer
Current buffer pointer.
Definition: StreamBuffer.h:158

Friends And Related Function Documentation

friend class DataObject
friend

DataObject is friend.

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

char* StreamBuffer::m_buffer = nullptr
mutableprotected

Pointer to heap buffer.

Definition at line 164 of file StreamBuffer.h.

ContainedLinks StreamBuffer::m_containedLinks
mutableprotected

Container with links to contained objects.

Definition at line 170 of file StreamBuffer.h.

IdentifiedLinks StreamBuffer::m_identifiedLinks
mutableprotected

Container with links to contained objects.

Definition at line 173 of file StreamBuffer.h.

long StreamBuffer::m_length = 0
mutableprotected

Total buffer length.

Definition at line 161 of file StreamBuffer.h.

Mode StreamBuffer::m_mode = UNINITIALIZED
protected

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

Definition at line 155 of file StreamBuffer.h.

long StreamBuffer::m_pointer = 0
mutableprotected

Current buffer pointer.

Definition at line 158 of file StreamBuffer.h.

bool StreamBuffer::m_swapEnabled = true
protected

Flag indicating swapping.

Definition at line 167 of file StreamBuffer.h.


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