23 #include "TClassEdit.h"
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
104 typedef std::map<string, TClassRec*>
IdMap_t;
106 typedef std::map<std::string, TClassRec*>
IdMap_t;
108 typedef IdMap_t::key_type key_type;
109 typedef IdMap_t::const_iterator const_iterator;
110 typedef IdMap_t::size_type size_type;
113 typedef TClassRec* mapped_type;
115 typedef IdMap_t::mapped_type mapped_type;
122 void Add(
const key_type &key, mapped_type &obj) {
126 mapped_type
Find(
const key_type &key)
const {
128 IdMap_t::const_iterator iter = fMap.find(key);
130 if (iter != fMap.end()) cl = iter->second;
134 void Remove(
const key_type &key) { fMap.erase(key); }
137 Info(
"TMapTypeToClassRec::Print",
"printing the typeinfo map in TClassTable");
138 for (const_iterator iter = fMap.begin(); iter != fMap.end(); iter++) {
139 printf(
"Key: %40s 0x%lx\n", iter->first.c_str(), (
unsigned long)iter->second);
146 #ifdef R__COMPLETE_MEM_TERMINATION
147 ~TMapTypeToClassRec() {
156 void Add(
const char *key, TClassRec *&obj)
161 fMap.Add(realkey, (
TObject*)obj);
164 TClassRec *
Find(
const char *key)
const {
167 if (a)
return (TClassRec*) a->
Value();
171 void Remove(
const char *key) {
174 TObject *actual = fMap.Remove(&realkey);
180 Info(
"TMapTypeToClassRec::Print",
"printing the typeinfo map in TClassTable");
184 printf(
"Key: %s\n",key->
String().Data());
185 TClassRec *
data = (TClassRec*)fMap.GetValue(key);
187 printf(
" class: %s %d\n",data->fName,data->fId);
189 printf(
" no class: \n");
198 auto p =
reinterpret_cast<const unsigned char*
>(
name );
201 while (*p) slot = slot<<1 ^ *p++;
216 fgTable =
new TClassRec* [fgSize];
217 fgAlternate =
new TClassAlt* [fgSize];
219 memset(fgTable, 0, fgSize*
sizeof(TClassRec*));
220 memset(fgAlternate, 0, fgSize*
sizeof(TClassAlt*));
232 for (
UInt_t i = 0; i < fgSize; i++) {
235 delete [] fgTable; fgTable = 0;
236 delete [] fgSortedTable; fgSortedTable = 0;
237 delete fgIdMap; fgIdMap = 0;
248 if (fgTally == 0 || !fgTable)
253 int n = 0, ninit = 0, nl = 0;
255 int nch = strlen(option);
258 Printf(
"\nDefined classes");
259 Printf(
"class version bits initialized");
260 Printf(
"================================================================");
261 for (
UInt_t i = 0; i < fgTally; i++) {
262 TClassRec *
r = fgSortedTable[i];
265 TString s = r->fName;
266 if (nch && strcmp(option,r->fName) && s.Index(re) ==
kNPOS)
continue;
270 Printf(
"%-35s %6d %7d Yes", r->fName, r->fId, r->fBits);
272 Printf(
"%-35s %6d %7d No", r->fName, r->fId, r->fBits);
274 Printf(
"----------------------------------------------------------------");
275 Printf(
"Listed Classes: %4d Total classes: %4d initialized: %4d",nl, n, ninit);
276 Printf(
"================================================================\n");
290 if (index < fgTally) {
291 TClassRec *
r = fgSortedTable[index];
292 if (r)
return r->fName;
302 namespace ROOT {
class TForNamespace {}; }
315 TClassRec *
r = FindElementImpl(cname,
kTRUE);
316 if (r->fName && r->fInfo) {
317 if ( strcmp(r->fInfo->name(),
typeid(ROOT::TForNamespace).
name())==0
318 && strcmp(info.name(),
typeid(ROOT::TForNamespace).
name())==0 ) {
324 if (!TClassEdit::IsStdClass(cname)) {
326 ::Warning(
"TClassTable::Add",
"class %s already in TClassTable", cname);
346 if (!r->fName) r->fName =
StrDup(cname);
348 r->fBits = pragmabits;
352 fgIdMap->Add(info.name(),
r);
367 const char *cname = proto->
GetName();
370 TClassRec *
r = FindElementImpl(cname,
kTRUE);
372 if (r->fProto)
delete r->fProto;
383 ::Warning(
"TClassTable::Add(TProtoClass*)",
"Called for existing class without a prior call add the dictionary function.");
406 for (
const TClassAlt *
a = fgAlternate[slot];
a;
a =
a->fNext.get()) {
407 if (strcmp(alternate,
a->fName)==0) {
408 if (strcmp(normName,
a->fNormName) != 0) {
409 fprintf(stderr,
"Error in TClassTable::AddAlternate: "
410 "Second registration of %s with a different normalized name (old: '%s', new: '%s')\n",
411 alternate,
a->fNormName, normName);
417 fgAlternate[slot] =
new TClassAlt(alternate,normName,fgAlternate[slot]);
429 for (TClassRec *
r = fgTable[slot];
r;
r =
r->fNext)
433 for (
const TClassAlt *
a = fgAlternate[slot];
a;
a =
a->fNext.get()) {
434 if (strcmp(cname,
a->fName)==0) {
435 normname =
a->fNormName;
455 for (r = fgTable[slot];
r; r = r->fNext) {
456 if (!strcmp(r->fName, cname)) {
458 prev->fNext = r->fNext;
460 fgTable[slot] = r->fNext;
461 fgIdMap->Remove(r->fInfo->name());
481 for (TClassRec *
r = fgTable[slot];
r;
r =
r->fNext)
482 if (strcmp(cname,
r->
fName)==0)
return r;
484 if (!insert)
return 0;
486 fgTable[slot] =
new TClassRec(fgTable[slot]);
489 return fgTable[slot];
501 if (!fgTable)
return 0;
505 std::string normalized;
506 TClassEdit::GetNormalizedName(normalized,cname);
508 return FindElementImpl(normalized.c_str(), insert);
516 TClassRec *
r = FindElement(cname);
517 if (r)
return r->fId;
526 TClassRec *
r = FindElement(cname);
527 if (r)
return r->fBits;
538 ::Info(
"GetDict",
"searches for %s", cname);
542 TClassRec *
r = FindElement(cname);
543 if (r)
return r->fDict;
554 ::Info(
"GetDict",
"searches for %s at 0x%lx", info.name(), (
Long_t)&info);
558 TClassRec *
r = fgIdMap->Find(info.name());
559 if (r)
return r->fDict;
570 ::Info(
"GetDict",
"searches for %s", cname);
574 TClassRec *
r = FindElementImpl(cname,
kFALSE);
575 if (r)
return r->fDict;
586 ::Info(
"GetDict",
"searches for %s", cname);
590 TClassRec *
r = FindElement(cname);
591 if (r)
return r->fProto;
602 ::Info(
"GetDict",
"searches for %s", cname);
606 TClassRec *
r = FindElementImpl(cname,
kFALSE);
607 if (r)
return r->fProto;
618 return strcmp((*(TClassRec **)a)->fName, (*(TClassRec **)b)->fName);
629 if (fgCursor < fgTally) {
630 TClassRec *
r = fgSortedTable[fgCursor++];
642 if (fgTally == 0 || !fgTable)
647 int n = 0, ninit = 0;
649 Printf(
"\nDefined classes");
650 Printf(
"class version bits initialized");
651 Printf(
"================================================================");
653 for (
UInt_t i = 0; i < last; i++) {
654 TClassRec *
r = fgSortedTable[i];
658 if (
gROOT->GetListOfClasses()->FindObject(r->fName)) {
660 Printf(
"%-35s %6d %7d Yes", r->fName, r->fId, r->fBits);
662 Printf(
"%-35s %6d %7d No", r->fName, r->fId, r->fBits);
664 Printf(
"----------------------------------------------------------------");
665 Printf(
"Total classes: %4d initialized: %4d", n, ninit);
666 Printf(
"================================================================\n");
675 delete [] fgSortedTable;
676 fgSortedTable =
new TClassRec* [fgTally];
679 for (
UInt_t i = 0; i < fgSize; i++)
680 for (TClassRec *
r = fgTable[i];
r;
r =
r->fNext)
681 fgSortedTable[j++] =
r;
683 ::qsort(fgSortedTable, fgTally,
sizeof(TClassRec *), ::
ClassComp);
694 for (
UInt_t i = 0; i < fgSize; i++)
697 delete [] fgTable; fgTable = 0;
698 delete [] fgSortedTable; fgSortedTable = 0;
699 delete fgIdMap; fgIdMap = 0;
710 const std::type_info& info,
742 if (cname && cname!=(
void*)-1) {
744 if (r) r->fId = newid;
749 if (cname!=(
void*)-1)
750 Error(
"ResetClassVersion",
"Version number of %s can not be changed after first usage!",
754 Error(
"SetClassVersion",
"The class version (for %s) must be positive (value %d is ignored)",cl->
GetName(),newid);
756 if (cname==(
void*)-1) {
784 if ((pcname=
gROOT->GetListOfClasses()->FindObject(cname))) {
807 TString classname(name);
808 Ssiz_t loc = classname.Index(
"<");
809 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
TClass *(* DictFuncPtr_t)()
static Bool_t Check(const char *cname, std::string &normname)
Collectable string class.
R__EXTERN TClassTable * gClassTable
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.
Regular expression class.
ROOT::TMapTypeToClassRec IdMap_t
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).
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.
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
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
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 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,...)
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).
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 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.
void Add(THist< DIMENSIONS, PRECISION_TO, STAT_TO...> &to, const THist< DIMENSIONS, PRECISION_FROM, STAT_FROM...> &from)
Add two histograms.
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).
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
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.
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
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