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 375 of file RootType.cxx.

376{
377 /* empty */
378}

◆ TScopeAdapter() [2/6]

TScopeAdapter::TScopeAdapter ( TClass * klass)

Definition at line 380 of file RootType.cxx.

380 : fClass( klass )
381{
382// wrap a class (scope)
383 if ( fClass.GetClass() != 0 )
384 fName = fClass->GetName();
385}
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 498 of file RootType.cxx.

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

◆ TScopeAdapter() [4/6]

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

Definition at line 506 of file RootType.cxx.

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

◆ TScopeAdapter() [5/6]

TScopeAdapter::TScopeAdapter ( const TMemberAdapter & mb)

Definition at line 569 of file RootType.cxx.

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

◆ TScopeAdapter() [6/6]

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

Definition at line 548 of file RootType.cxx.

549 : fClass (TClassRef( TClass::GetClass(typeinfo) ) ) // MN: is that right?
550{
551 if( fClass.GetClass() ) {
552 // We apparently see this sometimes due to races in TClass.
553 // In that case, try retrieving it again.
554 // (See ATEAM-697.)
555 if (!fClass.GetClass()->HasDictionary()) {
556 fClass = TClassRef( TClass::GetClass(typeinfo) );
557 }
558 fName = fClass->GetName();
559 } else {
560 char buff[1024];
561 size_t len = sizeof(buff);
562 int status = 0;
563 fName = __cxxabiv1::__cxa_demangle(typeinfo.name(), buff, &len, &status);
564 fIsFundamental = true;
565 }
566}
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 776 of file RootType.cxx.

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

◆ BaseSize()

size_t TScopeAdapter::BaseSize ( ) const

Definition at line 752 of file RootType.cxx.

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

◆ ByNameNoQuiet()

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

Definition at line 584 of file RootType.cxx.

586{
587 return TScopeAdapter (name, load);
588}

◆ 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 664 of file RootType.cxx.

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

◆ Construct() [2/2]

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

Definition at line 670 of file RootType.cxx.

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

◆ DataMemberAt()

TMemberAdapter TScopeAdapter::DataMemberAt ( size_t nth) const

Definition at line 810 of file RootType.cxx.

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

◆ DataMemberSize()

size_t TScopeAdapter::DataMemberSize ( ) const

Definition at line 800 of file RootType.cxx.

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

◆ DeclaringScope()

TScopeAdapter TScopeAdapter::DeclaringScope ( ) const

Definition at line 653 of file RootType.cxx.

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

◆ Destruct()

void TScopeAdapter::Destruct ( void * place) const

Definition at line 675 of file RootType.cxx.

676{
677 if (place && fClass.GetClass()) fClass.GetClass()->Destructor(place);
678}

◆ 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 793 of file RootType.cxx.

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

◆ FunctionMemberSize()

size_t TScopeAdapter::FunctionMemberSize ( ) const

Definition at line 783 of file RootType.cxx.

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

◆ 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 517 of file RootType.cxx.

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

◆ IsAbstract()

Bool_t TScopeAdapter::IsAbstract ( ) const

Definition at line 951 of file RootType.cxx.

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

◆ IsArray()

Bool_t TScopeAdapter::IsArray ( ) const

Definition at line 746 of file RootType.cxx.

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

◆ IsClass()

Bool_t TScopeAdapter::IsClass ( ) const

Definition at line 913 of file RootType.cxx.

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

◆ IsComplete()

Bool_t TScopeAdapter::IsComplete ( ) const

Definition at line 892 of file RootType.cxx.

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

◆ IsEnum()

Bool_t TScopeAdapter::IsEnum ( ) const

Definition at line 736 of file RootType.cxx.

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

◆ IsFundamental()

Bool_t TScopeAdapter::IsFundamental ( ) const

Definition at line 729 of file RootType.cxx.

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

◆ IsNamespace()

Bool_t TScopeAdapter::IsNamespace ( ) const

Definition at line 941 of file RootType.cxx.

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

◆ IsPointer()

Bool_t TScopeAdapter::IsPointer ( ) const

Definition at line 700 of file RootType.cxx.

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

◆ IsStruct()

Bool_t TScopeAdapter::IsStruct ( ) const

Definition at line 928 of file RootType.cxx.

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

◆ IsTemplateInstance()

Bool_t TScopeAdapter::IsTemplateInstance ( ) const

Definition at line 708 of file RootType.cxx.

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

◆ IsTopScope()

Bool_t TScopeAdapter::IsTopScope ( ) const

Definition at line 723 of file RootType.cxx.

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

◆ IsTypedef()

Bool_t TScopeAdapter::IsTypedef ( ) const

Definition at line 741 of file RootType.cxx.

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

◆ Name()

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

Definition at line 610 of file RootType.cxx.

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

◆ operator Bool_t()

TScopeAdapter::operator Bool_t ( ) const

Definition at line 877 of file RootType.cxx.

878{
879 // check the validity of this scope (class)
880 if( fName.empty() ) return false;
881 if( fIsFundamental ) return true;
882
883 // MN: rewriting this method to avoid premature header parsing
884 TClass* klass = fClass.GetClass();
885 if( !klass ) return false;
886 if( klass->HasDictionary() ) return true;
887
888 return false;
889}

◆ 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 968 of file RootType.cxx.

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

◆ operator==()

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

Definition at line 961 of file RootType.cxx.

962{
963// comparison operator, used for STL containers (implementation debatable)
964 return fClass.GetClass() == rh.fClass.GetClass();
965}

◆ Properties()

TPropertyListAdapter TScopeAdapter::Properties ( ) const

Definition at line 692 of file RootType.cxx.

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

◆ SizeOf()

size_t TScopeAdapter::SizeOf ( ) const

Definition at line 763 of file RootType.cxx.

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

◆ TemplateArgumentAt()

TScopeAdapter TScopeAdapter::TemplateArgumentAt ( size_t nth) const

Definition at line 817 of file RootType.cxx.

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

◆ TemplateArgumentSize()

size_t TScopeAdapter::TemplateArgumentSize ( ) const

Definition at line 855 of file RootType.cxx.

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

◆ 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 591 of file RootType.cxx.

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

◆ TypeInfo()

const type_info & TScopeAdapter::TypeInfo ( ) const

Definition at line 682 of file RootType.cxx.

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

◆ 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 600 of file RootType.cxx.

601{
602// return total number of types in the system (this is stupid, as the number
603// of types is dynamic ...)
604 R__READ_LOCKGUARD (ROOT::gCoreMutex);
605 TClassTable* tab ATLAS_THREAD_SAFE = gClassTable;
606 return tab ? tab->Classes() : 0;
607}
#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: