// @(#)root/base:$Id$
// Author: Victor Perev and Philippe Canal   08/05/02

/*************************************************************************
 * Copyright (C) 1995-2003, Rene Brun, Fons Rademakers and al.           *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TClassStreamer_h
#define ROOT_TClassStreamer_h

#include "Rtypes.h"
#include "TClassRef.h"

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TClassStreamer is used to stream an object of a specific class.      //
//                                                                      //
// The address passed to operator() will be the address of the start    //
// of the  object.                                                      //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

class TClassStreamer {
protected:
   TClassStreamer() : fStreamer(0) {};
   TClassStreamer(const TClassStreamer &rhs) : fStreamer(rhs.fStreamer), fOnFileClass() {};
   TClassStreamer &operator=(const TClassStreamer &rhs) {   fOnFileClass = rhs.fOnFileClass; fStreamer = rhs.fStreamer; return *this; }

public:
   TClassStreamer(ClassStreamerFunc_t pointer) : fStreamer(pointer), fOnFileClass() {};

   virtual void SetOnFileClass( const TClass* cl ) { fOnFileClass = const_cast<TClass*>(cl); }
   virtual const TClass* GetOnFileClass() const { return fOnFileClass; }

   virtual TClassStreamer *Generate() const {
      // Virtual copy constructor.
      return new TClassStreamer(*this);
   }

   virtual  ~TClassStreamer(){};
   virtual void operator()(TBuffer &b, void *objp)
   {
      // The address passed to operator() will be the address of the start of the
      // object.

      (*fStreamer)(b,objp);
   }
   virtual void Stream(TBuffer &b, void *objp, const TClass *onfileClass)
   {
      // The address passed to operator() will be the address of the start of the
      // object.   Overload this routine, if your derived class can optimize
      // the handling of the onfileClass (rather than storing and restoring from the
      // fOnFileClass member.

      // Note we can not name this routine 'operator()' has it would be slightly
      // backward incompatible and lead to the following warning/error from the
      // compiler in the derived class overloading the other operator():
//      include/TClassStreamer.h:51: error: ‘virtual void TClassStreamer::operator()(TBuffer&, void*, const TClass*)’ was hidden
//      include/TCollectionProxyFactory.h:180: error:   by ‘virtual void TCollectionClassStreamer::operator()(TBuffer&, void*)’
//   cc1plus: warnings being treated as errors

      SetOnFileClass(onfileClass);
      (*this)(b,objp);
   }

private:
   ClassStreamerFunc_t fStreamer;
protected:
   TClassRef           fOnFileClass;
};

#endif
 TClassStreamer.h:1
 TClassStreamer.h:2
 TClassStreamer.h:3
 TClassStreamer.h:4
 TClassStreamer.h:5
 TClassStreamer.h:6
 TClassStreamer.h:7
 TClassStreamer.h:8
 TClassStreamer.h:9
 TClassStreamer.h:10
 TClassStreamer.h:11
 TClassStreamer.h:12
 TClassStreamer.h:13
 TClassStreamer.h:14
 TClassStreamer.h:15
 TClassStreamer.h:16
 TClassStreamer.h:17
 TClassStreamer.h:18
 TClassStreamer.h:19
 TClassStreamer.h:20
 TClassStreamer.h:21
 TClassStreamer.h:22
 TClassStreamer.h:23
 TClassStreamer.h:24
 TClassStreamer.h:25
 TClassStreamer.h:26
 TClassStreamer.h:27
 TClassStreamer.h:28
 TClassStreamer.h:29
 TClassStreamer.h:30
 TClassStreamer.h:31
 TClassStreamer.h:32
 TClassStreamer.h:33
 TClassStreamer.h:34
 TClassStreamer.h:35
 TClassStreamer.h:36
 TClassStreamer.h:37
 TClassStreamer.h:38
 TClassStreamer.h:39
 TClassStreamer.h:40
 TClassStreamer.h:41
 TClassStreamer.h:42
 TClassStreamer.h:43
 TClassStreamer.h:44
 TClassStreamer.h:45
 TClassStreamer.h:46
 TClassStreamer.h:47
 TClassStreamer.h:48
 TClassStreamer.h:49
 TClassStreamer.h:50
 TClassStreamer.h:51
 TClassStreamer.h:52
 TClassStreamer.h:53
 TClassStreamer.h:54
 TClassStreamer.h:55
 TClassStreamer.h:56
 TClassStreamer.h:57
 TClassStreamer.h:58
 TClassStreamer.h:59
 TClassStreamer.h:60
 TClassStreamer.h:61
 TClassStreamer.h:62
 TClassStreamer.h:63
 TClassStreamer.h:64
 TClassStreamer.h:65
 TClassStreamer.h:66
 TClassStreamer.h:67
 TClassStreamer.h:68
 TClassStreamer.h:69
 TClassStreamer.h:70
 TClassStreamer.h:71
 TClassStreamer.h:72
 TClassStreamer.h:73
 TClassStreamer.h:74
 TClassStreamer.h:75
 TClassStreamer.h:76