ATLAS Offline Software
Loading...
Searching...
No Matches
TScopeAdapter Class Reference

#include <RootType.h>

Collaboration diagram for TScopeAdapter:

Public Member Functions

 TScopeAdapter ()
 TScopeAdapter (TClass *klass)
 TScopeAdapter (const std::string &name, Bool_t load=kTRUE)
ATLAS_NOT_THREAD_SAFE TScopeAdapter (const std::string &name, Bool_t load, Bool_t quiet)
 TScopeAdapter (const TMemberAdapter &)
 TScopeAdapter (const std::type_info &typeinfo)
 operator TClass * () const
 operator Bool_t () const
std::string Name (unsigned int mod=Reflex::SCOPED) const
TScopeAdapter DeclaringScope () const
void * Construct () const
void * Construct (void *place) const
void Destruct (void *place) const
const std::type_info & TypeInfo () const
TPropertyListAdapter Properties () const
Bool_t IsPointer () const
Bool_t IsTemplateInstance () const
Bool_t IsTopScope () const
Bool_t IsFundamental () const
Bool_t IsEnum () const
Bool_t IsTypedef () const
Bool_t IsArray () const
TBaseAdapter BaseAt (size_t nth) const
size_t BaseSize () const
size_t SizeOf () const
TMemberAdapter FunctionMemberAt (size_t nth) const
size_t FunctionMemberSize () const
TMemberAdapter DataMemberAt (size_t nth) const
size_t DataMemberSize () const
TScopeAdapter TemplateArgumentAt (size_t nth) const
size_t TemplateArgumentSize () const
Bool_t IsComplete () const
Bool_t IsClass () const
Bool_t IsStruct () const
Bool_t IsNamespace () const
Bool_t IsAbstract () const
void * Id () const
TClass * Class () const
TTypeAdapter ToType () const
TScopeAdapter TypeOf () const
bool operator== (const TScopeAdapter &rh) const
bool operator!= (const TScopeAdapter &rh) const
bool operator< (const TScopeAdapter &rh) const

Static Public Member Functions

static TScopeAdapter ByName ATLAS_NOT_THREAD_SAFE (const std::string &name, Bool_t load=kTRUE, Bool_t quiet=kTRUE)
static TScopeAdapter ByNameNoQuiet (const std::string &name, Bool_t load=kTRUE)
static TScopeAdapter TypeAt (size_t nth)
static size_t TypeSize ()
static void EnableCintex ()

Private Member Functions

void Init (const std::string &name, Bool_t load, Bool_t quiet)

Private Attributes

std::string fName
TClassRef fClass
bool fIsFundamental = false

Detailed Description

Definition at line 119 of file RootType.h.

Constructor & Destructor Documentation

◆ TScopeAdapter() [1/6]

TScopeAdapter::TScopeAdapter ( )

Definition at line 377 of file RootType.cxx.

378{
379 /* empty */
380}

◆ TScopeAdapter() [2/6]

TScopeAdapter::TScopeAdapter ( TClass * klass)

Definition at line 382 of file RootType.cxx.

382 : fClass( klass )
383{
384// wrap a class (scope)
385 if ( fClass.GetClass() != 0 )
386 fName = fClass->GetName();
387}
TClassRef fClass
Definition RootType.h:202
std::string fName
Definition RootType.h:201

◆ TScopeAdapter() [3/6]

TScopeAdapter::TScopeAdapter ( const std::string & name,
Bool_t load = kTRUE )

Definition at line 500 of file RootType.cxx.

500 :
501 fName( name )
502{
503 Init (name, load, false);
504}
void Init(const std::string &name, Bool_t load, Bool_t quiet)
Definition RootType.cxx:519

◆ TScopeAdapter() [4/6]

TScopeAdapter::TScopeAdapter ( const std::string & name,
Bool_t load,
Bool_t quiet )

Definition at line 508 of file RootType.cxx.

508 :
509 fName( name )
510{
511 Int_t oldEIL = gErrorIgnoreLevel;
512 if( quiet ) gErrorIgnoreLevel = 3000;
513 Init (name, load, quiet);
514 gErrorIgnoreLevel = oldEIL;
515}

