60 TClassRec(TClassRec *
next) :
61 fName(0), fId(0), fDict(0), fInfo(0), fProto(0), fNext(next)
75 const type_info *fInfo;
82 TClassAlt(
const char*alternate,
const char *normName, TClassAlt *
next) :
83 fName(alternate), fNormName(normName), fNext(next)
91 const char *fNormName;
92 std::unique_ptr<TClassAlt> fNext;
95 #define R__USE_STD_MAP
96 class TMapTypeToClassRec {
97 #if defined R__USE_STD_MAP
102 typedef std::map<string, TClassRec*>
IdMap_t;
104 typedef std::map<std::string, TClassRec*>
IdMap_t;
106 typedef IdMap_t::key_type key_type;
107 typedef IdMap_t::const_iterator const_iterator;
108 typedef IdMap_t::size_type size_type;
111 typedef TClassRec* mapped_type;
113 typedef IdMap_t::mapped_type mapped_type;
120 void Add(
const key_type &key, mapped_type &
obj) {
124 mapped_type
Find(
const key_type &key)
const {
126 IdMap_t::const_iterator
iter = fMap.find(key);
128 if (iter != fMap.end()) cl = iter->second;
132 void Remove(
const key_type &key) { fMap.erase(key); }
135 Info(
"TMapTypeToClassRec::Print",
"printing the typeinfo map in TClassTable");
136 for (const_iterator
iter = fMap.begin();
iter != fMap.end();
iter++) {
137 printf(
"Key: %40s 0x%lx\n",
iter->first.c_str(), (
unsigned long)
iter->second);
144 #ifdef R__COMPLETE_MEM_TERMINATION
145 ~TMapTypeToClassRec() {
154 void Add(
const char *key, TClassRec *&obj)
162 TClassRec *
Find(
const char *key)
const {
165 if (a)
return (TClassRec*) a->
Value();
169 void Remove(
const char *key) {
178 Info(
"TMapTypeToClassRec::Print",
"printing the typeinfo map in TClassTable");
183 TClassRec *data = (TClassRec*)fMap.
GetValue(key);
185 printf(
" class: %s %d\n",data->fName,data->fId);
196 auto p =
reinterpret_cast<const unsigned char*
>(
name );
199 while (*p) slot = slot<<1 ^ *p++;
211 if (gClassTable)
return;
214 fgTable =
new TClassRec* [fgSize];
215 fgAlternate =
new TClassAlt* [fgSize];
217 memset(fgTable, 0, fgSize*
sizeof(TClassRec*));
218 memset(fgAlternate, 0, fgSize*
sizeof(TClassAlt*));
228 if (gClassTable !=
this)
return;
230 for (
UInt_t i = 0; i < fgSize; i++) {
233 delete [] fgTable; fgTable = 0;
234 delete [] fgSortedTable; fgSortedTable = 0;
235 delete fgIdMap; fgIdMap = 0;
246 if (fgTally == 0 || !fgTable)
251 int n = 0, ninit = 0, nl = 0;
253 int nch = strlen(option);
256 Printf(
"\nDefined classes");
257 Printf(
"class version bits initialized");
258 Printf(
"================================================================");
259 for (
UInt_t i = 0; i < fgTally; i++) {
260 TClassRec *
r = fgSortedTable[i];
264 if (nch && strcmp(option,r->fName) && s.
Index(re) ==
kNPOS)
continue;
268 Printf(
"%-35s %6d %7d Yes", r->fName, r->fId, r->fBits);
270 Printf(
"%-35s %6d %7d No", r->fName, r->fId, r->fBits);
272 Printf(
"----------------------------------------------------------------");
273 Printf(
"Listed Classes: %4d Total classes: %4d initialized: %4d",nl, n, ninit);
274 Printf(
"================================================================\n");
288 if (index < fgTally) {
289 TClassRec *
r = fgSortedTable[index];
290 if (r)
return r->fName;
300 namespace ROOT {
class TForNamespace {}; }
313 TClassRec *
r = FindElementImpl(cname,
kTRUE);
314 if (r->fName && r->fInfo) {
315 if ( strcmp(r->fInfo->name(),
typeid(ROOT::TForNamespace).
name())==0
316 && strcmp(info.name(),
typeid(ROOT::TForNamespace).
name())==0 ) {
324 ::Warning(
"TClassTable::Add",
"class %s already in TClassTable", cname);
344 if (!r->fName) r->fName =
StrDup(cname);
346 r->fBits = pragmabits;
350 fgIdMap->Add(info.name(),
r);
365 const char *cname = proto->
GetName();
368 TClassRec *
r = FindElementImpl(cname,
kTRUE);
380 ::Warning(
"TClassTable::Add(TProtoClass*)",
"Called for existing class without a prior call add the dictionary function.");
401 UInt_t slot = ROOT::ClassTableHash(alternate, fgSize);
403 for (
const TClassAlt *
a = fgAlternate[slot];
a;
a =
a->fNext.get()) {
404 if (strcmp(alternate,
a->fName)==0) {
405 if (strcmp(normName,
a->fNormName) != 0) {
406 fprintf(stderr,
"Error in TClassTable::AddAlternate: "
407 "Second registration of %s with a different normalized name (old: '%s', new: '%s')\n",
408 alternate,
a->fNormName, normName);
414 fgAlternate[slot] =
new TClassAlt(alternate,normName,fgAlternate[slot]);
421 if (!gClassTable || !fgTable)
return kFALSE;
423 UInt_t slot = ROOT::ClassTableHash(cname, fgSize);
426 for (TClassRec *
r = fgTable[slot];
r;
r =
r->fNext)
427 if (strcmp(cname,
r->fName)==0)
return kTRUE;
430 for (
const TClassAlt *
a = fgAlternate[slot];
a;
a =
a->fNext.get()) {
431 if (strcmp(cname,
a->fName)==0) {
432 normname =
a->fNormName;
446 if (!gClassTable || !fgTable)
return;
448 UInt_t slot = ROOT::ClassTableHash(cname,fgSize);
452 for (r = fgTable[slot];
r; r = r->fNext) {
453 if (!strcmp(r->fName, cname)) {
455 prev->fNext = r->fNext;
457 fgTable[slot] = r->fNext;
458 fgIdMap->Remove(r->fInfo->name());
476 UInt_t slot = ROOT::ClassTableHash(cname,fgSize);
478 for (TClassRec *
r = fgTable[slot];
r;
r =
r->fNext)
479 if (strcmp(cname,
r->fName)==0)
return r;
481 if (!insert)
return 0;
483 fgTable[slot] =
new TClassRec(fgTable[slot]);
486 return fgTable[slot];
498 if (!fgTable)
return 0;
502 std::string normalized;
505 return FindElementImpl(normalized.c_str(), insert);
513 TClassRec *
r = FindElement(cname);
514 if (r)
return r->fId;
523 TClassRec *
r = FindElement(cname);
524 if (r)
return r->fBits;
535 ::Info(
"GetDict",
"searches for %s", cname);
539 TClassRec *
r = FindElement(cname);
540 if (r)
return r->fDict;
551 ::Info(
"GetDict",
"searches for %s at 0x%lx", info.name(), (
Long_t)&info);
555 TClassRec *
r = fgIdMap->Find(info.name());
556 if (r)
return r->fDict;
567 ::Info(
"GetDict",
"searches for %s", cname);
571 TClassRec *
r = FindElementImpl(cname,
kFALSE);
572 if (r)
return r->fDict;
583 ::Info(
"GetDict",
"searches for %s", cname);
587 TClassRec *
r = FindElement(cname);
588 if (r)
return r->fProto;
599 ::Info(
"GetDict",
"searches for %s", cname);
603 TClassRec *
r = FindElementImpl(cname,
kFALSE);
604 if (r)
return r->fProto;
615 return strcmp((*(TClassRec **)a)->fName, (*(TClassRec **)b)->fName);
626 if (fgCursor < fgTally) {
627 TClassRec *
r = fgSortedTable[fgCursor++];
639 if (fgTally == 0 || !fgTable)
644 int n = 0, ninit = 0;
646 Printf(
"\nDefined classes");
647 Printf(
"class version bits initialized");
648 Printf(
"================================================================");
650 for (
UInt_t i = 0; i < last; i++) {
651 TClassRec *
r = fgSortedTable[i];
655 if (
gROOT->GetListOfClasses()->FindObject(r->fName)) {
657 Printf(
"%-35s %6d %7d Yes", r->fName, r->fId, r->fBits);
659 Printf(
"%-35s %6d %7d No", r->fName, r->fId, r->fBits);
661 Printf(
"----------------------------------------------------------------");
662 Printf(
"Total classes: %4d initialized: %4d", n, ninit);
663 Printf(
"================================================================\n");
672 delete [] fgSortedTable;
673 fgSortedTable =
new TClassRec* [fgTally];
676 for (
UInt_t i = 0; i < fgSize; i++)
677 for (TClassRec *
r = fgTable[i];
r;
r =
r->fNext)
678 fgSortedTable[j++] =
r;
680 ::qsort(fgSortedTable, fgTally,
sizeof(TClassRec *), ::
ClassComp);
691 for (
UInt_t i = 0; i < fgSize; i++)
694 delete [] fgTable; fgTable = 0;
695 delete [] fgSortedTable; fgSortedTable = 0;
696 delete fgIdMap; fgIdMap = 0;
707 const type_info& info,
739 if (cname && cname!=(
void*)-1) {
741 if (r) r->fId = newid;
746 if (cname!=(
void*)-1)
747 Error(
"ResetClassVersion",
"Version number of %s can not be changed after first usage!",
751 Error(
"SetClassVersion",
"The class version (for %s) must be positive (value %d is ignored)",cl->
GetName(),newid);
753 if (cname==(
void*)-1) {
781 if ((pcname=
gROOT->GetListOfClasses()->FindObject(cname))) {
806 if (loc >= 1) classname.
Remove(loc);
static ROOT::TClassRec ** fgSortedTable
void Add(THist< DIMENSION, PRECISIONA > &to, THist< DIMENSION, PRECISIONB > &from)
Namespace for new ROOT classes and functions.
static Bool_t Check(const char *cname, std::string &normname)
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
Collectable string class.
static int ClassComp(const void *a, const void *b)
static Version_t GetID(const char *cname)
Returns the ID of a class.
static TProtoClass * GetProtoNorm(const char *cname)
Given the class normalized name returns the TClassProto object for the class.
static void SortTable()
Sort the class table by ascending class ID's.
static TProtoClass * GetProto(const char *cname)
Given the class name returns the TClassProto object for the class.
void SetClassVersion(Version_t version)
Private function.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
Persistent version of a TClass.
ClassImp(TClassTable) namespace ROOT
Regular expression class.
void Add(TObject *obj)
This function may not be used (but we need to provide it since it is a pure virtual in TCollection)...
ROOT::TMapTypeToClassRec IdMap_t
void AddClass(const char *cname, Version_t id, const type_info &info, DictFuncPtr_t dict, Int_t pragmabits)
Global function called by the ctor of a class's init class (see the ClassImp macro).
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
This class registers for all classes their name, id and dictionary function in a hash table...
virtual void RegisterTClassUpdate(TClass *oldcl, DictFuncPtr_t dict)=0
TClassTable()
TClassTable is a singleton (i.e. only one can exist per application).
const char * Data() const
The TNamed class is the base class for all named ROOT classes.
void AddClassAlternate(const char *normName, const char *alternate)
Global function called by GenerateInitInstance.
std::map< std::string, std::string >::const_iterator iter
void Info(const char *location, const char *msgfmt,...)
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
static void Add(const char *cname, Version_t id, const type_info &info, DictFuncPtr_t dict, Int_t pragmabits)
Add a class to the class table (this is a static function).
std::atomic< Bool_t > fVersionUsed
saved remember if fOffsetStreamer has been set.
static ROOT::TClassRec ** fgTable
TClass *(* DictFuncPtr_t)()
TClassTable * gClassTable
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
TObject * FindObject(const char *keyname) const
Check if a (key,value) pair exists with keyname as name of the key.
R__EXTERN TROOT * gROOTLocal
void ResetClassVersion(TClass *, const char *, Short_t)
Global function to update the version number.
void RemoveClass(const char *cname)
Global function called by the dtor of a class's init class (see the ClassImp macro).
static void AddAlternate(const char *normname, const char *alternate)
void GetNormalizedName(std::string &norm_name, std::string_view name)
Return the normalized name.
TObject * Remove(TObject *key)
Remove the (key,value) pair with key from the map.
void SetUnloaded()
Call this method to indicate that the shared library containing this class's code has been removed (u...
static void Remove(const char *cname)
Remove a class from the class table.
virtual const char * GetName() const
Returns name of object.
static Int_t GetPragmaBits(const char *name)
Returns the pragma bits as specified in the LinkDef.h file.
The ROOT global object gROOT contains a list of all defined classes.
ROOT::TMapTypeToTClass IdMap_t
void Warning(const char *location, const char *msgfmt,...)
bool IsStdClass(const char *type)
return true if the class belongs to the std namespace
char * StrDup(const char *str)
Duplicate the string str.
static void Terminate()
Deletes the class table (this static class function calls the dtor).
TString & Remove(Ssiz_t pos)
Class used by TMap to store (key,value) pairs.
static ROOT::TClassRec * FindElement(const char *cname, Bool_t insert=kFALSE)
Find a class by name in the class table (using hash of name).
static char * Next()
Returns next class from sorted class table.
void Print(std::ostream &os, const OptionType &opt)
~TClassTable()
TClassTable singleton is deleted in Terminate().
static DictFuncPtr_t GetDict(const char *cname)
Given the class name returns the Dictionary() function of a class (uses hash of name).
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
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 Print(Option_t *option="") const
Print the class table.
UInt_t Find(std::list< std::pair< const Node< T > *, Float_t > > &nlist, const Node< T > *node, const T &event, UInt_t nfind)
Mother of all ROOT objects.
static void PrintTable()
Print the class table.
virtual void Add(TObject *obj)
static ROOT::TClassRec * FindElementImpl(const char *cname, Bool_t insert)
Find a class by name in the class table (using hash of name).
R__EXTERN TInterpreter * gCling
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
TNamed * RegisterClassTemplate(const char *name, const char *file, Int_t line)
Global function to register the implementation file and line of a class template (i.e.
static char * At(UInt_t index)
Returns class at index from sorted class table.
static DictFuncPtr_t GetDictNorm(const char *cname)
Given the normalized class name returns the Dictionary() function of a class (uses hash of name)...
void Error(ErrorHandler_t func, int code, const char *va_(fmt),...)
Write error message and call a handler, if required.
static ROOT::TClassAlt ** fgAlternate