Logo ROOT   6.18/05
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
20class TClass;
21
22//////////////////////////////////////////////////////////////////////////
23// //
24// TIsAProxy implementation class. //
25// //
26//////////////////////////////////////////////////////////////////////////
28private:
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*);
42protected:
43 TIsAProxy(const TIsAProxy&) = delete;
44 TIsAProxy& operator=(const TIsAProxy&) = delete;
45
46public:
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//////////////////////////////////////////////////////////////////////////
62template <class T> class TInstrumentedIsAProxy : public TVirtualIsAProxy {
63
64private:
65 TClass *fClass; //Actual TClass
66
67protected:
69 TVirtualIsAProxy(iip), fClass(iip.fClass) { }
71 {if(this!=&iip) {TVirtualIsAProxy::operator=(iip); fClass=iip.fClass;}
72 return *this;}
73
74public:
75 // Standard initializing constructor
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
char Char_t
Definition: RtypesCore.h:29
bool Bool_t
Definition: RtypesCore.h:59
Binding & operator=(OUT(*fun)(void))
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:75
virtual TClass * operator()(const void *obj)
Definition: TIsAProxy.h:82
virtual ~TInstrumentedIsAProxy()
Definition: TIsAProxy.h:78
TInstrumentedIsAProxy(const TInstrumentedIsAProxy &iip)
Definition: TIsAProxy.h:68
virtual void SetClass(TClass *cl)
Definition: TIsAProxy.h:80
TInstrumentedIsAProxy(TClass *cl)
Definition: TIsAProxy.h:76
TInstrumentedIsAProxy & operator=(const TInstrumentedIsAProxy &iip)
Definition: TIsAProxy.h:70
TIsAProxy implementation class.
Definition: TIsAProxy.h:27
Atomic_t< UInt_t > fSubTypesReaders
Definition: TIsAProxy.h:35
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
virtual void SetClass(TClass *cl)
Set class pointer This method is not thread safe.
Definition: TIsAProxy.cxx:71
virtual ~TIsAProxy()
Standard destructor.
Definition: TIsAProxy.cxx:60
std::atomic< T > Atomic_t
Definition: TIsAProxy.h:29
Atomic_t< void * > fLast
Definition: TIsAProxy.h:33
TIsAProxy & operator=(const TIsAProxy &)=delete
Char_t fSubTypes[72]
Definition: TIsAProxy.h:34
virtual TClass * operator()(const void *obj)
IsA callback.
Definition: TIsAProxy.cxx:81
const std::type_info * fType
Definition: TIsAProxy.h:31
Atomic_t< Bool_t > fSubTypesWriteLockTaken
Definition: TIsAProxy.h:36
Bool_t fVirtual
Definition: TIsAProxy.h:37
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
Atomic_t< Bool_t > fInit
Definition: TIsAProxy.h:38
Atomic_t< TClass * > fClass
Definition: TIsAProxy.h:32
TIsAProxy(const TIsAProxy &)=delete
double T(double x)
Definition: ChebyshevPol.h:34