Logo ROOT   6.12/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 #include "TVirtualIsAProxy.h"
16 #include "RtypesCore.h"
17 #include <atomic>
18 #include <typeinfo>
19 
20 class TClass;
21 
22 //////////////////////////////////////////////////////////////////////////
23 // //
24 // TIsAProxy implementation class. //
25 // //
26 //////////////////////////////////////////////////////////////////////////
27 class TIsAProxy : public TVirtualIsAProxy {
28 private:
29  template <typename T> using Atomic_t = std::atomic<T>;
30 
31  const std::type_info *fType; //Actual typeid of the proxy
32  Atomic_t<TClass*> fClass; //Actual TClass
33  Atomic_t<void*> fLast; //points into fSubTypes map for last used values
34  Char_t fSubTypes[72];//map of known sub-types
35  mutable Atomic_t<UInt_t> fSubTypesReaders; //number of readers of fSubTypes
36  Atomic_t<Bool_t> fSubTypesWriteLockTaken; //True if there is a writer
37  Bool_t fVirtual; //Flag if class is virtual
38  Atomic_t<Bool_t> fInit; //Initialization flag
39 
40  void* FindSubType(const std::type_info*) const;
41  void* CacheSubType(const std::type_info*, TClass*);
42 protected:
43  TIsAProxy(const TIsAProxy&) = delete;
44  TIsAProxy& operator=(const TIsAProxy&) = delete;
45 
46 public:
47  // Standard initializing constructor
48  TIsAProxy(const std::type_info &typ);
49  // Standard destructor
50  virtual ~TIsAProxy();
51  // Callbacl to set the class
52  virtual void SetClass(TClass *cl);
53  // IsA callback
54  virtual TClass* operator()(const void *obj);
55 };
56 
57 //////////////////////////////////////////////////////////////////////////
58 // //
59 // TInstrumentedIsAProxy implementation class. //
60 // //
61 //////////////////////////////////////////////////////////////////////////
62 template <class T> class TInstrumentedIsAProxy : public TVirtualIsAProxy {
63 
64 private:
65  TClass *fClass; //Actual TClass
66 
67 protected:
69  TVirtualIsAProxy(iip), fClass(iip.fClass) { }
71  {if(this!=&iip) {TVirtualIsAProxy::operator=(iip); fClass=iip.fClass;}
72  return *this;}
73 
74 public:
75  // Standard initializing constructor
76  TInstrumentedIsAProxy(TClass *cl) : fClass(cl) {}
77  // Standard destructor
79  // Callbacl to set the class
80  virtual void SetClass(TClass *cl) { fClass = cl; }
81  // IsA callback
82  virtual TClass* operator()(const void *obj) {
83  return obj==0 ? fClass : ((const T*)obj)->IsA();
84  }
85 };
86 
87 #endif // ROOT_TIsAProxy
std::atomic< T > Atomic_t
Definition: TIsAProxy.h:29
virtual ~TIsAProxy()
Standard destructor.
Definition: TIsAProxy.cxx:60
Atomic_t< TClass * > fClass
Definition: TIsAProxy.h:32
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:37
TIsAProxy implementation class.
Definition: TIsAProxy.h:27
virtual TClass * operator()(const void *obj)
IsA callback.
Definition: TIsAProxy.cxx:81
Atomic_t< Bool_t > fSubTypesWriteLockTaken
Definition: TIsAProxy.h:36
TInstrumentedIsAProxy(const TInstrumentedIsAProxy &iip)
Definition: TIsAProxy.h:68
virtual ~TInstrumentedIsAProxy()
Definition: TIsAProxy.h:78
Atomic_t< Bool_t > fInit
Definition: TIsAProxy.h:38
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
virtual TClass * operator()(const void *obj)
Definition: TIsAProxy.h:82
const std::type_info * fType
Definition: TIsAProxy.h:31
TInstrumentedIsAProxy & operator=(const TInstrumentedIsAProxy &iip)
Definition: TIsAProxy.h:70
Atomic_t< UInt_t > fSubTypesReaders
Definition: TIsAProxy.h:35
TInstrumentedIsAProxy(TClass *cl)
Definition: TIsAProxy.h:76
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:34
virtual void SetClass(TClass *cl)
Definition: TIsAProxy.h:80
Atomic_t< void * > fLast
Definition: TIsAProxy.h:33
Binding & operator=(OUT(*fun)(void))
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