44#include <unordered_map>
62 static std::mutex sMutex;
143#define R__USE_STD_MAP
145#if defined R__USE_STD_MAP
149 typedef std::map<std::string, TClassRec*>
IdMap_t;
169 IdMap_t::const_iterator iter =
fMap.find(key);
171 if (iter !=
fMap.end()) cl = iter->second;
178 Info(
"TMapTypeToClassRec::Print",
"printing the typeinfo map in TClassTable");
180 printf(
"Key: %40s 0x%zx\n", iter->first.c_str(), (
size_t)iter->second);
187#ifdef R__COMPLETE_MEM_TERMINATION
197 void Add(
const char *key, TClassRec *&obj)
201 TObjString *realkey =
new TObjString(key);
202 fMap.Add(realkey, (TObject*)obj);
205 TClassRec *
Find(
const char *key)
const {
207 const TPair *
a = (
const TPair *)
fMap.FindObject(key);
208 if (
a)
return (TClassRec*)
a->Value();
212 void Remove(
const char *key) {
214 TObjString realkey(key);
215 TObject *actual =
fMap.Remove(&realkey);
221 Info(
"TMapTypeToClassRec::Print",
"printing the typeinfo map in TClassTable");
224 while((key = (TObjString*)next())) {
230 printf(
" no class: \n");
239 auto p =
reinterpret_cast<const unsigned char*
>(
name );
242 while (*p) slot = slot<<1 ^ *p++;
250 static std::vector<std::unique_ptr<TClassRec>> delayedAddClass;
251 return delayedAddClass;
256 static std::vector<std::pair<const char *, const char *>> delayedAddClassAlternate;
257 return delayedAddClassAlternate;
263 static std::unordered_map<ROOT::TClassRec *, std::vector<ROOT::TClassAlt *>> classRecToAltMap;
264 return classRecToAltMap;
301 for (UInt_t i = 0; i <
fgSize; i++) {
345 int n = 0, ninit = 0, nl = 0;
351 Printf(
"\nDefined classes");
352 Printf(
"class version bits initialized");
353 Printf(
"================================================================");
354 for (UInt_t i = 0; i <
fgTally; i++) {
363 Printf(
"%-35s %6d %7d Yes",
r->fName,
r->fId,
r->fBits);
365 Printf(
"%-35s %6d %7d No",
r->fName,
r->fId,
r->fBits);
367 Printf(
"----------------------------------------------------------------");
368 Printf(
"Listed Classes: %4d Total classes: %4d initialized: %4d",nl,
n, ninit);
369 Printf(
"================================================================\n");
407 if (!cname || *cname == 0)
408 ::Fatal(
"TClassTable::Add()",
"Failed to deduce type for '%s'", info.name());
419 if (
r->fName &&
r->fInfo) {
429 ::Warning(
"TClassTable::Add",
"class %s already in TClassTable", cname);
445 gCling->RegisterTClassUpdate(oldcl, dict);
452 r->fBits = pragmabits;
476 const char *cname =
proto->GetName();
481 if (
r->fProto)
delete r->fProto;
487 proto->FillTClass(oldcl);
498 ::Warning(
"TClassTable::Add(TProtoClass*)",
"Called for existing class without a prior call add the dictionary function.");
526 if (strcmp(alternate,
a->fName)==0) {
527 if (strcmp(normName,
a->fNormName) != 0) {
528 fprintf(stderr,
"Error in TClassTable::AddAlternate: "
529 "Second registration of %s with a different normalized name (old: '%s', new: '%s')\n",
530 alternate,
a->fNormName, normName);
542 if (
auto it = classToAlt.find(
fgTable[slotNorm]); it == classToAlt.end())
569 if (
a->fNext.get() == alt) {
570 a->fNext.swap( alt->
fNext );
571 assert( alt == alt->
fNext.get());
572 alt->
fNext.release();
592 if (strcmp(cname,
r->fName)==0)
return kTRUE;
596 if (strcmp(cname,
a->fName)==0) {
597 normname =
a->fNormName;
621 if (!strcmp(
r->fName, cname)) {
650 if (strcmp(cname,
r->fName) == 0)
695 ::Info(
"GetDict",
"searches for %s", cname);
721 ::Info(
"GetDict",
"searches for %s at 0x%zx", info.name(), (
size_t)&info);
746 ::Info(
"GetDict",
"searches for %s", cname);
763 ::Info(
"GetDict",
"searches for %s", cname);
774 ::Info(
"GetDict",
"searches for %s", cname);
791 ::Info(
"GetDict",
"searches for %s", cname);
850 int n = 0, ninit = 0;
852 Printf(
"\nDefined classes");
853 Printf(
"class version bits initialized");
854 Printf(
"================================================================");
856 for (UInt_t i = 0; i < last; i++) {
861 if (
gROOT->GetListOfClasses()->FindObject(
r->fName)) {
863 Printf(
"%-35s %6d %7d Yes",
r->fName,
r->fId,
r->fBits);
865 Printf(
"%-35s %6d %7d No",
r->fName,
r->fId,
r->fBits);
867 Printf(
"----------------------------------------------------------------");
868 Printf(
"Total classes: %4d initialized: %4d",
n, ninit);
869 Printf(
"================================================================\n");
884 for (UInt_t i = 0; i <
fgSize; i++)
899 for (UInt_t i = 0; i <
fgSize; i++)
915 const std::type_info& info,
920 auto r = std::unique_ptr<TClassRec>(
new TClassRec(
nullptr));
923 r->fBits = pragmabits;
980 if (cname!=(
void*)-1)
981 Error(
"ResetClassVersion",
"Version number of %s can not be changed after first usage!",
985 Error(
"SetClassVersion",
"The class version (for %s) must be positive (value %d is ignored)",cl->
GetName(),newid);
987 if (cname==(
void*)-1) {
1027 static Bool_t isInit = []() {
1043 reg =
new TNamed((
const char*)classname, file);
1059 if (
auto it = classRecToAltMap.find(
fgTable[slot]); it == classRecToAltMap.end())
1062 const auto &classAlts = classRecToAltMap.at(
fgTable[slot]);
1063 std::vector<std::string>
ret;
1064 ret.reserve(classAlts.size());
1065 for (
const auto *classAlt : classAlts) {
1066 ret.push_back(classAlt->fName);
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
short Version_t
Class version identifier (short).
int Ssiz_t
String size (currently int).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
short Short_t
Signed Short integer 2 bytes (short).
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
const char Option_t
Option string (const char).
TClass *(* DictFuncPtr_t)()
static std::mutex & GetClassTableMutex()
static int ClassComp(const void *a, const void *b)
std::unordered_map< ROOT::TClassRec *, std::vector< ROOT::TClassAlt * > > & GetClassRecToAltMap()
externTClassTable * gClassTable
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
externTInterpreter * gCling
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
char * StrDup(const char *str)
Duplicate the string str.
TClassAlt(const char *alternate, const char *normName, TClassAlt *next)
std::unique_ptr< TClassAlt > fNext
TClassRec(TClassRec *next)
const std::type_info * fInfo
IdMap_t::size_type size_type
IdMap_t::mapped_type mapped_type
void Add(const key_type &key, mapped_type &obj)
IdMap_t::key_type key_type
std::map< std::string, TClassRec * > IdMap_t
IdMap_t::const_iterator const_iterator
void Remove(const key_type &key)
mapped_type Find(const key_type &key) const
IdMap_t::size_type size_type
IdMap_t::mapped_type mapped_type
IdMap_t::key_type key_type
const std::string & GetNormalizedName() const
std::string fNormalizedName
NormalizeThenLock(const NormalizeThenLock &)=delete
NormalizeThenLock(const char *cname)
NormalizeThenLock(NormalizeThenLock &&)=delete
NormalizeThenLock()=delete
NormalizeThenLock & operator=(const NormalizeThenLock &)=delete
NormalizeThenLock & operator=(NormalizeThenLock &&)=delete
This class registers for all classes their name, id and dictionary function in a hash table.
static void PrintTable()
Print the class table.
static Int_t GetPragmaBits(const char *name)
Returns the pragma bits as specified in the LinkDef.h file.
static DictFuncPtr_t GetDict(const char *cname)
Given the class name returns the Dictionary() function of a class (uses hash of name).
static Version_t GetID(const char *cname)
Returns the ID of a class.
ROOT::TMapTypeToClassRec IdMap_t
static void SortTable()
Sort the class table by ascending class ID's.
static TProtoClass * GetProtoNorm(const char *cname)
Given the class normalized name returns the TClassProto object for the class.
static DictFuncPtr_t GetDictNorm(const char *cname)
Given the normalized class name returns the Dictionary() function of a class (uses hash of name).
static ROOT::TClassAlt ** fgAlternate
void Print(Option_t *option="") const override
Print the class table.
static void Terminate()
Deletes the class table (this static class function calls the dtor).
static TProtoClass * GetProto(const char *cname)
Given the class name returns the TClassProto object for the class.
static std::atomic< UInt_t > fgTally
TClassTable()
TClassTable is a singleton (i.e. only one can exist per application).
static char * Next()
Returns next class from sorted class table.
static char * At(UInt_t index)
Returns class at index from sorted class table.
static Bool_t Check(const char *cname, std::string &normname)
static void Remove(const char *cname)
Remove a class from the class table.
static ROOT::TClassRec ** fgSortedTable
static ROOT::TClassRec ** fgTable
static Bool_t CheckClassTableInit()
Return true fs the table exist.
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).
~TClassTable()
TClassTable singleton is deleted in Terminate().
static void RemoveAlternate(ROOT::TClassAlt *alt)
static ROOT::TClassRec * FindElement(const char *cname, Bool_t insert)
Find a class by name in the class table (using hash of name).
static std::vector< std::string > GetClassAlternativeNames(const char *cname)
static ROOT::TClassAlt * AddAlternate(const char *normname, const char *alternate)
TClass instances represent classes, structs and namespaces in the ROOT type system.
void SetUnloaded()
Call this method to indicate that the shared library containing this class's code has been removed (u...
void SetClassVersion(Version_t version)
Private function.
std::atomic< Bool_t > fVersionUsed
!Indicates whether GetClassVersion has been called
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.
virtual bool UseRWLock(Bool_t enable=true)
Set this collection to use a RW lock upon access, making it thread safe.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
void Add(TObject *obj) override
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
The TNamed class is the base class for all named ROOT classes.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
const char * GetName() const override
Returns name of object.
Collectable string class.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Persistent version of a TClass.
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
Regular expression class.
const char * Data() const
TString & Remove(Ssiz_t pos)
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
The namespace of The Lean Mean C++ Option Parser.
std::vector< std::pair< const char *, const char * > > & GetDelayedAddClassAlternate()
ROOT::TClassAlt * AddClassAlternate(const char *normName, const char *alternate)
Global function called by GenerateInitInstance.
std::vector< std::unique_ptr< TClassRec > > & GetDelayedAddClass()
void RemoveClass(const char *cname, TClass *cl)
Global function called by the dtor of a class's init class (see the ClassDef macro).
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 ClassDef macro).
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....
static UInt_t ClassTableHash(const char *name, UInt_t size)
void ResetClassVersion(TClass *, const char *, Short_t)
Global function to update the version number.
void RemoveClassAlternate(ROOT::TClassAlt *)
bool IsStdClass(const char *type)
return true if the class belongs to the std namespace
void GetNormalizedName(std::string &norm_name, std::string_view name)
Return the normalized name.