◆ TScopeAdapter() [5/6]

TScopeAdapter::TScopeAdapter ( const TMemberAdapter & mb)

Definition at line 571 of file RootType.cxx.

571 :
573 fClass( mb.Name( Reflex::SCOPED ).c_str() )
574{
575 /* empty */
576}
@ SCOPED
Definition RootType.h:27
@ QUALIFIED
Definition RootType.h:26

◆ TScopeAdapter() [6/6]

TScopeAdapter::TScopeAdapter ( const std::type_info & typeinfo)

Definition at line 550 of file RootType.cxx.

551 : fClass (TClassRef( TClass::GetClass(typeinfo) ) ) // MN: is that right?
552{
553 if( fClass.GetClass() ) {
554 // We apparently see this sometimes due to races in TClass.
555 // In that case, try retrieving it again.
556 // (See ATEAM-697.)
557 if (!fClass.GetClass()->HasDictionary()) {
558 fClass = TClassRef( TClass::GetClass(typeinfo) );
559 }
560 fName = fClass->GetName();
561 } else {
562 char buff[1024];
563 size_t len = sizeof(buff);
564 int status = 0;
565 fName = __cxxabiv1::__cxa_demangle(typeinfo.name(), buff, &len, &status);
566 fIsFundamental = true;
567 }
568}
bool fIsFundamental
Definition RootType.h:203
status
Definition merge.py:16

Member Function Documentation

◆ ATLAS_NOT_THREAD_SAFE()

TScopeAdapter ByName TScopeAdapter::ATLAS_NOT_THREAD_SAFE ( const std::string & name,
Bool_t load = kTRUE,
Bool_t quiet = kTRUE )
static

◆ BaseAt()

TBaseAdapter TScopeAdapter::BaseAt ( size_t nth) const

Definition at line 778 of file RootType.cxx.

779{
780// get the nth base of this class
781 return (TBaseClass*)fClass->GetListOfBases()->At( nth );
782}

◆ BaseSize()

size_t TScopeAdapter::BaseSize ( ) const

Definition at line 754 of file RootType.cxx.

755{
756// get the total number of base classes that this class has
757 if ( fClass.GetClass() && fClass->GetListOfBases() != 0 )
758 return fClass->GetListOfBases()->GetSize();
759
760 return 0;
761}

◆ ByNameNoQuiet()

TScopeAdapter TScopeAdapter::ByNameNoQuiet ( const std::string & name,
Bool_t load = kTRUE )
static

Definition at line 586 of file RootType.cxx.

588{
589 return TScopeAdapter (name, load);
590}

◆ Class()

TClass * TScopeAdapter::Class ( ) const
inline

Definition at line 183 of file RootType.h.

183{ return fClass.GetClass(); }

◆ Construct() [1/2]

void * TScopeAdapter::Construct ( ) const

Definition at line 666 of file RootType.cxx.

667{
668 return fClass.GetClass()? fClass.GetClass()->New() : 0;
669}

◆ Construct() [2/2]

void * RootType::Construct ( void * place) const

Definition at line 672 of file RootType.cxx.

672 {
673 return (place && fClass.GetClass())? fClass.GetClass()->New(place) : 0;
674}

◆ DataMemberAt()

TMemberAdapter TScopeAdapter::DataMemberAt ( size_t nth) const

Definition at line 812 of file RootType.cxx.

813{
814// get the nth data member of this class
815 return (TDataMember*)fClass->GetListOfDataMembers()->At( nth );
816}

◆ DataMemberSize()

size_t TScopeAdapter::DataMemberSize ( ) const

Definition at line 802 of file RootType.cxx.

803{
804// get the total number of data members that this class has
805 if ( fClass.GetClass() )
806 return fClass->GetListOfDataMembers()->GetSize();
807
808 return 0;
809}

◆ DeclaringScope()

TScopeAdapter TScopeAdapter::DeclaringScope ( ) const

Definition at line 655 of file RootType.cxx.

