00001
00002 #include "PyROOT.h"
00003 #include "Adapters.h"
00004
00005
00006 #include "TBaseClass.h"
00007 #include "TClass.h"
00008 #include "TClassEdit.h"
00009 #include "TDataType.h"
00010 #include "TDataMember.h"
00011 #include "TMethod.h"
00012 #include "TFunction.h"
00013 #include "TMethodArg.h"
00014 #include "TList.h"
00015 #include "TError.h"
00016
00017
00018 #include "Api.h"
00019
00020
00021
00022 std::string PyROOT::TReturnTypeAdapter::Name( unsigned int mod ) const
00023 {
00024
00025 std::string name = fName;
00026
00027 if ( ! ( mod & ( ROOT::Reflex::QUALIFIED | ROOT::Reflex::Q ) ) )
00028 name = TClassEdit::CleanType( fName.c_str(), 1 );
00029
00030 if ( mod & ( ROOT::Reflex::FINAL | ROOT::Reflex::F ) )
00031 return TClassEdit::ResolveTypedef( name.c_str(), true );
00032
00033 return name;
00034 }
00035
00036
00037
00038 PyROOT::TMemberAdapter::TMemberAdapter( TMethod* meth ) : fMember( meth )
00039 {
00040
00041 }
00042
00043
00044 PyROOT::TMemberAdapter::operator TMethod*() const
00045 {
00046
00047 return dynamic_cast< TMethod* >( const_cast< TDictionary* >( fMember ) );
00048 }
00049
00050
00051 PyROOT::TMemberAdapter::TMemberAdapter( TFunction* func ) : fMember( func )
00052 {
00053
00054 }
00055
00056
00057 PyROOT::TMemberAdapter::operator TFunction*() const
00058 {
00059
00060 return dynamic_cast< TFunction* >( const_cast< TDictionary* >( fMember ) );
00061 }
00062
00063
00064 PyROOT::TMemberAdapter::TMemberAdapter( TDataMember* mb ) : fMember( mb )
00065 {
00066
00067 }
00068
00069
00070 PyROOT::TMemberAdapter::operator TDataMember*() const
00071 {
00072
00073 return dynamic_cast< TDataMember* >( const_cast< TDictionary* >( fMember ) );
00074 }
00075
00076
00077 PyROOT::TMemberAdapter::TMemberAdapter( TMethodArg* ma ) : fMember( ma )
00078 {
00079
00080 }
00081
00082
00083 PyROOT::TMemberAdapter::operator TMethodArg*() const
00084 {
00085
00086 return dynamic_cast< TMethodArg* >( const_cast< TDictionary* >( fMember ) );
00087 }
00088
00089
00090 std::string PyROOT::TMemberAdapter::Name( unsigned int mod ) const
00091 {
00092
00093 TMethodArg* arg = (TMethodArg*)*this;
00094
00095 if ( arg ) {
00096
00097 std::string name = arg->GetTypeName();
00098 if ( mod & ( ROOT::Reflex::QUALIFIED | ROOT::Reflex::Q ) )
00099 name = arg->GetFullTypeName();
00100
00101 if ( mod & ( ROOT::Reflex::FINAL | ROOT::Reflex::F ) )
00102 return TClassEdit::ResolveTypedef( name.c_str(), true );
00103
00104 return name;
00105
00106 } else if ( mod & ( ROOT::Reflex::FINAL | ROOT::Reflex::F ) )
00107 return TClassEdit::ResolveTypedef( fMember->GetName(), true );
00108
00109 return fMember->GetName();
00110 }
00111
00112
00113 Bool_t PyROOT::TMemberAdapter::IsEnum() const
00114 {
00115
00116 return fMember->Property() & kIsEnum;
00117 }
00118
00119
00120 Bool_t PyROOT::TMemberAdapter::IsPublic() const
00121 {
00122
00123 return fMember->Property() & kIsPublic;
00124 }
00125
00126
00127 Bool_t PyROOT::TMemberAdapter::IsStatic() const
00128 {
00129
00130 return fMember->Property() & G__BIT_ISSTATIC;
00131 }
00132
00133
00134 size_t PyROOT::TMemberAdapter::FunctionParameterSize( bool required ) const
00135 {
00136
00137 TFunction* func = (TFunction*)fMember;
00138 if ( ! func )
00139 return 0;
00140
00141 if ( required == true )
00142 return func->GetNargs() - func->GetNargsOpt();
00143
00144 return func->GetNargs();
00145 }
00146
00147
00148 PyROOT::TMemberAdapter PyROOT::TMemberAdapter::FunctionParameterAt( size_t nth ) const
00149 {
00150
00151 return (TMethodArg*)((TFunction*)fMember)->GetListOfMethodArgs()->At( nth );
00152 }
00153
00154
00155 std::string PyROOT::TMemberAdapter::FunctionParameterNameAt( size_t nth ) const
00156 {
00157
00158 const char* name =
00159 ((TMethodArg*)((TFunction*)fMember)->GetListOfMethodArgs()->At( nth ))->GetName();
00160
00161 if ( name )
00162 return name;
00163 return "";
00164 }
00165
00166
00167 std::string PyROOT::TMemberAdapter::FunctionParameterDefaultAt( size_t nth ) const
00168 {
00169
00170 TMethodArg* arg = (TMethodArg*)((TFunction*)fMember)->GetListOfMethodArgs()->At( nth );
00171 const char* def = arg->GetDefault();
00172
00173 if ( ! def )
00174 return "";
00175
00176
00177 if ( strstr( TClassEdit::ResolveTypedef( arg->GetTypeName(), true ).c_str(), "char*" ) ) {
00178 std::string sdef = "\"";
00179 sdef += def;
00180 sdef += "\"";
00181 return sdef;
00182 }
00183
00184 return def;
00185 }
00186
00187
00188 PyROOT::TReturnTypeAdapter PyROOT::TMemberAdapter::ReturnType() const
00189 {
00190
00191 return TReturnTypeAdapter( ((TFunction*)fMember)->GetReturnTypeName() );
00192 }
00193
00194
00195 PyROOT::TScopeAdapter PyROOT::TMemberAdapter::DeclaringScope() const
00196 {
00197
00198 TMethod* method = (TMethod*)*this;
00199 if ( method )
00200 return method->GetClass();
00201
00202
00203 return std::string( "" );
00204 }
00205
00206
00207
00208 std::string PyROOT::TBaseAdapter::Name() const
00209 {
00210
00211 return fBase->GetName();
00212 }
00213
00214
00215
00216 PyROOT::TScopeAdapter::TScopeAdapter( TClass* klass ) : fClass( klass )
00217 {
00218
00219 if ( fClass.GetClass() != 0 )
00220 fName = fClass->GetName();
00221 }
00222
00223
00224 PyROOT::TScopeAdapter::TScopeAdapter( const std::string& name ) :
00225 fClass( name.c_str() ), fName( name )
00226 {
00227
00228 }
00229
00230 PyROOT::TScopeAdapter::TScopeAdapter( const TMemberAdapter& mb ) :
00231 fClass( mb.Name( ROOT::Reflex::SCOPED ).c_str() ),
00232 fName( mb.Name( ROOT::Reflex::Q | ROOT::Reflex::S ) )
00233 {
00234
00235 }
00236
00237
00238 PyROOT::TScopeAdapter PyROOT::TScopeAdapter::ByName( const std::string & name )
00239 {
00240
00241 return TClass::GetClass( name.c_str() );
00242 }
00243
00244
00245 std::string PyROOT::TScopeAdapter::Name( unsigned int mod ) const
00246 {
00247
00248 if ( ! fClass.GetClass() || ! fClass->Property() ) {
00249
00250 std::string name = fName;
00251
00252 if ( ! ( mod & ( ROOT::Reflex::QUALIFIED | ROOT::Reflex::Q ) ) )
00253 name = TClassEdit::CleanType( fName.c_str(), 1 );
00254
00255 if ( mod & ( ROOT::Reflex::FINAL | ROOT::Reflex::F ) )
00256 return TClassEdit::ResolveTypedef( name.c_str(), true );
00257
00258 return name;
00259 }
00260
00261 if ( mod & ( ROOT::Reflex::FINAL | ROOT::Reflex::F ) ) {
00262 G__ClassInfo* clInfo = (G__ClassInfo*)fClass->GetClassInfo();
00263 if ( mod & ( ROOT::Reflex::SCOPED | ROOT::Reflex::S ) )
00264 return clInfo ? clInfo->Fullname() : fClass->GetName();
00265
00266
00267 std::string actual = clInfo ? clInfo->Name() : fClass->GetName();
00268
00269
00270 if ( ! ( clInfo && clInfo->IsValid() ) ) {
00271 std::string::size_type pos = actual.substr( 0, actual.find( '<' ) ).rfind( "::" );
00272 if ( pos != std::string::npos ) {
00273
00274 actual = actual.substr( pos + 2, std::string::npos );
00275 }
00276 }
00277
00278 return actual;
00279
00280 } else if ( ! ( mod & ( ROOT::Reflex::SCOPED | ROOT::Reflex::S ) ) ) {
00281 G__ClassInfo* clInfo = (G__ClassInfo*)fClass->GetClassInfo();
00282 return clInfo ? clInfo->Name() : fClass->GetName();
00283 }
00284
00285 return fClass->GetName();
00286 }
00287
00288
00289 size_t PyROOT::TScopeAdapter::BaseSize() const
00290 {
00291
00292 if ( fClass.GetClass() && fClass->GetListOfBases() != 0 )
00293 return fClass->GetListOfBases()->GetSize();
00294
00295 return 0;
00296 }
00297
00298
00299 PyROOT::TBaseAdapter PyROOT::TScopeAdapter::BaseAt( size_t nth ) const
00300 {
00301
00302 return (TBaseClass*)fClass->GetListOfBases()->At( nth );
00303 }
00304
00305
00306 size_t PyROOT::TScopeAdapter::FunctionMemberSize() const
00307 {
00308
00309 if ( fClass.GetClass() )
00310 return fClass->GetListOfMethods()->GetSize();
00311
00312 return 0;
00313 }
00314
00315
00316 PyROOT::TMemberAdapter PyROOT::TScopeAdapter::FunctionMemberAt( size_t nth ) const
00317 {
00318
00319 return (TMethod*)fClass->GetListOfMethods()->At( nth );
00320 }
00321
00322
00323 size_t PyROOT::TScopeAdapter::DataMemberSize() const
00324 {
00325
00326 if ( fClass.GetClass() )
00327 return fClass->GetListOfDataMembers()->GetSize();
00328
00329 return 0;
00330 }
00331
00332
00333 PyROOT::TMemberAdapter PyROOT::TScopeAdapter::DataMemberAt( size_t nth ) const
00334 {
00335
00336 return (TDataMember*)fClass->GetListOfDataMembers()->At( nth );
00337 }
00338
00339
00340 PyROOT::TScopeAdapter::operator bool() const
00341 {
00342
00343 if ( fName.empty() )
00344 return false;
00345
00346 Int_t oldEIL = gErrorIgnoreLevel;
00347 gErrorIgnoreLevel = 3000;
00348 bool b = G__TypeInfo( Name( ROOT::Reflex::Q | ROOT::Reflex::S ).c_str() ).IsValid();
00349 gErrorIgnoreLevel = oldEIL;
00350 return b;
00351 }
00352
00353
00354 Bool_t PyROOT::TScopeAdapter::IsComplete() const
00355 {
00356
00357 return G__TypeInfo( Name( ROOT::Reflex::SCOPED ).c_str() ).IsLoaded();
00358 }
00359
00360
00361 Bool_t PyROOT::TScopeAdapter::IsClass() const
00362 {
00363
00364 if ( fClass.GetClass() ) {
00365
00366
00367 return (fClass->Property() & kIsClass) || ! (fClass->Property() & kIsFundamental);
00368 }
00369
00370
00371
00372
00373 return TDataType( Name( ROOT::Reflex::F | ROOT::Reflex::S ).c_str() ).GetType() == kOther_t;
00374 }
00375
00376
00377 Bool_t PyROOT::TScopeAdapter::IsStruct() const
00378 {
00379
00380 if ( fClass.GetClass() ) {
00381
00382 return (fClass->Property() & kIsStruct) || ! (fClass->Property() & kIsFundamental);
00383 }
00384
00385
00386 return TDataType( Name( ROOT::Reflex::F | ROOT::Reflex::S ).c_str() ).GetType() == kOther_t;
00387 }
00388
00389
00390 Bool_t PyROOT::TScopeAdapter::IsNamespace() const
00391 {
00392
00393 if ( fClass.GetClass() )
00394 return fClass->Property() & G__BIT_ISNAMESPACE;
00395
00396 return kFALSE;
00397 }
00398
00399
00400 Bool_t PyROOT::TScopeAdapter::IsAbstract() const
00401 {
00402
00403 if ( fClass.GetClass() )
00404 return fClass->Property() & kIsAbstract;
00405
00406 return kFALSE;
00407 }