1. binet
  2. mana-core-gaudikernel

Source

mana-core-gaudikernel / GaudiKernel / StreamBuffer.h

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
// $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/GaudiKernel/StreamBuffer.h,v 1.9 2008/10/27 16:41:33 marcocle Exp $
#ifndef GAUDIKERNEL_STREAMBUFFER_H
#define GAUDIKERNEL_STREAMBUFFER_H 1

// STL include files
#include <list>
#include <vector>
#include <string>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <typeinfo>

#include "GaudiKernel/Kernel.h"
#include "GaudiKernel/swab.h"

// forward declarations
class StreamBuffer;
class DataObject;
class ContainedObject;

/** @class StreamBuffer StreamBuffer.h GaudiKernel/StreamBuffer.h

    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) 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
*/
class StreamBuffer /* : public std::string  */  {
public:
  /// A small base class to handle generic data streaming
  class DataIO   {
  public:
    /// Standard constructor
    DataIO()    {
    }
    /// Standard destructor
    virtual ~DataIO()    {
    }
    /// Throw Exception
    void badStreamMode()    {
      throw("Not acceptable stream mode!");
    }
    /// Serialization method: loads/dumps streambuffer content
    virtual void serialize(StreamBuffer& stream)   {
      if (stream.isReading())
        load(stream);
      else if (stream.isWriting())
        dump(stream);
      else
        badStreamMode();
    }
    /// Template function to load stream data
    virtual void load(StreamBuffer&)   {
      badStreamMode();
    }
    /// Template function to save stream data
    virtual void dump(StreamBuffer&)   {
      badStreamMode();
    }
  };

  /// Reader for standard input streams
  class Istream : public DataIO  {
    /// Reference to input stream
    std::istream* m_stream;
  public:
    /// Constructor
    Istream(std::istream& str) : m_stream(&str)   {
    }
    /// Destructor
    virtual ~Istream()  {
    }
    /// Data load method
    virtual void load(StreamBuffer& stream)   {
      // Generic implementation for istreams:
      int  len;
      (*m_stream) >> len;
      stream.erase();
      stream.reserve(len);
      m_stream->read(stream.data(),len);
    }
  };
  /// Writer for standard output streams
  class Ostream : public DataIO  {
    std::ostream* m_stream;
  public:
    /// Standard constructor: pass reference to stream object
    Ostream(std::ostream& str) : m_stream(&str)   {
    }
    /// Standard Destructor
    virtual ~Ostream()  {
    }
    /// Output dumper
    virtual void dump(StreamBuffer& stream)   {
      // Generic implementation for ostreams:
      (*m_stream) << stream.buffPointer();
      m_stream->write(stream.data(), stream.buffPointer());
    }
  };
public:
  /// Streamer mode
  enum Mode       {UNINITIALIZED, READING, WRITING};
  /// Data Sawp actions
  enum SwapAction {SINGLE_BYTE, SWAP, NOSWAP};
  /// Link state defintions
  enum    State   {INVALID=-1, VALID };
  /// Definition of the contained link set
  class ContainedLink   {
  public:
    ContainedObject* first;
    long second;
    long third;
    ContainedLink() : first(0), second(INVALID), third(INVALID)  {
    }
    ContainedLink(const ContainedLink& copy)
      : first(copy.first), second(copy.second), third(copy.third)  {
    }
    ContainedLink(ContainedObject* pObj, long hint, long link)
      : first(pObj), second(hint), third(link)  {
    }
  };
  /// Definition of the contained link set
  class IdentifiedLink   {
  public:
    DataObject* first;
    long second;
    IdentifiedLink() : first(0), second(INVALID)  {
    }
    IdentifiedLink(const IdentifiedLink& copy)
      : first(copy.first), second(copy.second)  {
    }
    IdentifiedLink(DataObject* pObj, long hint)
      : first(pObj), second(hint)  {
    }
  };

  typedef std::vector<ContainedLink>   ContainedLinks;
  /// Definition of the identifiable link set
  typedef std::vector<IdentifiedLink>  IdentifiedLinks;
  /// Definition of the buffer analyzer
  typedef void (*AnalyzeFunction)(const void* data, int siz, const std::type_info& type);
  /// DataObject is friend
  friend class DataObject;

protected:
  /// Boolean indicating wether the stream is in read or write mode
  Mode             m_mode;

