TClassStreamer.h

Go to the documentation of this file.
00001 // @(#)root/base:$Id: TClassStreamer.h 36096 2010-10-05 21:27:26Z pcanal $
00002 // Author: Victor Perev and Philippe Canal   08/05/02
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2003, Rene Brun, Fons Rademakers and al.           *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TClassStreamer_h
00013 #define ROOT_TClassStreamer_h
00014 
00015 #include "Rtypes.h"
00016 #include "TClassRef.h"
00017 
00018 //////////////////////////////////////////////////////////////////////////
00019 //                                                                      //
00020 // TClassStreamer is used to stream an object of a specific class.      //
00021 //                                                                      //
00022 // The address passed to operator() will be the address of the start    //
00023 // of the  object.                                                      //
00024 //                                                                      //
00025 //////////////////////////////////////////////////////////////////////////
00026 
00027 class TClassStreamer {
00028 protected:
00029    TClassStreamer() : fStreamer(0) {};
00030 
00031 public:
00032    TClassStreamer(ClassStreamerFunc_t pointer) : fStreamer(pointer), fOnFileClass() {};
00033    TClassStreamer(const TClassStreamer &rhs) : fStreamer(rhs.fStreamer), fOnFileClass() {};
00034 
00035    virtual void SetOnFileClass( const TClass* cl ) { fOnFileClass = const_cast<TClass*>(cl); }
00036    virtual const TClass* GetOnFileClass() const { return fOnFileClass; }
00037 
00038    virtual TClassStreamer *Generate() const {
00039       // Virtual copy constructor.
00040       return new TClassStreamer(*this); 
00041    }
00042 
00043    virtual  ~TClassStreamer(){};   
00044    virtual void operator()(TBuffer &b, void *objp)
00045    {
00046       // The address passed to operator() will be the address of the start of the
00047       // object.
00048       
00049       (*fStreamer)(b,objp);
00050    }
00051    virtual void Stream(TBuffer &b, void *objp, const TClass *onfileClass)
00052    {
00053       // The address passed to operator() will be the address of the start of the
00054       // object.   Overload this routine, if your derived class can optimize
00055       // the handling of the onfileClass (rather than storing and restoring from the
00056       // fOnFileClass member.
00057       
00058       // Note we can not name this routine 'operator()' has it would be slightly
00059       // backward incompatible and lead to the following warning/error from the
00060       // compiler in the derived class overloading the other operator():
00061 //      include/TClassStreamer.h:51: error: ‘virtual void TClassStreamer::operator()(TBuffer&, void*, const TClass*)’ was hidden
00062 //      include/TCollectionProxyFactory.h:180: error:   by ‘virtual void TCollectionClassStreamer::operator()(TBuffer&, void*)’
00063 //   cc1plus: warnings being treated as errors
00064       
00065       SetOnFileClass(onfileClass);
00066       (*this)(b,objp);
00067    }
00068    
00069 private:
00070    ClassStreamerFunc_t fStreamer;
00071 protected:
00072    TClassRef           fOnFileClass;
00073 };
00074 
00075 #endif

Generated on Tue Jul 5 14:11:39 2011 for ROOT_528-00b_version by  doxygen 1.5.1