Logo ROOT  
Reference Guide
TClassStreamer.h
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Victor Perev and Philippe Canal 08/05/02
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2003, Rene Brun, Fons Rademakers and al. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TClassStreamer_h
13 #define ROOT_TClassStreamer_h
14 
15 #include "TClassRef.h"
16 
17 //////////////////////////////////////////////////////////////////////////
18 // //
19 // TClassStreamer is used to stream an object of a specific class. //
20 // //
21 // The address passed to operator() will be the address of the start //
22 // of the object. //
23 // //
24 //////////////////////////////////////////////////////////////////////////
25 
27 protected:
28  TClassStreamer() : fStreamer(0) {};
30  TClassStreamer &operator=(const TClassStreamer &rhs) { fOnFileClass = rhs.fOnFileClass; fStreamer = rhs.fStreamer; return *this; }
31 
32 public:
33  TClassStreamer(ClassStreamerFunc_t pointer) : fStreamer(pointer), fOnFileClass() {};
34 
35  virtual void SetOnFileClass( const TClass* cl ) { fOnFileClass = const_cast<TClass*>(cl); }
36  virtual const TClass* GetOnFileClass() const { return fOnFileClass; }
37 
38  virtual TClassStreamer *Generate() const {
39  // Virtual copy constructor.
40  return new TClassStreamer(*this);
41  }
42 
43  virtual ~TClassStreamer(){};
44  virtual void operator()(TBuffer &b, void *objp)
45  {
46  // The address passed to operator() will be the address of the start of the
47  // object.
48 
49  (*fStreamer)(b,objp);
50  }
51  virtual void Stream(TBuffer &b, void *objp, const TClass *onfileClass)
52  {
53  // The address passed to operator() will be the address of the start of the
54  // object. Overload this routine, if your derived class can optimize
55  // the handling of the onfileClass (rather than storing and restoring from the
56  // fOnFileClass member.
57 
58  // Note we can not name this routine 'operator()' has it would be slightly
59  // backward incompatible and lead to the following warning/error from the
60  // compiler in the derived class overloading the other operator():
61 // include/TClassStreamer.h:51: error: ‘virtual void TClassStreamer::operator()(TBuffer&, void*, const TClass*)’ was hidden
62 // include/TCollectionProxyFactory.h:180: error: by ‘virtual void TCollectionClassStreamer::operator()(TBuffer&, void*)’
63 // cc1plus: warnings being treated as errors
64 
65  SetOnFileClass(onfileClass);
66  (*this)(b,objp);
67  }
68 
69 private:
71 protected:
73 };
74 
75 #endif
TClassStreamer::GetOnFileClass
virtual const TClass * GetOnFileClass() const
Definition: TClassStreamer.h:42
TClassStreamer::Stream
virtual void Stream(TBuffer &b, void *objp, const TClass *onfileClass)
Definition: TClassStreamer.h:57
TBuffer
Definition: TBuffer.h:43
TClassStreamer::~TClassStreamer
virtual ~TClassStreamer()
Definition: TClassStreamer.h:49
b
#define b(i)
Definition: RSha256.hxx:118
ClassStreamerFunc_t
void(* ClassStreamerFunc_t)(TBuffer &, void *)
Definition: Rtypes.h:72
TClassStreamer::TClassStreamer
TClassStreamer()
Definition: TClassStreamer.h:34
TClassStreamer::operator()
virtual void operator()(TBuffer &b, void *objp)
Definition: TClassStreamer.h:50
TClassStreamer::SetOnFileClass
virtual void SetOnFileClass(const TClass *cl)
Definition: TClassStreamer.h:41
TClassStreamer::Generate
virtual TClassStreamer * Generate() const
Definition: TClassStreamer.h:44
TClassRef.h
TClassStreamer::operator=
TClassStreamer & operator=(const TClassStreamer &rhs)
Definition: TClassStreamer.h:36
TClass
Definition: TClass.h:80
TClassStreamer::fStreamer
ClassStreamerFunc_t fStreamer
Definition: TClassStreamer.h:76
TClassStreamer
Definition: TClassStreamer.h:26
TClassRef
Definition: TClassRef.h:28
TClassStreamer::fOnFileClass
TClassRef fOnFileClass
Definition: TClassStreamer.h:78