656{
657 std::string name = Name( Reflex::FINAL | Reflex::SCOPED );
658 std::string::size_type pos = name.rfind( "::" );
659 if ( pos == std::string::npos )
660 return TScopeAdapter( /* wrap global scope */
661 TClass::GetClass( gInterpreter->ClassInfo_Factory( "" ) ) );
662 return TScopeAdapter( name.substr( 0, pos ) );
663}
JetDumper::Name Name
Definition JetDumper.cxx:19
@ FINAL
Definition RootType.h:25

◆ Destruct()

void TScopeAdapter::Destruct ( void * place) const

Definition at line 677 of file RootType.cxx.

678{
679 if (place && fClass.GetClass()) fClass.GetClass()->Destructor(place);
680}

◆ EnableCintex()

void TScopeAdapter::EnableCintex ( )
inlinestatic

Definition at line 196 of file RootType.h.

196{}

◆ FunctionMemberAt()

TMemberAdapter TScopeAdapter::FunctionMemberAt ( size_t nth) const

Definition at line 795 of file RootType.cxx.

796{
797// get the nth method of this class
798 return (TMethod*)fClass->GetListOfMethods()->At( nth );
799}

◆ FunctionMemberSize()

size_t TScopeAdapter::FunctionMemberSize ( ) const

Definition at line 785 of file RootType.cxx.

786{
787// get the total number of methods that this class has
788 if ( fClass.GetClass() )
789 return fClass->GetListOfMethods()->GetSize();
790
791 return 0;
792}

◆ Id()

void * TScopeAdapter::Id ( ) const
inline

Definition at line 182 of file RootType.h.

182{ return fClass.GetClass(); }

◆ Init()

void TScopeAdapter::Init ( const std::string & name,
Bool_t load,
Bool_t quiet )
private

Definition at line 519 of file RootType.cxx.

520{
521 const string anonnmsp("(anonymous)");
522
523 if( !load ) {
524 // let GetClass() have a crack at it first, to prevent accidental loading
525 TClass* klass = TClass::GetClass( name.c_str(), load, quiet );
526 if( klass ) {
527 fClass = klass;
528 return;
529 }
530 } else {
531 // load
532 const string scoped_name = Name( Reflex::SCOPED );
533 fClass = TClassRef( scoped_name.c_str() );
534 if( fClass.GetClass() ) {
535 return;
536 }
537 }
538
539 // now check if GetClass failed because of lack of dictionary or it is maybe not a class at all
540 if( gROOT->GetType(name.c_str()) ) {
541 fIsFundamental = true;
542 } else if( TEnum::GetEnum(name.c_str(), load ? TEnum::kALoadAndInterpLookup : TEnum::kNone) ) {
543 // MN: enum, or anonymous type that could be an enum. for the moment mark it as fundamental
544 fIsFundamental = true;
545 }
546}

◆ IsAbstract()

Bool_t TScopeAdapter::IsAbstract ( ) const

Definition at line 954 of file RootType.cxx.

955{
956// test if this scope represents an abstract class
957 if ( fClass.GetClass() )
958 return fClass->Property() & kIsAbstract; // assume set only for classes
959
960 return kFALSE;
961}

◆ IsArray()

Bool_t TScopeAdapter::IsArray ( ) const

Definition at line 748 of file RootType.cxx.

749{
750 return fClass.GetClass()? fClass.GetClass()->Property() & kIsArray : false;
751}

◆ IsClass()

Bool_t TScopeAdapter::IsClass ( ) const

Definition at line 916 of file RootType.cxx.

917{
918// test if this scope represents a class
919 if ( fClass.GetClass() ) {
920 // some inverted logic: we don't have a TClass, but a builtin will be recognized, so
921 // if it is NOT a builtin, it is a class or struct (but may be missing dictionary)
922 return (fClass->Property() & kIsClass) || ! (fClass->Property() & kIsFundamental);
923 }
924
925 // no class can mean either is no class (i.e. builtin), or no dict or interpreted(?)
926 // as a workaround, use TDataTypes that has a full enumeration of builtin types
927 return TDataType( Name( Reflex::FINAL | Reflex::SCOPED ).c_str() ).GetType() == kOther_t;
928}

◆ IsComplete()