  /// Current buffer pointer
  long             m_pointer;

  /// Total buffer length
  long             m_length;

  /// Pointer to heap buffer
  char*            m_buffer;

  /// Flag indicating swapping
  bool             m_swapEnabled;

  /// Container with links to contained objects
  ContainedLinks   m_containedLinks;

  /// Container with links to contained objects
  IdentifiedLinks  m_identifiedLinks;

  /// Hook function for analysis of data to the stream
  AnalyzeFunction  m_analyzer;

  /// Check for byte swapping
  SwapAction swapBuffer(int siz)  const;

  /** Helper to distinguis between identified pointers and contained pointers.
      This entry resolves identified pointers (= Pointers to DataObject instances.)
  */
  template <class TYPE> StreamBuffer& getObjectPointer(const DataObject* pObject, TYPE*& refpObject) {
    IdentifiedLink& link = m_identifiedLinks.back();
    DataObject* pObj = link.first;
    m_identifiedLinks.pop_back();
    refpObject = dynamic_cast<TYPE*>(pObj);
    return *this;
  }
  /** Helper to distinguis between identified pointers and contained pointers.
      This entry resolves contained pointers (= Pointers to ContainedObject instances.)
  */
  template <class TYPE> StreamBuffer& getObjectPointer(const ContainedObject* pObject, TYPE*& refpObject) {
    ContainedLink& link = m_containedLinks.back();
    ContainedObject* pObj = link.first;
    m_containedLinks.pop_back();
    refpObject = dynamic_cast<TYPE*>(pObj);
    return *this;
  }
public:
  /// Standard constructor
  StreamBuffer(bool do_swap=true) :
    m_mode(UNINITIALIZED),
    m_pointer(0),
    m_length(0),
    m_buffer(0),
    m_swapEnabled(do_swap)
  {
    m_analyzer = 0;
  }
  /// Standard destructor
  virtual ~StreamBuffer()   {
    ::free( m_buffer );
  }
  /// Read access to data buffer
  const char* data()    const   {
    return m_buffer;
  }
  /// write access to data buffer
  char* data()   {
    return m_buffer;
  }
  /// Reset the buffer
  void erase()    {
    m_pointer = 0;
  }
  /// Reserve buffer space; Default: 16 k buffer size
  void reserve(long len)   {
    if ( len > m_length )   {
      m_length = (len < 16384) ? 16384 : len;
      m_buffer = (char*)::realloc (m_buffer,m_length);
    }
  }
  /// Extend the buffer
  void extend(long len)    {
    if ( len + m_pointer > m_length )    {
      // We have to be a bit generous here in order not to run too often
      // into ::realloc().
	long new_len = (m_length < 16384) ? 16384 : 2*m_length;
      if ( m_length < len ) new_len += len;
      reserve(new_len);
    }
  }
  /// Total buffer size
  long size ()  const   {
    return m_length;
  }
  /// Access to contained links
  ContainedLinks& containedLinks()   {
    return m_containedLinks;
  }
  /// CONST Access to contained links
  const ContainedLinks& containedLinks()   const {
    return m_containedLinks;
  }

  /// Access to identified links
  IdentifiedLinks& identifiedLinks()   {
    return m_identifiedLinks;
  }
  /// CONST Access to identified links
  const IdentifiedLinks& identifiedLinks()   const {
    return m_identifiedLinks;
  }

  /// Set mode of the stream and allocate buffer
  void setMode(Mode m)  {
    m_mode = m;
    m_pointer = 0;
    m_containedLinks.erase (m_containedLinks.begin(), m_containedLinks.end());
    m_identifiedLinks.erase(m_identifiedLinks.begin(),m_identifiedLinks.end());
  }

  /// Get stream buffer state
  bool isReading()    const     {
    return m_mode == READING;
  }

  /// Get stream buffer state
  bool isWriting()    const     {
    return m_mode == WRITING;
  }
  /// Retrieve current buffer pointer
  long buffPointer()    const   {
    return m_pointer;
  }
  /// Retrieve current buffer pointer
  void setBuffPointer(long ptr)   {
    m_pointer = ptr;
  }
  /// Enable user analysis function
  void setAnalyzer(AnalyzeFunction fun=0)  {
    m_analyzer = fun;
  }
  /// Swap buffers: int, long, short, float and double
  void swapToBuffer(const void* source, int siz);

