Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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:
68  TInstrumentedIsAProxy(const TInstrumentedIsAProxy& iip) :
69  TVirtualIsAProxy(iip), fClass(iip.fClass) { }
70  TInstrumentedIsAProxy& operator=(const TInstrumentedIsAProxy& iip)
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
78  virtual ~TInstrumentedIsAProxy() {}
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