Logo ROOT   6.08/07
Reference Guide
TClassTable.cxx
Go to the documentation of this file.
1 // @(#)root/cont:$Id$
2 // Author: Fons Rademakers 11/08/95
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class TClassTable
13 \ingroup Containers
14 This class registers for all classes their name, id and dictionary
15 function in a hash table. Classes are automatically added by the
16 ctor of a special init class when a global of this init class is
17 initialized when the program starts (see the ClassImp macro).
18 */
19 
20 #include "RConfig.h"
21 #include <stdlib.h>
22 #include <string>
23 #include <map>
24 #include <typeinfo>
25 #include "Riostream.h"
26 #include <memory>
27 
28 #include "TClassTable.h"
29 #include "TClass.h"
30 #include "TClassEdit.h"
31 #include "TProtoClass.h"
32 #include "TROOT.h"
33 #include "TString.h"
34 #include "TError.h"
35 #include "TRegexp.h"
36 
37 #include "TObjString.h"
38 #include "TMap.h"
39 
40 #include "TInterpreter.h"
41 using namespace ROOT;
42 
44 
45 TClassAlt **TClassTable::fgAlternate;
46 TClassRec **TClassTable::fgTable;
47 TClassRec **TClassTable::fgSortedTable;
53 
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 
58 namespace ROOT {
59  class TClassRec {
60  public:
61  TClassRec(TClassRec *next) :
62  fName(0), fId(0), fDict(0), fInfo(0), fProto(0), fNext(next)
63  {}
64 
65  ~TClassRec() {
66  // TClassTable::fgIdMap->Remove(r->fInfo->name());
67  delete [] fName;
68  delete fProto;
69  delete fNext;
70  }
71 
72  char *fName;
73  Version_t fId;
74  Int_t fBits;
75  DictFuncPtr_t fDict;
76  const std::type_info *fInfo;
77  TProtoClass *fProto;
78  TClassRec *fNext;
79  };
80 
81  class TClassAlt {
82  public:
83  TClassAlt(const char*alternate, const char *normName, TClassAlt *next) :
84  fName(alternate), fNormName(normName), fNext(next)
85  {}
86 
87  ~TClassAlt() {
88  // Nothing more to delete.
89  }
90 
91  const char *fName; // Do not own
92  const char *fNormName; // Do not own
93  std::unique_ptr<TClassAlt> fNext;
94  };
95 
96 #define R__USE_STD_MAP
97  class TMapTypeToClassRec {
98 #if defined R__USE_STD_MAP
99  // This wrapper class allow to avoid putting #include <map> in the
100  // TROOT.h header file.
101  public:
102 #ifdef R__GLOBALSTL
103  typedef std::map<string, TClassRec*> IdMap_t;
104 #else
105  typedef std::map<std::string, TClassRec*> IdMap_t;
106 #endif
107  typedef IdMap_t::key_type key_type;
108  typedef IdMap_t::const_iterator const_iterator;
109  typedef IdMap_t::size_type size_type;
110 #ifdef R__WIN32
111  // Window's std::map does NOT defined mapped_type
112  typedef TClassRec* mapped_type;
113 #else
114  typedef IdMap_t::mapped_type mapped_type;
115 #endif
116 
117  private:
118  IdMap_t fMap;
119 
120  public:
121  void Add(const key_type &key, mapped_type &obj) {
122  fMap[key] = obj;
123  }
124 
125  mapped_type Find(const key_type &key) const {
126 
127  IdMap_t::const_iterator iter = fMap.find(key);
128  mapped_type cl = 0;
129  if (iter != fMap.end()) cl = iter->second;
130  return cl;
131  }
132 
133  void Remove(const key_type &key) { fMap.erase(key); }
134 
135  void Print() {
136  Info("TMapTypeToClassRec::Print", "printing the typeinfo map in TClassTable");
137  for (const_iterator iter = fMap.begin(); iter != fMap.end(); iter++) {
138  printf("Key: %40s 0x%lx\n", iter->first.c_str(), (unsigned long)iter->second);
139  }
140  }
141 #else
142  private:
143  TMap fMap;
144  public:
145 #ifdef R__COMPLETE_MEM_TERMINATION
146  ~TMapTypeToClassRec() {
147  TIter next(&fMap);
148  TObjString *key;
149  while((key = (TObjString*)next())) {
150  delete key;
151  }
152  }
153 #endif
154 
155  void Add(const char *key, TClassRec *&obj)
156  {
157  // Add <key,value> pair to the map.
158 
159  TObjString *realkey = new TObjString(key);
160  fMap.Add(realkey, (TObject*)obj);
161  }
162 
163  TClassRec *Find(const char *key) const {
164  // Find the value corresponding the key.
165  const TPair *a = (const TPair *)fMap.FindObject(key);
166  if (a) return (TClassRec*) a->Value();
167  return 0;
168  }
169 
170  void Remove(const char *key) {
171  // Remove the value corresponding the key.
172  TObjString realkey(key);
173  TObject *actual = fMap.Remove(&realkey);
174  delete actual;
175  }
176 
177  void Print() {
178  // Print the content of the map.
179  Info("TMapTypeToClassRec::Print", "printing the typeinfo map in TClassTable");
180  TIter next(&fMap);
181  TObjString *key;
182  while((key = (TObjString*)next())) {
183  printf("Key: %s\n",key->String().Data());
184  TClassRec *data = (TClassRec*)fMap.GetValue(key);
185  if (data) {
186  printf(" class: %s %d\n",data->fName,data->fId);
187  } else {
188  printf(" no class: \n");
189  }
190  }
191  }
192 #endif
193  };
194 
195  static UInt_t ClassTableHash(const char *name, UInt_t size)
196  {
197  auto p = reinterpret_cast<const unsigned char*>( name );
198  UInt_t slot = 0;
199 
200  while (*p) slot = slot<<1 ^ *p++;
201  slot %= size;
202 
203  return slot;
204  }
205 }
206 
207 ////////////////////////////////////////////////////////////////////////////////
208 /// TClassTable is a singleton (i.e. only one can exist per application).
209 
211 {
212  if (gClassTable) return;
213 
214  fgSize = 1009; //this is the result of (int)TMath::NextPrime(1000);
215  fgTable = new TClassRec* [fgSize];
216  fgAlternate = new TClassAlt* [fgSize];
217  fgIdMap = new IdMap_t;
218  memset(fgTable, 0, fgSize*sizeof(TClassRec*));
219  memset(fgAlternate, 0, fgSize*sizeof(TClassAlt*));
220  gClassTable = this;
221 }
222 
223 ////////////////////////////////////////////////////////////////////////////////
224 /// TClassTable singleton is deleted in Terminate().
225 
227 {
228  // Try to avoid spurious warning from memory leak checkers.
229  if (gClassTable != this) return;
230 
231  for (UInt_t i = 0; i < fgSize; i++) {
232  delete fgTable[i]; // Will delete all the elements in the chain.
233  }
234  delete [] fgTable; fgTable = 0;
235  delete [] fgSortedTable; fgSortedTable = 0;
236  delete fgIdMap; fgIdMap = 0;
237 }
238 
239 ////////////////////////////////////////////////////////////////////////////////
240 /// Print the class table. Before printing the table is sorted
241 /// alphabetically. Only classes specified in option are listed.
242 /// The default is to list all classes.
243 /// Standard wildcarding notation supported.
244 
245 void TClassTable::Print(Option_t *option) const
246 {
247  if (fgTally == 0 || !fgTable)
248  return;
249 
250  SortTable();
251 
252  int n = 0, ninit = 0, nl = 0;
253 
254  int nch = strlen(option);
255  TRegexp re(option, kTRUE);
256 
257  Printf("\nDefined classes");
258  Printf("class version bits initialized");
259  Printf("================================================================");
260  for (UInt_t i = 0; i < fgTally; i++) {
261  TClassRec *r = fgSortedTable[i];
262  if (!r) break;
263  n++;
264  TString s = r->fName;
265  if (nch && strcmp(option,r->fName) && s.Index(re) == kNPOS) continue;
266  nl++;
267  if (TClass::GetClass(r->fName, kFALSE)) {
268  ninit++;
269  Printf("%-35s %6d %7d Yes", r->fName, r->fId, r->fBits);
270  } else
271  Printf("%-35s %6d %7d No", r->fName, r->fId, r->fBits);
272  }
273  Printf("----------------------------------------------------------------");
274  Printf("Listed Classes: %4d Total classes: %4d initialized: %4d",nl, n, ninit);
275  Printf("================================================================\n");
276 }
277 
278 //---- static members --------------------------------------------------------
279 
280 ////////////////////////////////////////////////////////////////////////////////
281 /// Returns class at index from sorted class table. Don't use this iterator
282 /// while modifying the class table. The class table can be modified
283 /// when making calls like TClass::GetClass(), etc.
284 /// Returns 0 if index points beyond last class name.
285 
287 {
288  SortTable();
289  if (index < fgTally) {
290  TClassRec *r = fgSortedTable[index];
291  if (r) return r->fName;
292  }
293  return 0;
294 }
295 
296 //______________________________________________________________________________
297 int TClassTable::Classes() { return fgTally; }
298 //______________________________________________________________________________
299 void TClassTable::Init() { fgCursor = 0; SortTable(); }
300 
301 namespace ROOT { class TForNamespace {}; } // Dummy class to give a typeid to namespace (see also TGenericClassInfo)
302 
303 ////////////////////////////////////////////////////////////////////////////////
304 /// Add a class to the class table (this is a static function).
305 /// Note that the given cname *must* be already normalized.
306 
307 void TClassTable::Add(const char *cname, Version_t id, const std::type_info &info,
308  DictFuncPtr_t dict, Int_t pragmabits)
309 {
310  if (!gClassTable)
311  new TClassTable;
312 
313  // check if already in table, if so return
314  TClassRec *r = FindElementImpl(cname, kTRUE);
315  if (r->fName && r->fInfo) {
316  if ( strcmp(r->fInfo->name(),typeid(ROOT::TForNamespace).name())==0
317  && strcmp(info.name(),typeid(ROOT::TForNamespace).name())==0 ) {
318  // We have a namespace being reloaded.
319  // This okay we just keep the old one.
320  return;
321  }
322 // if (splitname.IsSTLCont()==0) {
323  if (!TClassEdit::IsStdClass(cname)) {
324  // Warn only for class that are not STD classes
325  ::Warning("TClassTable::Add", "class %s already in TClassTable", cname);
326  }
327  return;
328  } else if (ROOT::Internal::gROOTLocal && gCling) {
329  TClass *oldcl = (TClass*)gROOT->GetListOfClasses()->FindObject(cname);
330  if (oldcl) { // && oldcl->GetClassInfo()) {
331  // As a work-around to ROOT-6012, we need to register the class even if
332  // it is not a template instance, because a forward declaration in the header
333  // files loaded by the current dictionary wil also de-activate the update
334  // class info mechanism!
335 
336  // The TClass exist and already has a class info, so it must
337  // correspond to a class template instantiation which the interpreter
338  // was able to make with the library containing the TClass Init.
339  // Because it is already known to the interpreter, the update class info
340  // will not be triggered, we need to force it.
341  gCling->RegisterTClassUpdate(oldcl,dict);
342  }
343  }
344 
345  if (!r->fName) r->fName = StrDup(cname);
346  r->fId = id;
347  r->fBits = pragmabits;
348  r->fDict = dict;
349  r->fInfo = &info;
350 
351  fgIdMap->Add(info.name(),r);
352 
353  fgSorted = kFALSE;
354 }
355 
356 ////////////////////////////////////////////////////////////////////////////////
357 /// Add a class to the class table (this is a static function).
358 
360 {
361  if (!gClassTable)
362  new TClassTable;
363 
364  // By definition the name in the TProtoClass is (must be) the normalized
365  // name, so there is no need to tweak it.
366  const char *cname = proto->GetName();
367 
368  // check if already in table, if so return
369  TClassRec *r = FindElementImpl(cname, kTRUE);
370  if (r->fName) {
371  if (r->fProto) delete r->fProto;
372  r->fProto = proto;
373  return;
374  } else if (ROOT::Internal::gROOTLocal && gCling) {
375  TClass *oldcl = (TClass*)gROOT->GetListOfClasses()->FindObject(cname);
376  if (oldcl) { // && oldcl->GetClassInfo()) {
377  // As a work-around to ROOT-6012, we need to register the class even if
378  // it is not a template instance, because a forward declaration in the header
379  // files loaded by the current dictionary wil also de-activate the update
380  // class info mechanism!
381 
382  ::Warning("TClassTable::Add(TProtoClass*)","Called for existing class without a prior call add the dictionary function.");
383  }
384  }
385 
386  r->fName = StrDup(cname);
387  r->fId = 0;
388  r->fBits = 0;
389  r->fDict = 0;
390  r->fInfo = 0;
391  r->fProto= proto;
392 
393  fgSorted = kFALSE;
394 }
395 
396 ////////////////////////////////////////////////////////////////////////////////
397 
398 void TClassTable::AddAlternate(const char *normName, const char *alternate)
399 {
400  if (!gClassTable)
401  new TClassTable;
402 
403  UInt_t slot = ROOT::ClassTableHash(alternate, fgSize);
404 
405  for (const TClassAlt *a = fgAlternate[slot]; a; a = a->fNext.get()) {
406  if (strcmp(alternate,a->fName)==0) {
407  if (strcmp(normName,a->fNormName) != 0) {
408  fprintf(stderr,"Error in TClassTable::AddAlternate: "
409  "Second registration of %s with a different normalized name (old: '%s', new: '%s')\n",
410  alternate, a->fNormName, normName);
411  return;
412  }
413  }
414  }
415 
416  fgAlternate[slot] = new TClassAlt(alternate,normName,fgAlternate[slot]);
417 }
418 
419 ////////////////////////////////////////////////////////////////////////////////
420 
421 Bool_t TClassTable::Check(const char *cname, std::string &normname)
422 {
423  if (!gClassTable || !fgTable) return kFALSE;
424 
425  UInt_t slot = ROOT::ClassTableHash(cname, fgSize);
426 
427  // Check if 'cname' is a known normalized name.
428  for (TClassRec *r = fgTable[slot]; r; r = r->fNext)
429  if (strcmp(cname,r->fName)==0) return kTRUE;
430 
431  // See if 'cname' is register in the list of alternate names
432  for (const TClassAlt *a = fgAlternate[slot]; a; a = a->fNext.get()) {
433  if (strcmp(cname,a->fName)==0) {
434  normname = a->fNormName;
435  return kTRUE;
436  }
437  }
438 
439  return kFALSE;
440 }
441 
442 ////////////////////////////////////////////////////////////////////////////////
443 /// Remove a class from the class table. This happens when a shared library
444 /// is unloaded (i.e. the dtor's of the global init objects are called).
445 
446 void TClassTable::Remove(const char *cname)
447 {
448  if (!gClassTable || !fgTable) return;
449 
450  UInt_t slot = ROOT::ClassTableHash(cname,fgSize);
451 
452  TClassRec *r;
453  TClassRec *prev = 0;
454  for (r = fgTable[slot]; r; r = r->fNext) {
455  if (!strcmp(r->fName, cname)) {
456  if (prev)
457  prev->fNext = r->fNext;
458  else
459  fgTable[slot] = r->fNext;
460  fgIdMap->Remove(r->fInfo->name());
461  r->fNext = 0; // Do not delete the others.
462  delete r;
463  fgTally--;
464  fgSorted = kFALSE;
465  break;
466  }
467  prev = r;
468  }
469 }
470 
471 ////////////////////////////////////////////////////////////////////////////////
472 /// Find a class by name in the class table (using hash of name). Returns
473 /// 0 if the class is not in the table. Unless arguments insert is true in
474 /// which case a new entry is created and returned.
475 
476 TClassRec *TClassTable::FindElementImpl(const char *cname, Bool_t insert)
477 {
478  UInt_t slot = ROOT::ClassTableHash(cname,fgSize);
479 
480  for (TClassRec *r = fgTable[slot]; r; r = r->fNext)
481  if (strcmp(cname,r->fName)==0) return r;
482 
483  if (!insert) return 0;
484 
485  fgTable[slot] = new TClassRec(fgTable[slot]);
486 
487  fgTally++;
488  return fgTable[slot];
489 }
490 
491 ////////////////////////////////////////////////////////////////////////////////
492 /// Find a class by name in the class table (using hash of name). Returns
493 /// 0 if the class is not in the table. Unless arguments insert is true in
494 /// which case a new entry is created and returned.
495 /// cname can be any spelling of the class name. See FindElementImpl if the
496 /// name is already normalized.
497 
498 TClassRec *TClassTable::FindElement(const char *cname, Bool_t insert)
499 {
500  if (!fgTable) return 0;
501 
502  // The recorded name is normalized, let's make sure we convert the
503  // input accordingly.
504  std::string normalized;
505  TClassEdit::GetNormalizedName(normalized,cname);
506 
507  return FindElementImpl(normalized.c_str(), insert);
508 }
509 
510 ////////////////////////////////////////////////////////////////////////////////
511 /// Returns the ID of a class.
512 
513 Version_t TClassTable::GetID(const char *cname)
514 {
515  TClassRec *r = FindElement(cname);
516  if (r) return r->fId;
517  return -1;
518 }
519 
520 ////////////////////////////////////////////////////////////////////////////////
521 /// Returns the pragma bits as specified in the LinkDef.h file.
522 
524 {
525  TClassRec *r = FindElement(cname);
526  if (r) return r->fBits;
527  return 0;
528 }
529 
530 ////////////////////////////////////////////////////////////////////////////////
531 /// Given the class name returns the Dictionary() function of a class
532 /// (uses hash of name).
533 
535 {
536  if (gDebug > 9) {
537  ::Info("GetDict", "searches for %s", cname);
538  fgIdMap->Print();
539  }
540 
541  TClassRec *r = FindElement(cname);
542  if (r) return r->fDict;
543  return 0;
544 }
545 
546 ////////////////////////////////////////////////////////////////////////////////
547 /// Given the std::type_info returns the Dictionary() function of a class
548 /// (uses hash of std::type_info::name()).
549 
550 DictFuncPtr_t TClassTable::GetDict(const std::type_info& info)
551 {
552  if (gDebug > 9) {
553  ::Info("GetDict", "searches for %s at 0x%lx", info.name(), (Long_t)&info);
554  fgIdMap->Print();
555  }
556 
557  TClassRec *r = fgIdMap->Find(info.name());
558  if (r) return r->fDict;
559  return 0;
560 }
561 
562 ////////////////////////////////////////////////////////////////////////////////
563 /// Given the normalized class name returns the Dictionary() function of a class
564 /// (uses hash of name).
565 
567 {
568  if (gDebug > 9) {
569  ::Info("GetDict", "searches for %s", cname);
570  fgIdMap->Print();
571  }
572 
573  TClassRec *r = FindElementImpl(cname,kFALSE);
574  if (r) return r->fDict;
575  return 0;
576 }
577 
578 ////////////////////////////////////////////////////////////////////////////////
579 /// Given the class name returns the TClassProto object for the class.
580 /// (uses hash of name).
581 
583 {
584  if (gDebug > 9) {
585  ::Info("GetDict", "searches for %s", cname);
586  fgIdMap->Print();
587  }
588 
589  TClassRec *r = FindElement(cname);
590  if (r) return r->fProto;
591  return 0;
592 }
593 
594 ////////////////////////////////////////////////////////////////////////////////
595 /// Given the class normalized name returns the TClassProto object for the class.
596 /// (uses hash of name).
597 
599 {
600  if (gDebug > 9) {
601  ::Info("GetDict", "searches for %s", cname);
602  fgIdMap->Print();
603  }
604 
605  TClassRec *r = FindElementImpl(cname,kFALSE);
606  if (r) return r->fProto;
607  return 0;
608 }
609 
610 ////////////////////////////////////////////////////////////////////////////////
611 
612 extern "C" {
613  static int ClassComp(const void *a, const void *b)
614  {
615  // Function used for sorting classes alphabetically.
616 
617  return strcmp((*(TClassRec **)a)->fName, (*(TClassRec **)b)->fName);
618  }
619 }
620 
621 ////////////////////////////////////////////////////////////////////////////////
622 /// Returns next class from sorted class table. Don't use this iterator
623 /// while modifying the class table. The class table can be modified
624 /// when making calls like TClass::GetClass(), etc.
625 
627 {
628  if (fgCursor < fgTally) {
629  TClassRec *r = fgSortedTable[fgCursor++];
630  return r->fName;
631  } else
632  return 0;
633 }
634 
635 ////////////////////////////////////////////////////////////////////////////////
636 /// Print the class table. Before printing the table is sorted
637 /// alphabetically.
638 
640 {
641  if (fgTally == 0 || !fgTable)
642  return;
643 
644  SortTable();
645 
646  int n = 0, ninit = 0;
647 
648  Printf("\nDefined classes");
649  Printf("class version bits initialized");
650  Printf("================================================================");
651  UInt_t last = fgTally;
652  for (UInt_t i = 0; i < last; i++) {
653  TClassRec *r = fgSortedTable[i];
654  if (!r) break;
655  n++;
656  // Do not use TClass::GetClass to avoid any risk of autoloading.
657  if (gROOT->GetListOfClasses()->FindObject(r->fName)) {
658  ninit++;
659  Printf("%-35s %6d %7d Yes", r->fName, r->fId, r->fBits);
660  } else
661  Printf("%-35s %6d %7d No", r->fName, r->fId, r->fBits);
662  }
663  Printf("----------------------------------------------------------------");
664  Printf("Total classes: %4d initialized: %4d", n, ninit);
665  Printf("================================================================\n");
666 }
667 
668 ////////////////////////////////////////////////////////////////////////////////
669 /// Sort the class table by ascending class ID's.
670 
672 {
673  if (!fgSorted) {
674  delete [] fgSortedTable;
675  fgSortedTable = new TClassRec* [fgTally];
676 
677  int j = 0;
678  for (UInt_t i = 0; i < fgSize; i++)
679  for (TClassRec *r = fgTable[i]; r; r = r->fNext)
680  fgSortedTable[j++] = r;
681 
682  ::qsort(fgSortedTable, fgTally, sizeof(TClassRec *), ::ClassComp);
683  fgSorted = kTRUE;
684  }
685 }
686 
687 ////////////////////////////////////////////////////////////////////////////////
688 /// Deletes the class table (this static class function calls the dtor).
689 
691 {
692  if (gClassTable) {
693  for (UInt_t i = 0; i < fgSize; i++)
694  delete fgTable[i]; // Will delete all the elements in the chain.
695 
696  delete [] fgTable; fgTable = 0;
697  delete [] fgSortedTable; fgSortedTable = 0;
698  delete fgIdMap; fgIdMap = 0;
699  fgSize = 0;
700  SafeDelete(gClassTable);
701  }
702 }
703 
704 ////////////////////////////////////////////////////////////////////////////////
705 /// Global function called by the ctor of a class's init class
706 /// (see the ClassImp macro).
707 
708 void ROOT::AddClass(const char *cname, Version_t id,
709  const std::type_info& info,
710  DictFuncPtr_t dict,
711  Int_t pragmabits)
712 {
713  TClassTable::Add(cname, id, info, dict, pragmabits);
714 }
715 
716 ////////////////////////////////////////////////////////////////////////////////
717 /// Global function called by GenerateInitInstance.
718 /// (see the ClassImp macro).
719 
720 void ROOT::AddClassAlternate(const char *normName, const char *alternate)
721 {
722  TClassTable::AddAlternate(normName,alternate);
723 }
724 
725 ////////////////////////////////////////////////////////////////////////////////
726 /// Global function to update the version number.
727 /// This is called via the RootClassVersion macro.
728 ///
729 /// if cl!=0 and cname==-1, set the new class version if and only is
730 /// greater than the existing one and greater or equal to 2;
731 /// and also ignore the request if fVersionUsed is true.
732 ///
733 /// Note on class version number:
734 /// - If no class has been specified, TClass::GetVersion will return -1
735 /// - The Class Version 0 request the whole object to be transient
736 /// - The Class Version 1, unless specify via ClassDef indicates that the
737 /// I/O should use the TClass checksum to distinguish the layout of the class
738 
739 void ROOT::ResetClassVersion(TClass *cl, const char *cname, Short_t newid)
740 {
741  if (cname && cname!=(void*)-1) {
742  TClassRec *r = TClassTable::FindElement(cname,kFALSE);
743  if (r) r->fId = newid;
744  }
745  if (cl) {
746  if (cl->fVersionUsed) {
747  // Problem, the reset is called after the first usage!
748  if (cname!=(void*)-1)
749  Error("ResetClassVersion","Version number of %s can not be changed after first usage!",
750  cl->GetName());
751  } else {
752  if (newid < 0) {
753  Error("SetClassVersion","The class version (for %s) must be positive (value %d is ignored)",cl->GetName(),newid);
754  }
755  if (cname==(void*)-1) {
756  if (cl->fClassVersion<newid && 2<=newid) {
757  cl->SetClassVersion(newid);
758  }
759  } else {
760  cl->SetClassVersion(newid);
761  }
762  }
763  }
764 }
765 
766 
767 ////////////////////////////////////////////////////////////////////////////////
768 /// Global function called by the dtor of a class's init class
769 /// (see the ClassImp macro).
770 
771 void ROOT::RemoveClass(const char *cname)
772 {
773  // don't delete class information since it is needed by the I/O system
774  // to write the StreamerInfo to file
775  if (cname) {
776  // Let's still remove this information to allow reloading later.
777  // Anyway since the shared library has been unloaded, the dictionary
778  // pointer is now invalid ....
779  // We still keep the TClass object around because TFile needs to
780  // get to the TStreamerInfo.
781  if (gROOT && gROOT->GetListOfClasses()) {
782  TObject *pcname;
783  if ((pcname=gROOT->GetListOfClasses()->FindObject(cname))) {
784  TClass *cl = dynamic_cast<TClass*>(pcname);
785  if (cl) cl->SetUnloaded();
786  }
787  }
788  TClassTable::Remove(cname);
789  }
790 }
791 
792 ////////////////////////////////////////////////////////////////////////////////
793 /// Global function to register the implementation file and line of
794 /// a class template (i.e. NOT a concrete class).
795 
796 TNamed *ROOT::RegisterClassTemplate(const char *name, const char *file,
797  Int_t line)
798 {
799  static TList table;
800  static Bool_t isInit = kFALSE;
801  if (!isInit) {
802  table.SetOwner(kTRUE);
803  isInit = kTRUE;
804  }
805 
806  TString classname(name);
807  Ssiz_t loc = classname.Index("<");
808  if (loc >= 1) classname.Remove(loc);
809  if (file) {
810  TNamed *obj = new TNamed((const char*)classname, file);
811  obj->SetUniqueID(line);
812  table.Add(obj);
813  return obj;
814  } else {
815  return (TNamed*)table.FindObject(classname);
816  }
817 }
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&#39;s init class (see the ClassImp macro).
static ROOT::TClassRec ** fgSortedTable
Definition: TClassTable.h:50
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
short Version_t
Definition: RtypesCore.h:61
static Bool_t Check(const char *cname, std::string &normname)
TLine * line
Collectable string class.
Definition: TObjString.h:32
const char Option_t
Definition: RtypesCore.h:62
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&#39;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.
Definition: TClass.cxx:5327
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
Persistent version of a TClass.
Definition: TProtoClass.h:37
Regular expression class.
Definition: TRegexp.h:35
void Add(TObject *obj)
This function may not be used (but we need to provide it since it is a pure virtual in TCollection)...
Definition: TMap.cxx:53
#define gROOT
Definition: TROOT.h:364
ROOT::TMapTypeToClassRec IdMap_t
Definition: TClassTable.h:46
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
const Bool_t kFALSE
Definition: Rtypes.h:92
This class registers for all classes their name, id and dictionary function in a hash table...
Definition: TClassTable.h:40
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
Find an object in this list using its name.
Definition: TList.cxx:497
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).
static void Init()
#define SafeDelete(p)
Definition: RConfig.h:507
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
void AddClassAlternate(const char *normName, const char *alternate)
Global function called by GenerateInitInstance.
void Add(THist< DIMENSIONS, PRECISION_TO, STAT_TO... > &to, THist< DIMENSIONS, PRECISION_FROM, STAT_FROM... > &from)
Add two histograms.
Definition: THist.hxx:327
void Info(const char *location, const char *msgfmt,...)
XFontStruct * id
Definition: TGX11.cxx:108
std::atomic< Bool_t > fVersionUsed
saved remember if fOffsetStreamer has been set.
Definition: TClass.h:233
static ROOT::TClassRec ** fgTable
Definition: TClassTable.h:49
TClass *(* DictFuncPtr_t)()
Definition: Rtypes.h:75
TClassTable * gClassTable
Definition: TClassTable.cxx:43
TObject * Value() const
Definition: TMap.h:125
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition: TObject.cxx:750
A doubly linked list.
Definition: TList.h:47
R__EXTERN TROOT * gROOTLocal
Definition: TROOT.h:361
void ResetClassVersion(TClass *, const char *, Short_t)
Global function to update the version number.
TRandom2 r(17)
void RemoveClass(const char *cname)
Global function called by the dtor of a class&#39;s init class (see the ClassImp macro).
static void AddAlternate(const char *normname, const char *alternate)
static UInt_t fgTally
Definition: TClassTable.h:53
void GetNormalizedName(std::string &norm_name, std::string_view name)
Return the normalized name.
Definition: TClassEdit.cxx:788
void Print(Option_t *option="") const
Print the class table.
TObject * Remove(TObject *key)
Remove the (key,value) pair with key from the map.
Definition: TMap.cxx:295
void SetUnloaded()
Call this method to indicate that the shared library containing this class&#39;s code has been removed (u...
Definition: TClass.cxx:5879
static void Remove(const char *cname)
Remove a class from the class table.
unsigned int UInt_t
Definition: RtypesCore.h:42
short Short_t
Definition: RtypesCore.h:35
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.
Definition: TClass.h:81
ROOT::TMapTypeToTClass IdMap_t
Definition: TClass.h:78
void Warning(const char *location, const char *msgfmt,...)
TString fName
Definition: TNamed.h:36
bool IsStdClass(const char *type)
return true if the class belongs to the std namespace
TString & String()
Definition: TObjString.h:52
#define Printf
Definition: TGeoToOCC.h:18
char * StrDup(const char *str)
Duplicate the string str.
Definition: TString.cxx:2514
static UInt_t fgSize
Definition: TClassTable.h:52
static void Terminate()
Deletes the class table (this static class function calls the dtor).
long Long_t
Definition: RtypesCore.h:50
int Ssiz_t
Definition: RtypesCore.h:63
static IdMap_t * fgIdMap
Definition: TClassTable.h:51
Class used by TMap to store (key,value) pairs.
Definition: TMap.h:106
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.
#define ClassImp(name)
Definition: Rtypes.h:279
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 ...
Definition: TMap.h:44
static UInt_t fgCursor
Definition: TClassTable.h:55
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.
Definition: TClass.cxx:2893
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.
Definition: TObject.h:37
static void PrintTable()
Print the class table.
Version_t fClassVersion
Definition: TClass.h:201
TObject * FindObject(const char *keyname) const
Check if a (key,value) pair exists with keyname as name of the key.
Definition: TMap.cxx:214
virtual void Add(TObject *obj)
Definition: TList.h:81
const Ssiz_t kNPOS
Definition: Rtypes.h:115
static ROOT::TClassRec * FindElementImpl(const char *cname, Bool_t insert)
Find a class by name in the class table (using hash of name).
Definition: file.py:1
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
Definition: TRolke.cxx:630
const char * proto
Definition: civetweb.c:11652
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
Definition: TMap.cxx:235
static Bool_t fgSorted
Definition: TClassTable.h:54
R__EXTERN TInterpreter * gCling
Definition: TInterpreter.h:519
const Bool_t kTRUE
Definition: Rtypes.h:91
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)...
const Int_t n
Definition: legend1.C:16
char name[80]
Definition: TGX11.cxx:109
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
Definition: TClassTable.h:48