  /// Swap buffers: int, long, short, float and double
  void swapFromBuffer(void* target, int siz);

  /// Write string to output stream
  StreamBuffer& writeBytes  (const char* str, long len)    {
    extend( m_pointer+len+4 );
    *this << len;
    memcpy(data()+buffPointer(), str, len);
    m_pointer += len;
    return *this;
  }

  void getIdentifiedLink (DataObject*& pObject, long& hint)   {
    IdentifiedLink& l = m_identifiedLinks.back();
    pObject = l.first;
    hint    = l.second;
    m_identifiedLinks.pop_back();
  }
  void addIdentifiedLink (const DataObject* pObject, long hint)   {
    m_identifiedLinks.push_back( IdentifiedLink((DataObject*)pObject, hint) );
  }

  void getContainedLink (ContainedObject*& pObject, long& hint, long& link)   {
    ContainedLink& l = m_containedLinks.back();
    pObject = l.first;
    hint    = l.second;
    link    = l.third;
    m_containedLinks.pop_back();
  }
  void addContainedLink (const ContainedObject* pObject, long hint, long link)   {
    m_containedLinks.push_back( ContainedLink((ContainedObject*)pObject, hint, link) );
  }

#ifdef USE_STREAM_ANALYSER
  #define STREAM_ANALYSE(data, len)   if ( 0 != m_analyzer ) m_analyzer(&data, len, typeid(data))
#else
  #define STREAM_ANALYSE(data, len)
#endif

  // Implement streamer macros for primivive data types.
#define IMPLEMENT_STREAMER(TYPE)                                    \
  /*  Output Streamer                                   */          \
  StreamBuffer& operator<<(TYPE   data)     {                       \
    swapToBuffer(&data, sizeof(data));                              \
    STREAM_ANALYSE(data, sizeof(data));                             \
    return *this;                                                   \
  }                                                                 \
  /*  Input Streamer                                    */          \
  StreamBuffer& operator>>(TYPE & data)     {                       \
    swapFromBuffer(&data, sizeof(data));                            \
    return *this;                                                   \
  }
// RootCint does not understand this macro....
// But we can easily live without it!
#undef IMPLEMENT_STREAMER