Bool_t TScopeAdapter::IsComplete ( ) const

Definition at line 895 of file RootType.cxx.

896{
897 // verify whether the dictionary of this class is fully available
898 Bool_t b = kFALSE;
899 std::string scname = Name( Reflex::SCOPED );
900 TClass* klass = TClass::GetClass( scname.c_str(), true, true );
901
902 if ( klass) {// works for normal case w/ dict
903 b = klass->HasDictionary();
904 }
905 else { // special case for forward declared classes
906 ClassInfo_t* ci = gInterpreter->ClassInfo_Factory( scname.c_str() );
907 if ( ci ) {
908 b = gInterpreter->ClassInfo_IsLoaded( ci );
909 gInterpreter->ClassInfo_Delete( ci ); // we own the fresh class info
910 }
911 }
912 return b;
913}

◆ IsEnum()

Bool_t TScopeAdapter::IsEnum ( ) const

Definition at line 738 of file RootType.cxx.

739{
740 return fClass.GetClass()? fClass.GetClass()->Property() & kIsEnum : false;
741}

◆ IsFundamental()

Bool_t TScopeAdapter::IsFundamental ( ) const

Definition at line 731 of file RootType.cxx.

732{
733 return fIsFundamental;
734// return fClass.GetClass()? fClass.GetClass()->Property() & kIsFundamental : false;
735}

◆ IsNamespace()

Bool_t TScopeAdapter::IsNamespace ( ) const

Definition at line 944 of file RootType.cxx.

945{
946// test if this scope represents a namespace
947 if ( fClass.GetClass() )
948 return fClass->Property() & kIsNamespace;
949
950 return kFALSE;
951}

◆ IsPointer()

Bool_t TScopeAdapter::IsPointer ( ) const

Definition at line 702 of file RootType.cxx.

703{
704// the assumption here is that the adapter can be initialized with a sugared
705// name, e.g. for function arguments
706 return *fName.rbegin() == '*';
707}

◆ IsStruct()

Bool_t TScopeAdapter::IsStruct ( ) const

Definition at line 931 of file RootType.cxx.

932{
933// test if this scope represents a struct
934 if ( fClass.GetClass() ) {
935 // same logic as for IsClass() above ...
936 return (fClass->Property() & kIsStruct) || ! (fClass->Property() & kIsFundamental);
937 }
938
939// same logic as for IsClass() above ...
940 return TDataType( Name( Reflex::FINAL | Reflex::SCOPED ).c_str() ).GetType() == kOther_t;
941}

◆ IsTemplateInstance()

Bool_t TScopeAdapter::IsTemplateInstance ( ) const

Definition at line 710 of file RootType.cxx.

711{
712// this concept differs quite a bit between ROOT/meta and Reflex; this code
713// supports both, with the addendum that the ROOT/meta idea of templates will
714// not have template arguments
715 if ( Name( Reflex::FINAL ).find('<') != std::string::npos )
716 return kTRUE; // Reflex notion of templates
717
718 if ( gInterpreter->CheckClassTemplate( Name( Reflex::SCOPED ).c_str() ) )
719 return kTRUE;
720
721 return kFALSE;
722}
std::string Name(unsigned int mod=Reflex::SCOPED) const
Definition RootType.cxx:612
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138

◆ IsTopScope()

Bool_t TScopeAdapter::IsTopScope ( ) const

Definition at line 725 of file RootType.cxx.

726{
727// check whether this corresponds to the global scope
728 return fClass->GetClassInfo() == gInterpreter->ClassInfo_Factory( "" );
729}

◆ IsTypedef()

Bool_t TScopeAdapter::IsTypedef ( ) const

Definition at line 743 of file RootType.cxx.

744{
745 return fClass.GetClass()? fClass.GetClass()->Property() & kIsTypedef : false;
746}

◆ Name()

std::string TScopeAdapter::Name ( unsigned int mod = Reflex::SCOPED) const

Definition at line 612 of file RootType.cxx.

