The Gaudi Framework  master (fb0007c6)
Loading...
Searching...
No Matches
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.
 
typedef void(* AnalyzeFunction) (const void *data, int siz, const std::type_info &type)
 Definition of the buffer analyzer.
 

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

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

Friends

class DataObject
 DataObject is friend.
 

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

◆ ContainedLinks

Definition at line 140 of file StreamBuffer.h.

◆ IdentifiedLinks

Definition of the identifiable link set.

Definition at line 142 of file StreamBuffer.h.

Member Enumeration Documentation

◆ Mode

Streamer mode.

Enumerator
UNINITIALIZED 
READING 
WRITING 

Definition at line 113 of file StreamBuffer.h.

◆ State

Link state defintions.

Enumerator
INVALID 
VALID 

Definition at line 117 of file StreamBuffer.h.

◆ SwapAction

Data Sawp actions.

Enumerator
SINGLE_BYTE 
SWAP 
NOSWAP 

Definition at line 115 of file StreamBuffer.h.

Constructor & Destructor Documentation

◆ StreamBuffer()

StreamBuffer::StreamBuffer ( bool do_swap = true)
inline

Standard constructor.

Definition at line 201 of file StreamBuffer.h.

201: m_swapEnabled( do_swap ) {}
bool m_swapEnabled
Flag indicating swapping.

◆ ~StreamBuffer()

virtual StreamBuffer::~StreamBuffer ( )
inlinevirtual

Standard destructor.

Definition at line 203 of file StreamBuffer.h.

203{ ::free( m_buffer ); }
char * m_buffer
Pointer to heap buffer.

Member Function Documentation

◆ addContainedLink()

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

Definition at line 300 of file StreamBuffer.h.

300 {
301 m_containedLinks.push_back( ContainedLink( (ContainedObject*)pObject, hint, link ) );
302 }
ContainedLinks m_containedLinks
Container with links to contained objects.

◆ addIdentifiedLink()

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

Definition at line 289 of file StreamBuffer.h.

289 {
290 m_identifiedLinks.push_back( IdentifiedLink( (DataObject*)pObject, hint ) );
291 }
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
friend class DataObject
DataObject is friend.

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

211 {
212 char* ptr = m_buffer;
213 m_containedLinks.erase( m_containedLinks.begin(), m_containedLinks.end() );
215 m_buffer = NULL; // char *
216 m_pointer = 0; // long
217 m_length = 0; // long
218 return ptr;
219 }
long m_pointer
Current buffer pointer.
long m_length
Total buffer length.

◆ buffPointer()

long StreamBuffer::buffPointer ( ) const
inline

Retrieve current buffer pointer.

Definition at line 263 of file StreamBuffer.h.

263{ return m_pointer; }

◆ containedLinks() [1/2]

ContainedLinks & StreamBuffer::containedLinks ( )
inline

Access to contained links.

Definition at line 240 of file StreamBuffer.h.

240{ return m_containedLinks; }

◆ containedLinks() [2/2]

const ContainedLinks & StreamBuffer::containedLinks ( ) const
inline

CONST Access to contained links.

Definition at line 242 of file StreamBuffer.h.

242{ return m_containedLinks; }

◆ data() [1/2]

char * StreamBuffer::data ( )
inline

write access to data buffer

Definition at line 207 of file StreamBuffer.h.

207{ return m_buffer; }

◆ data() [2/2]

const char * StreamBuffer::data ( ) const
inline

Read access to data buffer.

Definition at line 205 of file StreamBuffer.h.

205{ return m_buffer; }

◆ erase()

void StreamBuffer::erase ( )
inline

Reset the buffer.

Definition at line 209 of file StreamBuffer.h.

209{ m_pointer = 0; }

◆ extend()

void StreamBuffer::extend ( long len)
inline

Extend the buffer.

Definition at line 228 of file StreamBuffer.h.

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

◆ getContainedLink()

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

Definition at line 293 of file StreamBuffer.h.