  ///  Output Streamer
  StreamBuffer& operator<<(longlong   data)     {
    swapToBuffer(&data, sizeof(data));
    STREAM_ANALYSE(data, sizeof(data));
    return *this;
  }
  ///  Input Streamer
  StreamBuffer& operator>>(longlong & data)     {
    swapFromBuffer(&data, sizeof(data));
    return *this;
  }
  ///  Output Streamer
  StreamBuffer& operator<<(int   data)     {
    swapToBuffer(&data, sizeof(data));
    STREAM_ANALYSE(data, sizeof(data));
    return *this;
  }
  ///  Input Streamer
  StreamBuffer& operator>>(int & data)     {
    swapFromBuffer(&data, sizeof(data));
    return *this;
  }
  ///  Output Streamer
  StreamBuffer& operator<<(unsigned int   data)     {
    swapToBuffer(&data, sizeof(data));
    STREAM_ANALYSE(data, sizeof(data));
    return *this;
  }
  ///  Input Streamer
  StreamBuffer& operator>>(unsigned int & data)     {
    swapFromBuffer(&data, sizeof(data));
    return *this;
  }
  ///  Output Streamer
  StreamBuffer& operator<<(long   data)     {
    swapToBuffer(&data, sizeof(data));
    STREAM_ANALYSE(data, sizeof(data));
    return *this;
  }
  ///  Input Streamer
  StreamBuffer& operator>>(long & data)     {
    swapFromBuffer(&data, sizeof(data));
    return *this;
  }
  ///  Output Streamer
  StreamBuffer& operator<<(unsigned long   data)     {
    swapToBuffer(&data, sizeof(data));
    STREAM_ANALYSE(data, sizeof(data));
    return *this;
  }
  ///  Input Streamer
  StreamBuffer& operator>>(unsigned long & data)     {
    swapFromBuffer(&data, sizeof(data));
    return *this;
  }
  ///  Output Streamer
  StreamBuffer& operator<<(short   data)     {
    swapToBuffer(&data, sizeof(data));
    STREAM_ANALYSE(data, sizeof(data));
    return *this;
  }
  ///  Input Streamer
  StreamBuffer& operator>>(short & data)     {
    swapFromBuffer(&data, sizeof(data));
    return *this;
  }
  ///  Output Streamer
  StreamBuffer& operator<<(unsigned short   data)     {
    swapToBuffer(&data, sizeof(data));
    STREAM_ANALYSE(data, sizeof(data));
    return *this;
  }
  ///  Input Streamer
  StreamBuffer& operator>>(unsigned short & data)     {
    swapFromBuffer(&data, sizeof(data));
    return *this;
  }
  ///  Output Streamer
  StreamBuffer& operator<<(char   data)     {
    swapToBuffer(&data, sizeof(data));
    STREAM_ANALYSE(data, sizeof(data));
    return *this;
  }
  ///  Input Streamer
  StreamBuffer& operator>>(char & data)     {
    swapFromBuffer(&data, sizeof(data));
    return *this;
  }
  ///  Output Streamer
  StreamBuffer& operator<<(unsigned char   data)     {
    swapToBuffer(&data, sizeof(data));
    STREAM_ANALYSE(data, sizeof(data));
    return *this;
  }
  ///  Input Streamer
  StreamBuffer& operator>>(unsigned char & data)     {
    swapFromBuffer(&data, sizeof(data));
    return *this;
  }
  ///  Output Streamer
  StreamBuffer& operator<<(float   data)     {
    swapToBuffer(&data, sizeof(data));
    STREAM_ANALYSE(data, sizeof(data));
    return *this;
  }
  ///  Input Streamer
  StreamBuffer& operator>>(float & data)     {
    swapFromBuffer(&data, sizeof(data));
    return *this;
  }
  ///  Output Streamer
  StreamBuffer& operator<<(double   data)     {
    swapToBuffer(&data, sizeof(data));
    STREAM_ANALYSE(data, sizeof(data));
    return *this;
  }
  ///  Input Streamer
  StreamBuffer& operator>>(double & data)     {
    swapFromBuffer(&data, sizeof(data));
    return *this;
  }
  /// Streamer to read strings in (char*) format
  StreamBuffer& operator>>(char* data)    {
    long i, len;
    *this >> len;
    for ( i = 0, data[0]=0; i < len; i++ )    {
      data[i] = m_buffer[m_pointer++];
    }
    return *this;
  }
  /// Streamer to write strings in (char*) format
  StreamBuffer& operator<<(const char *data)     {
    const char* ptr = 0 == data ? "" : data;
    int len = strlen(ptr)+1;
    if ( 0 == m_analyzer )
      writeBytes(ptr, len);
    else  {
      STREAM_ANALYSE(data, len);
    }
    return *this;
  }
  /// Streamer to read strings in (std::string) format
  StreamBuffer& operator>>(std::string& data)   {
    long i, len;
    *this >> len;
    for ( i = 0, data = ""; i < len; i++ )    {
      data.append( 1, m_buffer[m_pointer++] );
    }
    return *this;
  }
  /// Streamer to write strings in (std::string) format
  StreamBuffer& operator<<(const std::string& data)   {
    if ( 0 == m_analyzer)   {
      const char* ptr = data.c_str();
      long len = data.length();
      writeBytes(ptr, len);
    }
    else    {
      STREAM_ANALYSE(data, sizeof(data));
    }
    return *this;
  }
  /** Streamer to read links to contained or identified objects.
      The specified internal function call distinguishes between
      contained and identified objects.
      @param    refpObject Reference to pointer to object to be loaded.
      @return              Reference to StreamBuffer object
  */
  template<class TYPE> StreamBuffer& operator>>(TYPE*& refpObject)	  {
    return getObjectPointer(refpObject, refpObject);
  }

  /** Streamer to write links to contained objects.
      Links to contained objects are not stored immediately,
      but collected instead and analyzed later.
      @param       pObject Pointer to object to be loaded.
      @return              Reference to StreamBuffer object
  */
  StreamBuffer& operator<<(const ContainedObject* pObject)   {
    STREAM_ANALYSE(pObject, sizeof(pObject));
    addContainedLink(pObject, INVALID, INVALID);
    return *this;
  }