613{
614// Return name of type described by fClass
615 if ( ! fClass.GetClass() || ! fClass->Property() ) {
616 // fundamental types have no class, and unknown classes have no property
617 std::string name = fName;
618
619 if ( mod & Reflex::FINAL )
620 name = ResolveTypedef( name );
621
622 if ( ! ( mod & Reflex::QUALIFIED ) )
624
625 return name;
626 }
627
628 std::string name = fClass->GetName();
629 if ( mod & Reflex::FINAL )
630 name = ResolveTypedef( name );
631
632 if ( ! (mod & Reflex::SCOPED) ) {
633 // remove scope from the name
634 Int_t tpl_open = 0;
635 for ( std::string::size_type pos = name.size() - 1; 0 < pos; --pos ) {
636 std::string::value_type c = name[ pos ];
637
638 // count '<' and '>' to be able to skip template contents
639 if ( c == '>' )
640 ++tpl_open;
641 else if ( c == '<' )
642 --tpl_open;
643 else if ( tpl_open == 0 && c == ':' && 0 < pos && name[ pos-1 ] == ':' ) {
644 // found scope, strip name from it
645 name = name.substr( pos+1, std::string::npos );
646 break;
647 }
648 }
649 }
650
651 return name;
652}
static const std::string ResolveTypedef(const std::string &tname)
Definition RootType.cxx:32
static const std::string UnqualifiedTypeName(const std::string &name)
Definition RootType.cxx:55

◆ operator Bool_t()

TScopeAdapter::operator Bool_t ( ) const

Definition at line 879 of file RootType.cxx.

880{
881 // check the validity of this scope (class)
882 if( fName.empty() ) return false;
883 if( fIsFundamental ) return true;
884
885 // MN: rewriting this method to avoid premature header parsing
886 TClass* klass = fClass.GetClass();
887 if( !klass ) return false;
888 if( klass->HasDictionary() ) return true;
889
890 // cout << "RootType: (Debug warning) Type " << fName << " has no dictionary!" << endl;
891 return false;
892}

◆ operator TClass *()

TScopeAdapter::operator TClass * ( ) const
inline

Definition at line 127 of file RootType.h.

127{ return fClass.GetClass(); }

◆ operator!=()

bool TScopeAdapter::operator!= ( const TScopeAdapter & rh) const
inline

Definition at line 190 of file RootType.h.

190 {
191 return ! (*this == rh);
192 }

◆ operator<()

bool TScopeAdapter::operator< ( const TScopeAdapter & rh) const

Definition at line 971 of file RootType.cxx.

972{
973// less-than operator, used for STL containers (makes little sense conceptually,
974// but this class is used as a key in std::map<>s for some reason; choosing to
975// compare on name here, as any simple comparison (e.g. GetClassInfo()) is bound
976// to fall apart if classes are unloaded/updated/replaced).
979}

◆ operator==()

bool TScopeAdapter::operator== ( const TScopeAdapter & rh) const

Definition at line 964 of file RootType.cxx.

965{
966// comparison operator, used for STL containers (implementation debatable)
967 return fClass.GetClass() == rh.fClass.GetClass();
968}

◆ Properties()

TPropertyListAdapter TScopeAdapter::Properties ( ) const

Definition at line 694 of file RootType.cxx.

695{
696// Reflex properties are more or less related to ROOT attributes: the names
697// may be different (see map_property() above)
698 return fIsFundamental? TPropertyListAdapter(0) : fClass->GetAttributeMap();
699}

◆ SizeOf()

size_t TScopeAdapter::SizeOf ( ) const

Definition at line 765 of file RootType.cxx.

766{
767 if (fClass.GetClass()) {
768 return fClass.GetClass()->Size();
769 } else {
770 const TDataType* fundType = gROOT->GetType(fName.c_str());
771 if ( fundType )
772 return fundType->Size();
773 }
774 return 0;
775}

◆ TemplateArgumentAt()

TScopeAdapter TScopeAdapter::TemplateArgumentAt ( size_t nth) const

Definition at line 819 of file RootType.cxx.