293 {
295 pObject = l.first;
296 hint = l.second;
297 link = l.third;
298 m_containedLinks.pop_back();
299 }
dict l
Definition gaudirun.py:583

◆ getIdentifiedLink()

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

Definition at line 283 of file StreamBuffer.h.

283 {
285 pObject = l.first;
286 hint = l.second;
287 m_identifiedLinks.pop_back();
288 }

◆ getObjectPointer() [1/2]

template<class TYPE>
StreamBuffer & StreamBuffer::getObjectPointer ( const ContainedObject * ,
TYPE *& refpObject )
inlineprotected

Helper to distinguish between identified pointers and contained pointers.

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

Definition at line 191 of file StreamBuffer.h.

191 {
192 ContainedLink& link = m_containedLinks.back();
193 ContainedObject* pObj = link.first;
194 m_containedLinks.pop_back();
195 refpObject = dynamic_cast<TYPE*>( pObj );
196 return *this;
197 }

◆ getObjectPointer() [2/2]

template<class TYPE>
StreamBuffer & StreamBuffer::getObjectPointer ( const DataObject * ,
TYPE *& refpObject )
inlineprotected

Helper to distinguish between identified pointers and contained pointers.

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

Definition at line 180 of file StreamBuffer.h.

180 {
181 IdentifiedLink& link = m_identifiedLinks.back();
182 DataObject* pObj = link.first;
183 m_identifiedLinks.pop_back();
184 refpObject = dynamic_cast<TYPE*>( pObj );
185 return *this;
186 }

◆ identifiedLinks() [1/2]

IdentifiedLinks & StreamBuffer::identifiedLinks ( )
inline

Access to identified links.

Definition at line 245 of file StreamBuffer.h.

245{ return m_identifiedLinks; }

◆ identifiedLinks() [2/2]

const IdentifiedLinks & StreamBuffer::identifiedLinks ( ) const
inline

CONST Access to identified links.

Definition at line 247 of file StreamBuffer.h.

247{ return m_identifiedLinks; }

◆ isReading()

bool StreamBuffer::isReading ( ) const
inline

Get stream buffer state.

Definition at line 258 of file StreamBuffer.h.

258{ return m_mode == READING; }
Mode m_mode
Boolean indicating wether the stream is in read or write mode.

◆ isWriting()

bool StreamBuffer::isWriting ( ) const
inline

Get stream buffer state.

Definition at line 261 of file StreamBuffer.h.

261{ return m_mode == WRITING; }

◆ operator<<() [1/15]

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

Output Streamer.

Definition at line 406 of file StreamBuffer.h.

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

◆ operator<<() [2/15]

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

Streamer to write strings in (char*) format.

Definition at line 457 of file StreamBuffer.h.

457 {
458 const char* ptr = 0 == data ? "" : data;
459 size_t len = strlen( ptr ) + 1;
460 if ( 0 == m_analyzer )
461 writeBytes( ptr, len );
462 else { STREAM_ANALYSE( data, len ); }
463 return *this;
464 }
AnalyzeFunction m_analyzer
Hook function for analysis of data to the stream.
StreamBuffer & writeBytes(const char *str, long len)
Write string to output stream.

◆ operator<<() [3/15]

StreamBuffer & StreamBuffer::operator<< ( const ContainedObject * pObject)
inline

Streamer to write links to contained objects.

Links to contained objects are not stored immediately, but collected instead and analyzed later.

Parameters
pObjectPointer to object to be loaded.
Returns
Reference to StreamBuffer object

Definition at line 500 of file StreamBuffer.h.

500 {
501 STREAM_ANALYSE( pObject, sizeof( pObject ) );
502 addContainedLink( pObject, INVALID, INVALID );
503 return *this;
504 }
void addContainedLink(const ContainedObject *pObject, long hint, long link)

◆ operator<<() [4/15]

StreamBuffer & StreamBuffer::operator<< ( const DataObject * pObject)
inline

Streamer to write links to identified objects.

Links to identified objects are not stored immediately, but collected instead and analyzed later.

Parameters
pObjectPointer to object to be loaded.
Returns
Reference to StreamBuffer object

