Logo ROOT   6.08/07
Reference Guide
TIsAProxy.h
Go to the documentation of this file.
1 // @(#)root/meta:$Id$
2 // Author: Markus Frank 20/05/2005
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
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_TIsAProxy
13 #define ROOT_TIsAProxy
14 
15 #ifndef ROOT_TVirtualIsAProxy
16 #include "TVirtualIsAProxy.h"
17 #endif
18 #ifndef ROOT_Rtypes
19 #include "Rtypes.h"
20 #endif
21 #include <atomic>
22 
23 class TClass;
24 
25 //////////////////////////////////////////////////////////////////////////
26 // //
27 // TIsAProxy implementation class. //
28 // //
29 //////////////////////////////////////////////////////////////////////////
30 class TIsAProxy : public TVirtualIsAProxy {
31 private:
32  template <typename T> using Atomic_t = std::atomic<T>;
33 
34  const std::type_info *fType; //Actual typeid of the proxy
35  Atomic_t<TClass*> fClass; //Actual TClass
36  Atomic_t<void*> fLast; //points into fSubTypes map for last used values
37  Char_t fSubTypes[72];//map of known sub-types
38  mutable Atomic_t<UInt_t> fSubTypesReaders; //number of readers of fSubTypes
39  Atomic_t<Bool_t> fSubTypesWriteLockTaken; //True if there is a writer
40  Bool_t fVirtual; //Flag if class is virtual
41  Atomic_t<Bool_t> fInit; //Initialization flag
42 
43  void* FindSubType(const std::type_info*) const;
44  void* CacheSubType(const std::type_info*, TClass*);
45 protected:
46  TIsAProxy(const TIsAProxy&) = delete;
47  TIsAProxy& operator=(const TIsAProxy&) = delete;
48 
49 public:
50  // Standard initializing constructor
51  TIsAProxy(const std::type_info &typ);
52  // Standard destructor
53  virtual ~TIsAProxy();
54  // Callbacl to set the class
55  virtual void SetClass(TClass *cl);
56  // IsA callback
57  virtual TClass* operator()(const void *obj);
58 };
59 
60 //////////////////////////////////////////////////////////////////////////
61 // //
62 // TInstrumentedIsAProxy implementation class. //
63 // //
64 //////////////////////////////////////////////////////////////////////////
65 template <class T> class TInstrumentedIsAProxy : public TVirtualIsAProxy {
66 
67 private:
68  TClass *fClass; //Actual TClass
69 
70 protected:
72  TVirtualIsAProxy(iip), fClass(iip.fClass) { }
74  {if(this!=&iip) {TVirtualIsAProxy::operator=(iip); fClass=iip.fClass;}
75  return *this;}
76 
77 public:
78  // Standard initializing constructor
79  TInstrumentedIsAProxy(TClass *cl) : fClass(cl) {}
80  // Standard destructor
82  // Callbacl to set the class
83  virtual void SetClass(TClass *cl) { fClass = cl; }
84  // IsA callback
85  virtual TClass* operator()(const void *obj) {
86  return obj==0 ? fClass : ((const T*)obj)->IsA();
87  }
88 };
89 
90 #endif // ROOT_TIsAProxy
std::atomic< T > Atomic_t
Definition: TIsAProxy.h:32
virtual ~TIsAProxy()
Standard destructor.
Definition: TIsAProxy.cxx:60
Atomic_t< TClass * > fClass
Definition: TIsAProxy.h:35
TIsAProxy(const TIsAProxy &)=delete
double T(double x)
Definition: ChebyshevPol.h:34
void * FindSubType(const std::type_info *) const
See if we have already cached the TClass that correspond to this std::type_info.
Definition: TIsAProxy.cxx:128
bool Bool_t
Definition: RtypesCore.h:59
Bool_t fVirtual
Definition: TIsAProxy.h:40
TIsAProxy implementation class.
Definition: TIsAProxy.h:30
virtual TClass * operator()(const void *obj)
IsA callback.
Definition: TIsAProxy.cxx:81
Atomic_t< Bool_t > fSubTypesWriteLockTaken
Definition: TIsAProxy.h:39
TInstrumentedIsAProxy(const TInstrumentedIsAProxy &iip)
Definition: TIsAProxy.h:71
virtual ~TInstrumentedIsAProxy()
Definition: TIsAProxy.h:81
Atomic_t< Bool_t > fInit
Definition: TIsAProxy.h:41
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
virtual TClass * operator()(const void *obj)
Definition: TIsAProxy.h:85
const std::type_info * fType
Definition: TIsAProxy.h:34
TInstrumentedIsAProxy & operator=(const TInstrumentedIsAProxy &iip)
Definition: TIsAProxy.h:73
Atomic_t< UInt_t > fSubTypesReaders
Definition: TIsAProxy.h:38
TInstrumentedIsAProxy(TClass *cl)
Definition: TIsAProxy.h:79
virtual void SetClass(TClass *cl)
Set class pointer This method is not thread safe.
Definition: TIsAProxy.cxx:71
Char_t fSubTypes[72]
Definition: TIsAProxy.h:37
virtual void SetClass(TClass *cl)
Definition: TIsAProxy.h:83
Atomic_t< void * > fLast
Definition: TIsAProxy.h:36
char Char_t
Definition: RtypesCore.h:29
void * CacheSubType(const std::type_info *, TClass *)
Record the TClass found for a std::type_info, so that we can retrieved it faster. ...
Definition: TIsAProxy.cxx:158
TIsAProxy & operator=(const TIsAProxy &)=delete