-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathTClass.cxx
7490 lines (6394 loc) · 270 KB
/
TClass.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// @(#)root/meta:$Id: 7109cb45f1219c2aae6be19906ae5a63e31972ef $
// Author: Rene Brun 07/01/95
/*************************************************************************
* Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
/** \class TClass
TClass instances represent classes, structs and namespaces in the ROOT type system.
TClass instances are created starting from different sources of information:
1. TStreamerInfo instances saved in a ROOT file which is opened. This is called in jargon an *emulated TClass*.
2. From TProtoClass instances saved in a ROOT pcm file created by the dictionary generator and the dictionary itself.
3. From a lookup in the AST built by cling.
If a TClass instance is built through the mechanisms 1. and 2., it does not contain information about methods of the
class/struct/namespace it represents. Conversely, if built through 3. or 1., it does not carry the information which is necessary
to ROOT to perform I/O of instances of the class/struct it represents.
The mechanisms 1., 2. and 3. are not mutually exclusive: it can happen that during the execution of the program, all
the three are triggered, modifying the state of the TClass instance.
In order to retrieve a TClass instance from the type system, a query can be executed as follows through the static
TClass::GetClass method:
~~~ {.cpp}
auto myClassTClass_0 = TClass::GetClass("myClass");
auto myClassTClass_1 = TClass::GetClass<myClass>();
auto myClassTClass_2 = TClass::GetClass(myClassTypeInfo);
~~~
The name of classes is crucial for ROOT. A careful procedure of *name normalization* is carried out for
each and every class. A *normalized name* is a valid C++ class name.
In order to access the name of a class within the ROOT type system, the method TClass::GetName() can be used.
*/
//*-*x7.5 macros/layout_class
#include "TClass.h"
#include "strlcpy.h"
#include "snprintf.h"
#include "TBaseClass.h"
#include "TBrowser.h"
#include "TBuffer.h"
#include "TClassGenerator.h"
#include "TClassEdit.h"
#include "TClassMenuItem.h"
#include "TClassRef.h"
#include "TClassTable.h"
#include "TDataMember.h"
#include "TDataType.h"
#include "TDatime.h"
#include "TEnum.h"
#include "TError.h"
#include "TExMap.h"
#include "TFunctionTemplate.h"
#include "THashList.h"
#include "TInterpreter.h"
#include "TMemberInspector.h"
#include "TMethod.h"
#include "TMethodArg.h"
#include "TMethodCall.h"
#include "TObjArray.h"
#include "TObjString.h"
#include "TProtoClass.h"
#include "TROOT.h"
#include "TRealData.h"
#include "TCheckHashRecursiveRemoveConsistency.h" // Private header
#include "TStreamer.h"
#include "TStreamerElement.h"
#include "TVirtualStreamerInfo.h"
#include "TVirtualCollectionProxy.h"
#include "TVirtualIsAProxy.h"
#include "TVirtualRefProxy.h"
#include "TVirtualMutex.h"
#include "TVirtualPad.h"
#include "THashTable.h"
#include "TSchemaRuleSet.h"
#include "TGenericClassInfo.h"
#include "TIsAProxy.h"
#include "TSchemaRule.h"
#include "TSystem.h"
#include "TThreadSlots.h"
#include "ThreadLocalStorage.h"
#include <cstdio>
#include <cctype>
#include <set>
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <typeinfo>
#include <cmath>
#include <cassert>
#include <vector>
#include <memory>
#include "TSpinLockGuard.h"
#ifdef WIN32
#include <io.h>
#include "Windows4Root.h"
#include <Psapi.h>
#define RTLD_DEFAULT ((void *)::GetModuleHandle(NULL))
#define dlsym(library, function_name) ::GetProcAddress((HMODULE)library, function_name)
#else
#include <dlfcn.h>
#endif
#include "TListOfDataMembers.h"
#include "TListOfFunctions.h"
#include "TListOfFunctionTemplates.h"
#include "TListOfEnums.h"
#include "TListOfEnumsWithLock.h"
#include "TViewPubDataMembers.h"
#include "TViewPubFunctions.h"
#include "TArray.h"
#include "TClonesArray.h"
#include "TRef.h"
#include "TRefArray.h"
using namespace std;
// Mutex to protect CINT and META operations
// (exported to be used for similar cases in related classes)
TVirtualMutex* gInterpreterMutex = nullptr;
namespace {
static constexpr const char kUndeterminedClassInfoName[] = "<NOT YET DETERMINED FROM fClassInfo>";
class TMmallocDescTemp {
private:
void *fSave;
public:
TMmallocDescTemp(void *value = nullptr) :
fSave(ROOT::Internal::gMmallocDesc) { ROOT::Internal::gMmallocDesc = value; }
~TMmallocDescTemp() { ROOT::Internal::gMmallocDesc = fSave; }
};
// When a new class is created, we need to be able to find
// if there are any existing classes that have the same name
// after any typedefs are expanded. (This only really affects
// template arguments.) To avoid having to search through all classes
// in that case, we keep a hash table mapping from the fully
// typedef-expanded names to the original class names.
// An entry is made in the table only if they are actually different.
//
// In these objects, the TObjString base holds the typedef-expanded
// name (the hash key), and fOrigName holds the original class name
// (the value to which the key maps).
//
class TNameMapNode : public TObjString {
public:
TString fOrigName;
TNameMapNode(const char *typedf, const char *orig) :
TObjString (typedf),
fOrigName (orig)
{
}
};
}
std::atomic<Int_t> TClass::fgClassCount;
static bool IsFromRootCling() {
// rootcling also uses TCling for generating the dictionary ROOT files.
const static bool foundSymbol = dlsym(RTLD_DEFAULT, "usedToIdentifyRootClingByDlSym");
return foundSymbol;
}
// Implementation of the TDeclNameRegistry
////////////////////////////////////////////////////////////////////////////////
/// TDeclNameRegistry class constructor.
TClass::TDeclNameRegistry::TDeclNameRegistry(Int_t verbLevel): fVerbLevel(verbLevel)
{
// MSVC doesn't support fSpinLock=ATOMIC_FLAG_INIT; in the class definition
std::atomic_flag_clear( &fSpinLock );
}
////////////////////////////////////////////////////////////////////////////////
/// Extract this part of the name
/// 1. Templates `ns::%ns2::,,,::%THISPART<...`
/// 2. Namespaces,classes `ns::%ns2::,,,::%THISPART`
void TClass::TDeclNameRegistry::AddQualifiedName(const char *name)
{
// Sanity check
auto strLen = name ? strlen(name) : 0;
if (strLen == 0) return;
// find <. If none, put end of string
const char* endCharPtr = strchr(name, '<');
endCharPtr = !endCharPtr ? &name[strLen] : endCharPtr;
// find last : before the <. If not found, put begin of string
const char* beginCharPtr = endCharPtr;
while (beginCharPtr!=name){
if (*beginCharPtr==':'){
beginCharPtr++;
break;
}
beginCharPtr--;
}
beginCharPtr = beginCharPtr!=endCharPtr ? beginCharPtr : name;
std::string s(beginCharPtr, endCharPtr);
if (fVerbLevel>1)
printf("TDeclNameRegistry::AddQualifiedName Adding key %s for class/namespace %s\n", s.c_str(), name);
ROOT::Internal::TSpinLockGuard slg(fSpinLock);
fClassNamesSet.insert(s);
}
////////////////////////////////////////////////////////////////////////////////
Bool_t TClass::TDeclNameRegistry::HasDeclName(const char *name) const
{
Bool_t found = false;
{
ROOT::Internal::TSpinLockGuard slg(fSpinLock);
found = fClassNamesSet.find(name) != fClassNamesSet.end();
}
return found;
}
////////////////////////////////////////////////////////////////////////////////
TClass::TDeclNameRegistry::~TDeclNameRegistry()
{
if (fVerbLevel > 1) {
printf("TDeclNameRegistry Destructor. List of %lu names:\n",
(long unsigned int)fClassNamesSet.size());
for (auto const & key: fClassNamesSet) {
printf(" - %s\n", key.c_str());
}
}
}
////////////////////////////////////////////////////////////////////////////////
TClass::InsertTClassInRegistryRAII::InsertTClassInRegistryRAII(TClass::EState &state,
const char *name,
TDeclNameRegistry &emuRegistry): fState(state),fName(name), fNoInfoOrEmuOrFwdDeclNameRegistry(emuRegistry) {}
////////////////////////////////////////////////////////////////////////////////
TClass::InsertTClassInRegistryRAII::~InsertTClassInRegistryRAII() {
if (fState == TClass::kNoInfo ||
fState == TClass::kEmulated ||
fState == TClass::kForwardDeclared){
fNoInfoOrEmuOrFwdDeclNameRegistry.AddQualifiedName(fName);
}
}
// Initialise the global member of TClass
TClass::TDeclNameRegistry TClass::fNoInfoOrEmuOrFwdDeclNameRegistry;
//Intent of why/how TClass::New() is called
//[Not a static data member because MacOS does not support static thread local data member ... who knows why]
TClass::ENewType &TClass__GetCallingNew() {
TTHREAD_TLS(TClass::ENewType) fgCallingNew = TClass::kRealNew;
return fgCallingNew;
}
struct TClass__GetCallingNewRAII
{
TClass::ENewType &fCurrentValue;
TClass::ENewType fOldValue;
TClass__GetCallingNewRAII(TClass::ENewType newvalue) :
fCurrentValue(TClass__GetCallingNew()),
fOldValue(fCurrentValue)
{
fCurrentValue = newvalue;
}
~TClass__GetCallingNewRAII()
{
fCurrentValue = fOldValue;
}
};
void TClass::RegisterAddressInRepository(const char * /*where*/, void *location, const TClass *what) const
{
// Register the object for special handling in the destructor.
Version_t version = what->GetClassVersion();
// if (!fObjectVersionRepository.count(location)) {
// Info(where, "Registering address %p of class '%s' version %d", location, what->GetName(), version);
// } else {
// Warning(where, "Registering address %p again of class '%s' version %d", location, what->GetName(), version);
// }
{
R__LOCKGUARD2(fOVRMutex);
fObjectVersionRepository.insert(RepoCont_t::value_type(location, version));
}
#if 0
// This code could be used to prevent an address to be registered twice.
std::pair<RepoCont_t::iterator, Bool_t> tmp = fObjectVersionRepository.insert(RepoCont_t::value_type>(location, version));
if (!tmp.second) {
Warning(where, "Reregistering an object of class '%s' version %d at address %p", what->GetName(), version, p);
fObjectVersionRepository.erase(tmp.first);
tmp = fObjectVersionRepository.insert(RepoCont_t::value_type>(location, version));
if (!tmp.second) {
Warning(where, "Failed to reregister an object of class '%s' version %d at address %p", what->GetName(), version, location);
}
}
#endif
}
void TClass::UnregisterAddressInRepository(const char * /*where*/, void *location, const TClass *what) const
{
// Remove an address from the repository of address/object.
R__LOCKGUARD2(fOVRMutex);
RepoCont_t::iterator cur = fObjectVersionRepository.find(location);
for (; cur != fObjectVersionRepository.end();) {
RepoCont_t::iterator tmp = cur++;
if ((tmp->first == location) && (tmp->second == what->GetClassVersion())) {
// -- We still have an address, version match.
// Info(where, "Unregistering address %p of class '%s' version %d", location, what->GetName(), what->GetClassVersion());
fObjectVersionRepository.erase(tmp);
} else {
// -- No address, version match, we've reached the end.
break;
}
}
}
void TClass::MoveAddressInRepository(const char * /*where*/, void *oldadd, void *newadd, const TClass *what) const
{
// Register in the repository that an object has moved.
// Move not only the object itself but also any base classes or sub-objects.
size_t objsize = what->Size();
long delta = (char*)newadd - (char*)oldadd;
R__LOCKGUARD2(fOVRMutex);
RepoCont_t::iterator cur = fObjectVersionRepository.find(oldadd);
for (; cur != fObjectVersionRepository.end();) {
RepoCont_t::iterator tmp = cur++;
if (oldadd <= tmp->first && tmp->first < ( ((char*)oldadd) + objsize) ) {
// The location is within the object, let's move it.
fObjectVersionRepository.insert(RepoCont_t::value_type(((char*)tmp->first)+delta, tmp->second));
fObjectVersionRepository.erase(tmp);
} else {
// -- No address, version match, we've reached the end.
break;
}
}
}
//______________________________________________________________________________
//______________________________________________________________________________
namespace ROOT {
#define R__USE_STD_MAP
class TMapTypeToTClass {
#if defined R__USE_STD_MAP
// This wrapper class allow to avoid putting #include <map> in the
// TROOT.h header file.
public:
typedef std::map<std::string,TClass*> IdMap_t;
typedef IdMap_t::key_type key_type;
typedef IdMap_t::const_iterator const_iterator;
typedef IdMap_t::size_type size_type;
#ifdef R__WIN32
// Window's std::map does NOT defined mapped_type
typedef TClass* mapped_type;
#else
typedef IdMap_t::mapped_type mapped_type;
#endif
private:
IdMap_t fMap;
public:
void Add(const key_type &key, mapped_type &obj)
{
// Add the <key,obj> pair to the map.
fMap[key] = obj;
}
mapped_type Find(const key_type &key) const
{
// Find the type corresponding to the key.
IdMap_t::const_iterator iter = fMap.find(key);
mapped_type cl = nullptr;
if (iter != fMap.end()) cl = iter->second;
return cl;
}
void Remove(const key_type &key) {
// Remove the type corresponding to the key.
fMap.erase(key);
}
#else
private:
TMap fMap;
public:
#ifdef R__COMPLETE_MEM_TERMINATION
TMapTypeToTClass() {
TIter next(&fMap);
TObjString *key;
while((key = (TObjString*)next())) {
delete key;
}
}
#endif
void Add(const char *key, TClass *&obj) {
TObjString *realkey = new TObjString(key);
fMap.Add(realkey, obj);
}
TClass* Find(const char *key) const {
const TPair *a = (const TPair *)fMap.FindObject(key);
if (a) return (TClass*) a->Value();
return 0;
}
void Remove(const char *key) {
TObjString realkey(key);
TObject *actual = fMap.Remove(&realkey);
delete actual;
}
#endif
};
class TMapDeclIdToTClass {
// Wrapper class for the multimap of DeclId_t and TClass.
public:
typedef multimap<TDictionary::DeclId_t, TClass*> DeclIdMap_t;
typedef DeclIdMap_t::key_type key_type;
typedef DeclIdMap_t::mapped_type mapped_type;
typedef DeclIdMap_t::const_iterator const_iterator;
typedef std::pair <const_iterator, const_iterator> equal_range;
typedef DeclIdMap_t::size_type size_type;
private:
DeclIdMap_t fMap;
public:
void Add(const key_type &key, mapped_type obj)
{
// Add the <key,obj> pair to the map.
std::pair<const key_type, mapped_type> pair = make_pair(key, obj);
fMap.insert(pair);
}
size_type CountElementsWithKey(const key_type &key)
{
return fMap.count(key);
}
equal_range Find(const key_type &key) const
{
// Find the type corresponding to the key.
return fMap.equal_range(key);
}
void Remove(const key_type &key) {
// Remove the type corresponding to the key.
fMap.erase(key);
}
};
}
IdMap_t *TClass::GetIdMap() {
#ifdef R__COMPLETE_MEM_TERMINATION
static IdMap_t gIdMapObject;
return &gIdMapObject;
#else
static IdMap_t *gIdMap = new IdMap_t;
return gIdMap;
#endif
}
DeclIdMap_t *TClass::GetDeclIdMap() {
#ifdef R__COMPLETE_MEM_TERMINATION
static DeclIdMap_t gDeclIdMapObject;
return &gDeclIdMapObject;
#else
static DeclIdMap_t *gDeclIdMap = new DeclIdMap_t;
return gDeclIdMap;
#endif
}
////////////////////////////////////////////////////////////////////////////////
/// static: Add a class to the list and map of classes.
void TClass::AddClass(TClass *cl)
{
if (!cl) return;
R__LOCKGUARD(gInterpreterMutex);
gROOT->GetListOfClasses()->Add(cl);
if (cl->GetTypeInfo()) {
GetIdMap()->Add(cl->GetTypeInfo()->name(),cl);
}
if (cl->fClassInfo) {
GetDeclIdMap()->Add((void*)(cl->fClassInfo), cl);
}
}
////////////////////////////////////////////////////////////////////////////////
/// static: Add a TClass* to the map of classes.
void TClass::AddClassToDeclIdMap(TDictionary::DeclId_t id, TClass* cl)
{
if (!cl || !id) return;
GetDeclIdMap()->Add(id, cl);
}
////////////////////////////////////////////////////////////////////////////////
/// static: Remove a class from the list and map of classes
void TClass::RemoveClass(TClass *oldcl)
{
if (!oldcl) return;
R__LOCKGUARD(gInterpreterMutex);
gROOT->GetListOfClasses()->Remove(oldcl);
if (oldcl->GetTypeInfo()) {
GetIdMap()->Remove(oldcl->GetTypeInfo()->name());
}
if (oldcl->fClassInfo) {
//GetDeclIdMap()->Remove((void*)(oldcl->fClassInfo));
}
}
////////////////////////////////////////////////////////////////////////////////
void TClass::RemoveClassDeclId(TDictionary::DeclId_t id)
{
if (!id) return;
GetDeclIdMap()->Remove(id);
}
////////////////////////////////////////////////////////////////////////////////
/// Indirect call to the implementation of ShowMember allowing [forward]
/// declaration with out a full definition of the TClass class.
void ROOT::Class_ShowMembers(TClass *cl, const void *obj, TMemberInspector&insp)
{
gInterpreter->InspectMembers(insp, obj, cl, kFALSE);
}
//______________________________________________________________________________
//______________________________________________________________________________
class TDumpMembers : public TMemberInspector {
bool fNoAddr;
public:
TDumpMembers(bool noAddr): fNoAddr(noAddr) { }
using TMemberInspector::Inspect;
void Inspect(TClass *cl, const char *parent, const char *name, const void *addr, Bool_t isTransient) override;
};
////////////////////////////////////////////////////////////////////////////////
/// Print value of member mname.
///
/// This method is called by the ShowMembers() method for each
/// data member when object.Dump() is invoked.
///
/// - cl is the pointer to the current class
/// - pname is the parent name (in case of composed objects)
/// - mname is the data member name
/// - add is the data member address
void TDumpMembers::Inspect(TClass *cl, const char *pname, const char *mname, const void *add, Bool_t /* isTransient */)
{
const Int_t kvalue = 30;
#ifdef R__B64
const Int_t ktitle = 50;
#else
const Int_t ktitle = 42;
#endif
const Int_t kline = 1024;
Int_t cdate = 0;
Int_t ctime = 0;
UInt_t *cdatime = nullptr;
char line[kline];
TDataType *membertype;
EDataType memberDataType = kNoType_t;
const char *memberName;
const char *memberFullTypeName;
const char *memberTitle;
Bool_t isapointer;
Bool_t isbasic;
Bool_t isarray;
if (TDataMember *member = cl->GetDataMember(mname)) {
if (member->GetDataType()) {
memberDataType = (EDataType)member->GetDataType()->GetType();
}
memberName = member->GetName();
memberFullTypeName = member->GetFullTypeName();
memberTitle = member->GetTitle();
isapointer = member->IsaPointer();
isbasic = member->IsBasic();
membertype = member->GetDataType();
isarray = member->GetArrayDim();
} else if (!cl->IsLoaded()) {
// The class is not loaded, hence it is 'emulated' and the main source of
// information is the StreamerInfo.
TVirtualStreamerInfo *info = cl->GetStreamerInfo();
if (!info) return;
const char *cursor = mname;
while ( (*cursor)=='*' ) ++cursor;
TString elname( cursor );
Ssiz_t pos = elname.Index("[");
if ( pos != kNPOS ) {
elname.Remove( pos );
}
TStreamerElement *element = (TStreamerElement*)info->GetElements()->FindObject(elname.Data());
if (!element) return;
memberFullTypeName = element->GetTypeName();
memberDataType = (EDataType)element->GetType();
memberName = element->GetName();
memberTitle = element->GetTitle();
isapointer = element->IsaPointer() || element->GetType() == TVirtualStreamerInfo::kCharStar;
membertype = gROOT->GetType(memberFullTypeName);
isbasic = membertype !=nullptr;
isarray = element->GetArrayDim();
} else {
return;
}
Bool_t isdate = kFALSE;
if (strcmp(memberName,"fDatime") == 0 && memberDataType == kUInt_t) {
isdate = kTRUE;
}
Bool_t isbits = kFALSE;
if (strcmp(memberName,"fBits") == 0 && memberDataType == kUInt_t) {
isbits = kTRUE;
}
TClass * dataClass = TClass::GetClass(memberFullTypeName);
Bool_t isTString = (dataClass == TString::Class());
static TClassRef stdClass("std::string");
Bool_t isStdString = (dataClass == stdClass);
Int_t i;
for (i = 0;i < kline; i++) line[i] = ' ';
line[kline-1] = 0;
snprintf(line,kline,"%s%s ",pname,mname);
i = strlen(line); line[i] = ' ';
// Encode data value or pointer value
char *pointer = (char*)add;
char **ppointer = (char**)(pointer);
if (isapointer) {
char **p3pointer = (char**)(*ppointer);
if (!p3pointer)
snprintf(&line[kvalue],kline-kvalue,"->0");
else if (!isbasic) {
if (!fNoAddr) {
snprintf(&line[kvalue],kline-kvalue,"->%zx ", (size_t)p3pointer);
}
} else if (membertype) {
if (!strcmp(membertype->GetTypeName(), "char")) {
i = strlen(*ppointer);
if (kvalue+i > kline) i=kline-1-kvalue;
Bool_t isPrintable = kTRUE;
for (Int_t j = 0; j < i; j++) {
if (!std::isprint((*ppointer)[j])) {
isPrintable = kFALSE;
break;
}
}
if (isPrintable) {
strncpy(line + kvalue, *ppointer, i);
line[kvalue+i] = 0;
} else {
line[kvalue] = 0;
}
} else {
strncpy(&line[kvalue], membertype->AsString(p3pointer), TMath::Min(kline-1-kvalue,(int)strlen(membertype->AsString(p3pointer))));
}
} else if (!strcmp(memberFullTypeName, "char*") ||
!strcmp(memberFullTypeName, "const char*")) {
i = strlen(*ppointer);
if (kvalue+i >= kline) i=kline-1-kvalue;
Bool_t isPrintable = kTRUE;
for (Int_t j = 0; j < i; j++) {
if (!std::isprint((*ppointer)[j])) {
isPrintable = kFALSE;
break;
}
}
if (isPrintable) {
strncpy(line + kvalue, *ppointer, std::min( i, kline - kvalue));
line[kvalue+i] = 0;
} else {
line[kvalue] = 0;
}
} else {
if (!fNoAddr) {
snprintf(&line[kvalue],kline-kvalue,"->%zx ", (size_t)p3pointer);
}
}
} else if (membertype) {
if (isdate) {
cdatime = (UInt_t*)pointer;
TDatime::GetDateTime(cdatime[0],cdate,ctime);
snprintf(&line[kvalue],kline-kvalue,"%d/%d",cdate,ctime);
} else if (isbits) {
snprintf(&line[kvalue],kline-kvalue,"0x%08x", *(UInt_t*)pointer);
} else {
strncpy(&line[kvalue], membertype->AsString(pointer), TMath::Min(kline-1-kvalue,(int)strlen(membertype->AsString(pointer))));
}
} else {
if (isStdString) {
std::string *str = (std::string*)pointer;
snprintf(&line[kvalue],kline-kvalue,"%s",str->c_str());
} else if (isTString) {
TString *str = (TString*)pointer;
snprintf(&line[kvalue],kline-kvalue,"%s",str->Data());
} else {
if (!fNoAddr) {
snprintf(&line[kvalue],kline-kvalue,"->%zx ", (size_t)pointer);
}
}
}
// Encode data member title
if (isdate == kFALSE && strcmp(memberFullTypeName, "char*") && strcmp(memberFullTypeName, "const char*")) {
i = strlen(&line[0]); line[i] = ' ';
assert(250 > ktitle);
strlcpy(&line[ktitle],memberTitle,250-ktitle+1); // strlcpy copy 'size-1' characters.
}
if (isarray) {
// Should iterate over the element
strncat(line, " ...", kline-strlen(line)-1);
}
Printf("%s", line);
}
THashTable* TClass::fgClassTypedefHash = nullptr;
//______________________________________________________________________________
class TBuildRealData : public TMemberInspector {
private:
void *fRealDataObject;
TClass *fRealDataClass;
public:
TBuildRealData(void *obj, TClass *cl) {
// Main constructor.
fRealDataObject = obj;
fRealDataClass = cl;
}
using TMemberInspector::Inspect;
void Inspect(TClass *cl, const char *parent, const char *name, const void *addr, Bool_t isTransient) override;
};
////////////////////////////////////////////////////////////////////////////////
/// This method is called from ShowMembers() via BuildRealdata().
void TBuildRealData::Inspect(TClass* cl, const char* pname, const char* mname, const void* add, Bool_t isTransient)
{
TDataMember* dm = cl->GetDataMember(mname);
if (!dm) {
return;
}
Bool_t isTransientMember = kFALSE;
if (!dm->IsPersistent()) {
// For the DataModelEvolution we need access to the transient member.
// so we now record them in the list of RealData.
isTransientMember = kTRUE;
isTransient = kTRUE;
}
TString rname( pname );
// Take into account cases like TPaveStats->TPaveText->TPave->TBox.
// Check that member is in a derived class or an object in the class.
if (cl != fRealDataClass) {
if (!fRealDataClass->InheritsFrom(cl)) {
Ssiz_t dot = rname.Index('.');
if (dot == kNPOS) {
return;
}
rname[dot] = '\0';
if (!fRealDataClass->GetDataMember(rname)) {
//could be a data member in a base class like in this example
// class Event : public Data {
// class Data : public TObject {
// EventHeader fEvtHdr;
// class EventHeader {
// Int_t fEvtNum;
// Int_t fRun;
// Int_t fDate;
// EventVertex fVertex;
// class EventVertex {
// EventTime fTime;
// class EventTime {
// Int_t fSec;
// Int_t fNanoSec;
if (!fRealDataClass->GetBaseDataMember(rname)) {
return;
}
}
rname[dot] = '.';
}
}
Longptr_t offset = Longptr_t(((Longptr_t) add) - ((Longptr_t) fRealDataObject));
if (TClassEdit::IsStdArray(dm->GetTypeName())){ // We tackle the std array case
TString rdName;
TRealData::GetName(rdName,dm);
rname += rdName;
TRealData* rd = new TRealData(rname.Data(), offset, dm);
fRealDataClass->GetListOfRealData()->Add(rd);
return;
}
rname += mname;
if (dm->IsaPointer()) {
// Data member is a pointer.
TRealData* rd = new TRealData(rname, offset, dm);
if (isTransientMember) { rd->SetBit(TRealData::kTransient); };
fRealDataClass->GetListOfRealData()->Add(rd);
} else {
// Data Member is a basic data type.
TRealData* rd = new TRealData(rname, offset, dm);
if (isTransientMember) { rd->SetBit(TRealData::kTransient); };
if (!dm->IsBasic()) {
rd->SetIsObject(kTRUE);
// Make sure that BuildReadData is called for any abstract
// bases classes involved in this object, i.e for all the
// classes composing this object (base classes, type of
// embedded object and same for their data members).
//
TClass* dmclass = TClass::GetClass(dm->GetTypeName(), kTRUE, isTransient);
if (!dmclass) {
dmclass = TClass::GetClass(dm->GetTrueTypeName(), kTRUE, isTransient);
}
if (dmclass) {
if ((dmclass != cl) && !dm->IsaPointer()) {
if (dmclass->GetCollectionProxy()) {
TClass* valcl = dmclass->GetCollectionProxy()->GetValueClass();
// We create the real data for the content of the collection to help the case
// of split branches in a TTree (where the node for the data member itself
// might have been elided). However, in some cases, like transient members
// and/or classes, the content might not be create-able. An example is the
// case of a map<A,B> where either A or B does not have default constructor
// and thus the compilation of the default constructor for pair<A,B> will
// fail (noisily) [This could also apply to any template instance, where it
// might have a default constructor definition that can not be compiled due
// to the template parameter]
if (valcl) {
Bool_t wantBuild = kTRUE;
if (valcl->Property() & kIsAbstract) wantBuild = kFALSE;
if ( (isTransient)
&& (dmclass->GetCollectionProxy()->GetProperties() & TVirtualCollectionProxy::kIsEmulated)
&& (!valcl->IsLoaded()) ) {
// Case where the collection dictionary was not requested and
// the content's dictionary was also not requested.
// [This is a super set of what we need, but we can't really detect it :(]
wantBuild = kFALSE;
}
if (wantBuild) valcl->BuildRealData(nullptr, isTransient);
}
} else {
void* addrForRecursion = nullptr;
if (GetObjectValidity() == kValidObjectGiven)
addrForRecursion = const_cast<void*>(add);
dmclass->BuildRealData(addrForRecursion, isTransient);
}
}
}
}
fRealDataClass->GetListOfRealData()->Add(rd);
}
}
//______________________________________________________________________________
//______________________________________________________________________________
//______________________________________________________________________________
////////////////////////////////////////////////////////////////////////////////
class TAutoInspector : public TMemberInspector {
public:
Int_t fCount;
TBrowser *fBrowser;
TAutoInspector(TBrowser *b)
{
// main constructor.
fBrowser = b; fCount = 0;
}
virtual ~TAutoInspector() {}
using TMemberInspector::Inspect;
void Inspect(TClass *cl, const char *parent, const char *name, const void *addr, Bool_t isTransient) override;
Bool_t IsTreatingNonAccessibleTypes() override { return kFALSE; }
};
////////////////////////////////////////////////////////////////////////////////
/// This method is called from ShowMembers() via AutoBrowse().
void TAutoInspector::Inspect(TClass *cl, const char *tit, const char *name,
const void *addr, Bool_t /* isTransient */)
{
if(tit && strchr(tit,'.')) return ;
if (fCount && !fBrowser) return;
TString ts;
if (!cl) return;
//if (*(cl->GetName()) == 'T') return;
if (*name == '*') name++;
int ln = strcspn(name,"[ ");
TString iname(name,ln);
ClassInfo_t *classInfo = cl->GetClassInfo();
if (!classInfo) return;
// Browse data members
DataMemberInfo_t *m = gCling->DataMemberInfo_Factory(classInfo, TDictionary::EMemberSelection::kNoUsingDecls);
TString mname;
int found=0;
while (gCling->DataMemberInfo_Next(m)) { // MemberLoop
mname = gCling->DataMemberInfo_Name(m);
mname.ReplaceAll("*","");
if ((found = (iname==mname))) break;
}
assert(found);
// we skip: non static members and non objects
// - the member G__virtualinfo inserted by the CINT RTTI system
//Long_t prop = m.Property() | m.Type()->Property();
Long_t prop = gCling->DataMemberInfo_Property(m) | gCling->DataMemberInfo_TypeProperty(m);
if (prop & kIsStatic) return;
if (prop & kIsFundamental) return;
if (prop & kIsEnum) return;
if (mname == "G__virtualinfo") return;
int size = sizeof(void*);
int nmax = 1;
if (prop & kIsArray) {
for (int dim = 0; dim < gCling->DataMemberInfo_ArrayDim(m); dim++) nmax *= gCling->DataMemberInfo_MaxIndex(m,dim);
}
std::string clmName(TClassEdit::ShortType(gCling->DataMemberInfo_TypeName(m),
TClassEdit::kDropTrailStar) );
TClass * clm = TClass::GetClass(clmName.c_str());
R__ASSERT(clm);
if (!(prop & kIsPointer)) {
size = clm->Size();
if (size==0) size = gCling->DataMemberInfo_TypeSize(m);
}
gCling->DataMemberInfo_Delete(m);
TVirtualCollectionProxy *proxy = clm->GetCollectionProxy();
for(int i=0; i<nmax; i++) {
char *ptr = (char*)addr + i*size;
void *obj = (prop & kIsPointer) ? *((void**)ptr) : (TObject*)ptr;
if (!obj) continue;
fCount++;
if (!fBrowser) return;
TString bwname;
TClass *actualClass = clm->GetActualClass(obj);
if (clm->IsTObject()) {
TObject *tobj = (TObject*)clm->DynamicCast(TObject::Class(),obj);
bwname = tobj->GetName();
} else {
bwname = actualClass->GetName();
bwname += "::";
bwname += mname;
}