820{
821// this is stupid, but highly likely never called, and if it is, only once, so
822// I don't see a reason for caching to prevent the extra loops
823 std::string name = Name( Reflex::FINAL );
824 size_t tpl_open = 0, argcount = 0;
825 std::string::size_type last = 0;
826 for ( std::string::size_type pos = 0; pos < name.size(); ++pos ) {
827 std::string::value_type c = name[pos];
828
829 // count '<' and '>' to be able to keep templated args intact
830 if ( c == '<' ) {
831 ++tpl_open;
832 if (tpl_open == 1) last = pos+1;
833 continue;
834 } else if (c == '>' && tpl_open > 0) {
835 --tpl_open;
836 }
837 if ((c == ',' && tpl_open == 1) || (c == '>' && tpl_open == 0)) {
838 if ( argcount++ == nth ) {
839 // Protect against data race inside TClassEdit.
840 // https://github.com/root-project/root/issues/10353
841 // Should be fixed in root 6.26.02.
842 R__WRITE_LOCKGUARD(ROOT::gCoreMutex);
843 std::string part =
844 TClassEdit::CleanType( name.substr(last, pos-last).c_str(), 1 );
845 return part;
846 }
847 last = pos+1; // done with part
848 }
849 }
850
851 // should never be called
852 assert( !"miscount between TemplateArgumentSize() and TemplateArgumentAt()" );
853 return TScopeAdapter();
854}

◆ TemplateArgumentSize()

size_t TScopeAdapter::TemplateArgumentSize ( ) const

Definition at line 857 of file RootType.cxx.

858{
859// this is stupid, too, see TemplateArgumentAt() above
860 std::string name = Name( Reflex::FINAL );
861 size_t tpl_open = 0, argcount = 0;
862 for ( std::string::size_type pos = 0; pos < name.size(); ++pos ) {
863 std::string::value_type c = name[pos];
864
865 // count '<' and '>' to be able to keep templated args intact
866 if ( c == '<' ) {
867 ++tpl_open;
868 continue;
869 } else if ( c == '>' && tpl_open > 0 )
870 --tpl_open;
871
872 if ((c == ',' && tpl_open == 1) || (c == '>' && tpl_open == 0))
873 ++argcount;
874 }
875 return argcount;
876}

◆ ToType()

TTypeAdapter TScopeAdapter::ToType ( ) const
inline

Definition at line 185 of file RootType.h.

185{ return *this; }

◆ TypeAt()

TScopeAdapter TScopeAdapter::TypeAt ( size_t nth)
static

Definition at line 593 of file RootType.cxx.

594{
595 R__READ_LOCKGUARD (ROOT::gCoreMutex);
596 const char *class_name = gClassTable->At( nth );
597 // prevent autoloading, as it could change gClassTable
598 return class_name? TScopeAdapter( string(class_name), false ) : TScopeAdapter();
599}

◆ TypeInfo()

const type_info & TScopeAdapter::TypeInfo ( ) const

Definition at line 684 of file RootType.cxx.

685{
686 if (fIsFundamental) { // Fundamentals have no fClass.GetClass()
687 return fundamental_type(fName);
688 }
689 return *fClass.GetClass()->GetTypeInfo();
690}
const std::type_info & fundamental_type(const std::string &name)
Definition RootType.cxx:453

◆ TypeOf()

TScopeAdapter TScopeAdapter::TypeOf ( ) const
inline

Definition at line 186 of file RootType.h.

186{ return *this; }

◆ TypeSize()

size_t TScopeAdapter::TypeSize ( )
static

Definition at line 602 of file RootType.cxx.

603{
604// return total number of types in the system (this is stupid, as the number
605// of types is dynamic ...)
606 R__READ_LOCKGUARD (ROOT::gCoreMutex);
607 TClassTable* tab ATLAS_THREAD_SAFE = gClassTable;
608 return tab ? tab->Classes() : 0;
609}
#define ATLAS_THREAD_SAFE

Member Data Documentation

◆ fClass

TClassRef TScopeAdapter::fClass
private

Definition at line 202 of file RootType.h.

◆ fIsFundamental

bool TScopeAdapter::fIsFundamental = false
private

Definition at line 203 of file RootType.h.

◆ fName

std::string TScopeAdapter::fName
private

Definition at line 201 of file RootType.h.


The documentation for this class was generated from the following files: