62 TClassRec(TClassRec *next) :
63 fName(0), fId(0), fDict(0), fInfo(0), fProto(0), fNext(next)
77 const std::type_info *fInfo;
84 TClassAlt(
const char*alternate,
const char *normName, TClassAlt *next) :
85 fName(alternate), fNormName(normName), fNext(next)
93 const char *fNormName;
94 std::unique_ptr<TClassAlt> fNext;
97 #define R__USE_STD_MAP 98 class TMapTypeToClassRec {
99 #if defined R__USE_STD_MAP 103 typedef std::map<std::string, TClassRec*>
IdMap_t;
104 typedef IdMap_t::key_type key_type;
105 typedef IdMap_t::const_iterator const_iterator;
106 typedef IdMap_t::size_type size_type;
109 typedef TClassRec* mapped_type;
111 typedef IdMap_t::mapped_type mapped_type;
118 void Add(
const key_type &key, mapped_type &obj) {
122 mapped_type
Find(
const key_type &key)
const {
124 IdMap_t::const_iterator iter = fMap.find(key);
126 if (iter != fMap.end()) cl = iter->second;
130 void Remove(
const key_type &key) { fMap.erase(key); }
133 Info(
"TMapTypeToClassRec::Print",
"printing the typeinfo map in TClassTable");
134 for (const_iterator iter = fMap.begin(); iter != fMap.end(); ++iter) {
135 printf(
"Key: %40s 0x%lx\n", iter->first.c_str(), (
unsigned long)iter->second);
142 #ifdef R__COMPLETE_MEM_TERMINATION 143 ~TMapTypeToClassRec() {
152 void Add(
const char *key, TClassRec *&obj)
160 TClassRec *
Find(
const char *key)
const {
163 if (a)
return (TClassRec*) a->
Value();
167 void Remove(
const char *key) {
176 Info(
"TMapTypeToClassRec::Print",
"printing the typeinfo map in TClassTable");
180 printf(
"Key: %s\n",key->
String().Data());
183 printf(
" class: %s %d\n",data->fName,data->fId);
185 printf(
" no class: \n");
194 auto p =
reinterpret_cast<const unsigned char*
>(
name );
197 while (*p) slot = slot<<1 ^ *p++;
205 static std::vector<std::unique_ptr<TClassRec>> delayedAddClass;
206 return delayedAddClass;
211 static std::vector<std::pair<const char *, const char *>> delayedAddClassAlternate;
212 return delayedAddClassAlternate;
221 if (gClassTable)
return;
224 fgTable =
new TClassRec* [fgSize];
225 fgAlternate =
new TClassAlt* [fgSize];
227 memset(fgTable, 0, fgSize*
sizeof(TClassRec*));
228 memset(fgAlternate, 0, fgSize*
sizeof(TClassAlt*));
237 AddAlternate(
r.first,
r.second);
248 if (gClassTable !=
this)
return;
250 for (
UInt_t i = 0; i < fgSize; i++) {
253 delete [] fgTable; fgTable = 0;
254 delete [] fgSortedTable; fgSortedTable = 0;
255 delete fgIdMap; fgIdMap = 0;
264 if (!gClassTable || !fgTable) {
282 if (fgTally == 0 || !fgTable)
287 int n = 0, ninit = 0, nl = 0;
289 int nch = strlen(option);
292 Printf(
"\nDefined classes");
293 Printf(
"class version bits initialized");
294 Printf(
"================================================================");
295 for (
UInt_t i = 0; i < fgTally; i++) {
296 TClassRec *
r = fgSortedTable[i];
299 TString
s = r->fName;
300 if (nch && strcmp(option,r->fName) && s.Index(re) ==
kNPOS)
continue;
304 Printf(
"%-35s %6d %7d Yes", r->fName, r->fId, r->fBits);
306 Printf(
"%-35s %6d %7d No", r->fName, r->fId, r->fBits);
308 Printf(
"----------------------------------------------------------------");
309 Printf(
"Listed Classes: %4d Total classes: %4d initialized: %4d",nl, n, ninit);
310 Printf(
"================================================================\n");
324 if (index < fgTally) {
325 TClassRec *
r = fgSortedTable[index];
326 if (r)
return r->fName;
336 namespace ROOT {
class TForNamespace {}; }
348 if (!cname || *cname == 0)
349 ::Fatal(
"TClassTable::Add()",
"Failed to deduce type for '%s'", info.name());
352 TClassRec *
r = FindElementImpl(cname,
kTRUE);
353 if (r->fName && r->fInfo) {
354 if ( strcmp(r->fInfo->name(),
typeid(ROOT::TForNamespace).
name())==0
355 && strcmp(info.name(),
typeid(ROOT::TForNamespace).
name())==0 ) {
362 ::Warning(
"TClassTable::Add",
"class %s already in TClassTable", cname);
382 if (!r->fName) r->fName =
StrDup(cname);
384 r->fBits = pragmabits;
388 fgIdMap->Add(info.name(),
r);
403 const char *cname = proto->
GetName();
406 TClassRec *
r = FindElementImpl(cname,
kTRUE);
408 if (r->fProto)
delete r->fProto;
419 ::Warning(
"TClassTable::Add(TProtoClass*)",
"Called for existing class without a prior call add the dictionary function.");
442 for (
const TClassAlt *
a = fgAlternate[slot];
a;
a =
a->fNext.get()) {
443 if (strcmp(alternate,
a->fName)==0) {
444 if (strcmp(normName,
a->fNormName) != 0) {
445 fprintf(stderr,
"Error in TClassTable::AddAlternate: " 446 "Second registration of %s with a different normalized name (old: '%s', new: '%s')\n",
447 alternate,
a->fNormName, normName);
453 fgAlternate[slot] =
new TClassAlt(alternate,normName,fgAlternate[slot]);
460 if (!CheckClassTableInit())
return kFALSE;
465 for (TClassRec *
r = fgTable[slot];
r;
r =
r->fNext)
466 if (strcmp(cname,
r->fName)==0)
return kTRUE;
469 for (
const TClassAlt *
a = fgAlternate[slot];
a;
a =
a->fNext.get()) {
470 if (strcmp(cname,
a->fName)==0) {
471 normname =
a->fNormName;
485 if (!CheckClassTableInit())
return;
491 for (r = fgTable[slot];
r; r = r->fNext) {
492 if (!strcmp(r->fName, cname)) {
494 prev->fNext = r->fNext;
496 fgTable[slot] = r->fNext;
497 fgIdMap->Remove(r->fInfo->name());
517 for (TClassRec *
r = fgTable[slot];
r;
r =
r->fNext)
518 if (strcmp(cname,
r->fName)==0)
return r;
520 if (!insert)
return 0;
522 fgTable[slot] =
new TClassRec(fgTable[slot]);
525 return fgTable[slot];
537 if (!CheckClassTableInit())
return nullptr;
541 std::string normalized;
544 return FindElementImpl(normalized.c_str(), insert);
552 TClassRec *
r = FindElement(cname);
553 if (r)
return r->fId;
562 TClassRec *
r = FindElement(cname);
563 if (r)
return r->fBits;
574 ::Info(
"GetDict",
"searches for %s", cname);
578 TClassRec *
r = FindElement(cname);
579 if (r)
return r->fDict;
589 if (!CheckClassTableInit())
return nullptr;
592 ::Info(
"GetDict",
"searches for %s at 0x%lx", info.name(), (
Long_t)&info);
596 TClassRec *
r = fgIdMap->Find(info.name());
597 if (r)
return r->fDict;
607 if (!CheckClassTableInit())
return nullptr;
610 ::Info(
"GetDict",
"searches for %s", cname);
614 TClassRec *
r = FindElementImpl(cname,
kFALSE);
615 if (r)
return r->fDict;
626 ::Info(
"GetDict",
"searches for %s", cname);
629 if (!CheckClassTableInit())
return nullptr;
632 ::Info(
"GetDict",
"searches for %s", cname);
636 TClassRec *
r = FindElement(cname);
637 if (r)
return r->fProto;
648 ::Info(
"GetDict",
"searches for %s", cname);
651 if (!CheckClassTableInit())
return nullptr;
657 TClassRec *
r = FindElementImpl(cname,
kFALSE);
658 if (r)
return r->fProto;
669 return strcmp((*(TClassRec **)a)->fName, (*(TClassRec **)b)->fName);
680 if (fgCursor < fgTally) {
681 TClassRec *
r = fgSortedTable[fgCursor++];
693 if (fgTally == 0 || !fgTable)
698 int n = 0, ninit = 0;
700 Printf(
"\nDefined classes");
701 Printf(
"class version bits initialized");
702 Printf(
"================================================================");
704 for (
UInt_t i = 0; i < last; i++) {
705 TClassRec *
r = fgSortedTable[i];
709 if (
gROOT->GetListOfClasses()->FindObject(r->fName)) {
711 Printf(
"%-35s %6d %7d Yes", r->fName, r->fId, r->fBits);
713 Printf(
"%-35s %6d %7d No", r->fName, r->fId, r->fBits);
715 Printf(
"----------------------------------------------------------------");
716 Printf(
"Total classes: %4d initialized: %4d", n, ninit);
717 Printf(
"================================================================\n");
726 delete [] fgSortedTable;
727 fgSortedTable =
new TClassRec* [fgTally];
730 for (
UInt_t i = 0; i < fgSize; i++)
731 for (TClassRec *
r = fgTable[i];
r;
r =
r->fNext)
732 fgSortedTable[j++] =
r;
734 ::qsort(fgSortedTable, fgTally,
sizeof(TClassRec *), ::
ClassComp);
745 for (
UInt_t i = 0; i < fgSize; i++)
748 delete [] fgTable; fgTable = 0;
749 delete [] fgSortedTable; fgSortedTable = 0;
750 delete fgIdMap; fgIdMap = 0;
761 const std::type_info& info,
766 auto r = std::unique_ptr<TClassRec>(
new TClassRec(
nullptr));
769 r->fBits = pragmabits;
807 if (cname && cname!=(
void*)-1) {
809 if (r) r->fId = newid;
814 if (cname!=(
void*)-1)
815 Error(
"ResetClassVersion",
"Version number of %s can not be changed after first usage!",
819 Error(
"SetClassVersion",
"The class version (for %s) must be positive (value %d is ignored)",cl->
GetName(),newid);
821 if (cname==(
void*)-1) {
849 if ((pcname=
gROOT->GetListOfClasses()->FindObject(cname))) {
872 TString classname(name);
873 Ssiz_t loc = classname.Index(
"<");
874 if (loc >= 1) classname.Remove(loc);
void AddClass(const char *cname, Version_t id, const std::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).
static ROOT::TClassRec ** fgSortedTable
virtual const char * GetName() const
Returns name of object.
Namespace for new ROOT classes and functions.
static Bool_t Check(const char *cname, std::string &normname)
void Fatal(const char *location, const char *msgfmt,...)
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.
static Bool_t CheckClassTableInit()
Return true fs the table exist.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
Persistent version of a TClass.
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)...
std::vector< std::unique_ptr< TClassRec > > & GetDelayedAddClass()
ROOT::TMapTypeToClassRec IdMap_t
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).
virtual TObject * FindObject(const char *name) const
Delete a TObjLink object.
static void Add(const char *cname, Version_t id, const std::type_info &info, DictFuncPtr_t dict, Int_t pragmabits)
Add a class to the class table (this is a static function).
The TNamed class is the base class for all named ROOT classes.
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
void AddClassAlternate(const char *normName, const char *alternate)
Global function called by GenerateInitInstance.
void Info(const char *location, const char *msgfmt,...)
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.
std::vector< std::pair< const char *, const char * > > & GetDelayedAddClassAlternate()
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.
void Print(Option_t *option="") const
Print the class table.
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.
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).
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).
void Add(THist< DIMENSIONS, PRECISION_TO, STAT_TO... > &to, const THist< DIMENSIONS, PRECISION_FROM, STAT_FROM... > &from)
Add two histograms.
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 ...
static constexpr double s
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.
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.
TObject * FindObject(const char *keyname) const
Check if a (key,value) pair exists with keyname as name of the key.
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).
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
R__EXTERN TInterpreter * gCling
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)...
static UInt_t ClassTableHash(const char *name, UInt_t size)
void Error(ErrorHandler_t func, int code, const char *va_(fmt),...)
Write error message and call a handler, if required.
static ROOT::TClassAlt ** fgAlternate