Definition at line 512 of file StreamBuffer.h.

512 {
513 STREAM_ANALYSE( pObject, sizeof( pObject ) );
514 addIdentifiedLink( pObject, INVALID );
515 return *this;
516 }
void addIdentifiedLink(const DataObject *pObject, long hint)

◆ operator<<() [5/15]

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

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

Definition at line 473 of file StreamBuffer.h.

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

◆ operator<<() [6/15]

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

Output Streamer.

Definition at line 439 of file StreamBuffer.h.

439 {
440 swapToBuffer( &data, sizeof( data ) );
441 STREAM_ANALYSE( data, sizeof( data ) );
442 return *this;
443 }

◆ operator<<() [7/15]

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

Output Streamer.

Definition at line 428 of file StreamBuffer.h.

428 {
429 swapToBuffer( &data, sizeof( data ) );
430 STREAM_ANALYSE( data, sizeof( data ) );
431 return *this;
432 }

◆ operator<<() [8/15]

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

Output Streamer.

Definition at line 340 of file StreamBuffer.h.

340 {
341 swapToBuffer( &data, sizeof( data ) );
342 STREAM_ANALYSE( data, sizeof( data ) );
343 return *this;
344 }

◆ operator<<() [9/15]

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

Output Streamer.

Definition at line 362 of file StreamBuffer.h.

362 {
363 swapToBuffer( &data, sizeof( data ) );
364 STREAM_ANALYSE( data, sizeof( data ) );
365 return *this;
366 }

◆ operator<<() [10/15]

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

Output Streamer.

Definition at line 329 of file StreamBuffer.h.

329 {
330 swapToBuffer( &data, sizeof( data ) );
331 STREAM_ANALYSE( data, sizeof( data ) );
332 return *this;
333 }

◆ operator<<() [11/15]

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

Output Streamer.

Definition at line 384 of file StreamBuffer.h.

384 {
385 swapToBuffer( &data, sizeof( data ) );
386 STREAM_ANALYSE( data, sizeof( data ) );
387 return *this;
388 }

◆ operator<<() [12/15]

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

Output Streamer.

Definition at line 417 of file StreamBuffer.h.

417 {
418 swapToBuffer( &data, sizeof( data ) );
419 STREAM_ANALYSE( data, sizeof( data ) );
420 return *this;
421 }

◆ operator<<() [13/15]

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

Output Streamer.

Definition at line 351 of file StreamBuffer.h.

351 {
352 swapToBuffer( &data, sizeof( data ) );
353 STREAM_ANALYSE( data, sizeof( data ) );
354 return *this;
355 }

◆ operator<<() [14/15]

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

Output Streamer.

Definition at line 373 of file StreamBuffer.h.

373 {
374 swapToBuffer( &data, sizeof( data ) );
375 STREAM_ANALYSE( data, sizeof( data ) );
376 return *this;
377 }

◆ operator<<() [15/15]

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

Output Streamer.

Definition at line 395 of file StreamBuffer.h.

395 {
396 swapToBuffer( &data, sizeof( data ) );
397 STREAM_ANALYSE( data, sizeof( data ) );
398 return *this;
399 }

◆ operator>>() [1/14]

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

Input Streamer.

Definition at line 412 of file StreamBuffer.h.

412 {
413 swapFromBuffer( &data, sizeof( data ) );
414 return *this;
415 }
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.

◆ operator>>() [2/14]

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

Streamer to read strings in (char*) format.

Definition at line 450 of file StreamBuffer.h.

450 {
451 long i, len;
452 *this >> len;
453 for ( i = 0, data[0] = 0; i < len; i++ ) { data[i] = m_buffer[m_pointer++]; }
454 return *this;
455 }

◆ operator>>() [3/14]

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

Input Streamer.

Definition at line 445 of file StreamBuffer.h.

445 {
446 swapFromBuffer( &data, sizeof( data ) );
447 return *this;
448 }

◆ operator>>() [4/14]

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

Input Streamer.

Definition at line 434 of file StreamBuffer.h.

434 {
435 swapFromBuffer( &data, sizeof( data ) );
436 return *this;
437 }

◆ operator>>() [5/14]

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

Input Streamer.

Definition at line 346 of file StreamBuffer.h.

346 {
347 swapFromBuffer( &data, sizeof( data ) );
348 return *this;
349 }

◆ operator>>() [6/14]

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

Input Streamer.

Definition at line 368 of file StreamBuffer.h.

368 {
369 swapFromBuffer( &data, sizeof( data ) );
370 return *this;
371 }

◆ operator>>() [7/14]

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

Input Streamer.

Definition at line 335 of file StreamBuffer.h.

335 {
336 swapFromBuffer( &data, sizeof( data ) );
337 return *this;
338 }

◆ operator>>() [8/14]

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

Input Streamer.

Definition at line 390 of file StreamBuffer.h.

390 {
391 swapFromBuffer( &data, sizeof( data ) );
392 return *this;
393 }

◆ operator>>() [9/14]

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

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

Definition at line 466 of file StreamBuffer.h.

466 {
467 long i, len;
468 *this >> len;
469 for ( i = 0, data = ""; i < len; i++ ) { data.append( 1, m_buffer[m_pointer++] ); }
470 return *this;
471 }

◆ operator>>() [10/14]

template<class TYPE>
StreamBuffer & StreamBuffer::operator>> ( TYPE *& refpObject)
inline

Streamer to read links to contained or identified objects.

The specified internal function call distinguishes between contained and identified objects.

Parameters
refpObjectReference to pointer to object to be loaded.
Returns
Reference to StreamBuffer object

Definition at line 490 of file StreamBuffer.h.

490 {
491 return getObjectPointer( refpObject, refpObject );
492 }
StreamBuffer & getObjectPointer(const DataObject *, TYPE *&refpObject)
Helper to distinguish between identified pointers and contained pointers.

◆ operator>>() [11/14]

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

Input Streamer.

Definition at line 423 of file StreamBuffer.h.

423 {
424 swapFromBuffer( &data, sizeof( data ) );
425 return *this;
426 }

◆ operator>>() [12/14]

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

Input Streamer.

Definition at line 357 of file StreamBuffer.h.

357 {
358 swapFromBuffer( &data, sizeof( data ) );
359 return *this;
360 }

◆ operator>>() [13/14]

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

Input Streamer.

Definition at line 379 of file StreamBuffer.h.

379 {
380 swapFromBuffer( &data, sizeof( data ) );
381 return *this;
382 }

◆ operator>>() [14/14]

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

Input Streamer.

Definition at line 401 of file StreamBuffer.h.

401 {
402 swapFromBuffer( &data, sizeof( data ) );
403 return *this;
404 }

◆ reserve()

void StreamBuffer::reserve ( long len)
inline

Reserve buffer space; Default: 16 k buffer size.

Definition at line 221 of file StreamBuffer.h.

221 {
222 if ( len > m_length ) {
223 m_length = ( len < 16384 ) ? 16384 : len;
224 m_buffer = (char*)::realloc( m_buffer, m_length );
225 }
226 }

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

524 {
525 ioObject.serialize( *this );
526 m_pointer = 0;
527 }

◆ setAnalyzer()

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

Enable user analysis function.

Definition at line 267 of file StreamBuffer.h.

267{ m_analyzer = fun; }

◆ setBuffPointer()

void StreamBuffer::setBuffPointer ( long ptr)
inline

Retrieve current buffer pointer.

Definition at line 265 of file StreamBuffer.h.

265{ m_pointer = ptr; }

◆ setMode()

void StreamBuffer::setMode ( Mode m)
inline

Set mode of the stream and allocate buffer.

Definition at line 250 of file StreamBuffer.h.

250 {
251 m_mode = m;
252 m_pointer = 0;
253 m_containedLinks.erase( m_containedLinks.begin(), m_containedLinks.end() );
255 }
constexpr double m

◆ size()

long StreamBuffer::size ( ) const
inline

Total buffer size.

Definition at line 238 of file StreamBuffer.h.

238{ return m_length; }

◆ swapBuffer()

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

Check for byte swapping.

Definition at line 533 of file StreamBuffer.h.

533 {
534 switch ( siz ) {
535 case 1:
536 return SINGLE_BYTE;
537 default:
538#if defined( __alpha ) && !defined( __VMS )
539 // return m_swapEnabled ? SWAP : NOSWAP;
540 return NOSWAP;
541#elif defined( __sun ) && defined( __SVR4 ) && defined( __i386 )
542 // return m_swapEnabled ? SWAP : NOSWAP;
543 return NOSWAP;
544#elif defined( __APPLE__ )
545 // return m_swapEnabled ? SWAP : NOSWAP;
546 return SWAP;
547#elif defined( __linux ) && !defined( __powerpc )
548 // return m_swapEnabled ? SWAP : NOSWAP;
549 return NOSWAP;
550#else
551 return m_swapEnabled ? SWAP : NOSWAP;
552// return NOSWAP;
553#endif
554 }
555}

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

584 {
585 char* tar = (char*)target;
586 char* src = m_buffer + m_pointer;
587 switch ( swapBuffer( siz ) ) {
588 case SINGLE_BYTE:
589 *tar = *src;
590 break;
591 case SWAP:
592#ifdef __APPLE__
593 for ( int i = 0, j = siz - 1; i < siz; i++, j-- ) tar[j] = src[i];
594#else
595 ::swab( src, tar, siz );
596#endif
597 break;
598 case NOSWAP:
599 std::copy_n( src, siz, tar );
600 break;
601 default:
602 break;
603 }
604 m_pointer += siz;
605}
SwapAction swapBuffer(int siz) const
Check for byte swapping.

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

558 {
559 char buff[8], *tar, *src = (char*)source;
560 extend( m_pointer + siz );
561 tar = m_buffer + m_pointer;
562 switch ( swapBuffer( siz ) ) {
563 case SINGLE_BYTE:
564 *tar = *src;
565 break;
566 case SWAP:
567#ifdef __APPLE__
568 for ( int i = 0, j = siz - 1; i < siz; i++, j-- ) tar[j] = src[i];
569#else
570 ::swab( src, buff, siz );
571#endif
572 src = buff;
573 [[fallthrough]];
574 case NOSWAP:
575 std::copy_n( src, siz, tar );
576 break;
577 default:
578 break;
579 }
580 m_pointer += siz;
581}
void extend(long len)
Extend the buffer.

◆ writeBytes()

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

Write string to output stream.

Definition at line 275 of file StreamBuffer.h.

275 {
276 extend( m_pointer + len + 4 );
277 *this << len;
278 std::copy_n( str, len, data() + buffPointer() );
279 m_pointer += len;
280 return *this;
281 }
long buffPointer() const
Retrieve current buffer pointer.

Friends And Related Symbol Documentation

◆ DataObject

friend class DataObject
friend

DataObject is friend.

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

◆ m_buffer

char* StreamBuffer::m_buffer = nullptr
mutableprotected

Pointer to heap buffer.

Definition at line 159 of file StreamBuffer.h.

◆ m_containedLinks

ContainedLinks StreamBuffer::m_containedLinks
mutableprotected

Container with links to contained objects.

Definition at line 165 of file StreamBuffer.h.

◆ m_identifiedLinks

IdentifiedLinks StreamBuffer::m_identifiedLinks
mutableprotected

Container with links to contained objects.

Definition at line 168 of file StreamBuffer.h.

◆ m_length

long StreamBuffer::m_length = 0
mutableprotected

Total buffer length.

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

◆ m_pointer

long StreamBuffer::m_pointer = 0
mutableprotected

Current buffer pointer.

Definition at line 153 of file StreamBuffer.h.

◆ m_swapEnabled

bool StreamBuffer::m_swapEnabled = true
protected

Flag indicating swapping.

Definition at line 162 of file StreamBuffer.h.


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