18 #include <type_traits>
29 virtual ~DynamicType() {}
32 typedef std::map<const void*, TClass*> ClassMap_t;
33 inline ClassMap_t *GetMap(
const void* p)
35 return (ClassMap_t*)p;
38 inline ClassMap_t::value_type* ToPair(
void*p)
40 return (ClassMap_t::value_type*)p;
49 fSubTypesReaders(0), fSubTypesWriteLockTaken(
kFALSE),
52 static_assert(
sizeof(ClassMap_t)<=
sizeof(
fSubTypes),
"ClassMap size is to large for array");
86 TClass* expected =
nullptr;
87 fClass.compare_exchange_strong(expected,cls);
89 if ( !
fClass.load() )
return nullptr;
103 DynamicType* ptr = (DynamicType*)obj;
104 const std::type_info* typ = &
typeid(*ptr);
106 if ( typ ==
fType ) {
109 auto last = ToPair(
fLast.load());
110 if ( last && typ == last->first ) {
115 if ( last ==
nullptr || last->second ==
nullptr ) {
122 return last ==
nullptr?
nullptr: last->second;
130 bool needToWait =
kTRUE;
144 void* returnValue =
nullptr;
147 auto found = map->find(type);
148 if(found != map->end()) {
149 returnValue = &(*found);
170 auto ret = map->emplace(type,cls);
173 (*ret.first).second = cls;
177 return &(*(ret.first));
Atomic_t< TClass * > fClass
TIsAProxy(const TIsAProxy &)=delete
void * FindSubType(const type_info *) const
See if we have already cached the TClass that correspond to this type_info.
TIsAProxy implementation class.
TClass * fClass
pointer to the foreign object
virtual TClass * operator()(const void *obj)
IsA callback.
Atomic_t< Bool_t > fSubTypesWriteLockTaken
The ROOT global object gROOT contains a list of all defined classes.
Atomic_t< UInt_t > fSubTypesReaders
virtual void SetClass(TClass *cl)
Set class pointer This method is not thread safe.
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
void * CacheSubType(const type_info *, TClass *)
Record the TClass found for a type_info, so that we can retrieved it faster.