  /** Streamer to write links to identified objects.
      Links to identified objects are not stored immediately,
      but collected instead and analyzed later.
      @param       pObject Pointer to object to be loaded.
      @return              Reference to StreamBuffer object
  */
  StreamBuffer& operator<<(const DataObject* pObject)   {
    STREAM_ANALYSE(pObject, sizeof(pObject));
    addIdentifiedLink(pObject, INVALID);
    return *this;
  }

  /** 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.
      @param       ioObject Reference to data IO object.
  */
  void serialize(DataIO& ioObject)   {
    ioObject.serialize ( *this );
    m_pointer = 0;
  }
};

#undef STREAM_ANALYSE

/// Check for byte swapping
inline StreamBuffer::SwapAction StreamBuffer::swapBuffer(int siz)  const    {
  switch(siz)   {
  case 1:
    return SINGLE_BYTE;
  default:
#if defined(__alpha) && !defined(__VMS)
//    return m_swapEnabled ? SWAP : NOSWAP;
    return NOSWAP;
#elif defined(__sun) && defined(__SVR4) && defined(__i386)
//    return m_swapEnabled ? SWAP : NOSWAP;
    return NOSWAP;
#elif defined(__APPLE__)
//    return m_swapEnabled ? SWAP : NOSWAP;
    return SWAP;
#elif defined(__linux) && !defined(__powerpc)
//    return m_swapEnabled ? SWAP : NOSWAP;
    return NOSWAP;
#elif defined(BORLAND) || defined(_WIN32) || defined(WIN32)
//    return m_swapEnabled ? SWAP : NOSWAP;
    return NOSWAP;
#else
    return m_swapEnabled ? SWAP : NOSWAP;
//    return NOSWAP;
#endif
  }
}

/// Swap bytes from a source buffer to the stream buffer with arbitray size
inline void StreamBuffer::swapToBuffer(const void* source, int siz)   {
  char buff[8], *tar, *src = (char*)source;
  extend (m_pointer+siz);
  tar = (char*)m_buffer+m_pointer;
  switch ( swapBuffer(siz) )   {
  case SINGLE_BYTE:
    *tar = *src;
    break;
  case SWAP:
#ifdef __APPLE__
    for(int i = 0,j = siz-1;i<siz;i++,j--) tar[j] = src[i];
#else
    ::_swab (src, buff, siz);
#endif
    src = buff;
  case NOSWAP:
    memcpy(tar, src, siz);
    break;
  }
  m_pointer += siz;
}

/// Swap bytes from the stream buffer to target buffer with arbitray size
inline void StreamBuffer::swapFromBuffer(void* target, int siz)   {
  char* tar = (char*)target;
  char* src = (char*)m_buffer+m_pointer;
  switch ( swapBuffer(siz) )   {
  case SINGLE_BYTE:
    *tar = *src;
    break;
  case SWAP:
#ifdef __APPLE__
    for(int i = 0,j = siz-1;i<siz;i++,j--) tar[j] = src[i];
#else
    ::_swab (src, tar, siz);
#endif
    break;
  case NOSWAP:
    ::memcpy(tar, src, siz);
    break;
  }
  m_pointer += siz;
}

// Output serialize a vector of items
template <class T> inline
StreamBuffer& operator << (StreamBuffer& s, const std::vector<T>& v)  {
  s << v.size();
  for ( typename std::vector<T>::const_iterator i = v.begin(); i != v.end(); i++ )  {
    s << (*i);
  }
  return s;
}

// Input serialize a vector of items
template <class T> inline
StreamBuffer& operator >> (StreamBuffer& s, std::vector<T>& v)  {
  long i, len;
  s >> len;
  v.clear();
  for ( i = 0; i < len; i++ )  {
    T    temp;
    s >> temp;
    v.push_back(temp);
  }
  return s;
}

// Output serialize a list of items
template <class T> inline
StreamBuffer& operator << (StreamBuffer& s, const std::list<T>& l)  {
  s << l.size();
  for ( typename std::list<T>::const_iterator i = l.begin(); i != l.end(); i++ )  {
    s << (*i);
  }
  return s;
}

// Input serialize a list of items
template <class T> inline
StreamBuffer& operator >> (StreamBuffer& s, std::list<T>& l)  {
  long i, len;
  s >> len;
  l.clear();
  for ( i = 0; i < len; i++ )  {
    T    temp;
    s >> temp;
    l.push_back(temp);
  }
  return s;
}
#endif // GAUDIKERNEL_STREAMBUFFER_H