Get the list of methods of a specific class

[Root 3.10 ]
is there a way to access the list of methods of a specific class?

I’ve tried to use ‘GetListOfMethods’ but this gives also the methods of the ancestor classes.
I’ve also tried to filter this list but I could not find any data in TMethod/TFunction that points to the class where the method is actually defined:

  • voidTCint::CreateListOfMethods(TClass *cl) set ‘TMethod::fClass’ to ‘cl’ wherever the method is implemented in the class hierarchy
    cl->fMethod->Add(new TMethod(a, cl));
  • filtering through the belonging class gives the same list of methods from the whole class hierarchy.

Any hints?

Thanks,

JM

Hi JM,
I don’t really understand what you were trying to do in the second part of your post, but this should give you an answer to your question: [quote]is there a way to access the list of methods of a specific class?[/quote]root [0] TObject::Class()->GetListOfMethods()->FindObject("GetName") (const class TObject*)0x890b0a0 root [1] TList::Class()->GetListOfMethods()->FindObject("GetName") (const class TObject*)0x0
So TClass::GetListOfMethods() does not return base classes’ methods.
Cheers, Axel.

Actually what I am trying to do is to have the list of methods of a class, not a pointer to a specific method for which I would have already the name (as it is the case in your example.)

JM

Hi JM,
TClass::GetListOfMethods() returns the TList you are looking for. I used TList::FindObject() to show that the returned list does not contain methods from the base classes: TObject has a method called “GetName”, and TList::FindObject finds it (it returns a pointer to a TMethod !=0). On the other hand, TList derives from TObject - but its list of methods does not contain a TMethod called “GetName” - TList::FindObject() returns 0.

This example prints all method names of the class TSystem (modulo pointer==0 protections):

TClass* cl=TSystem::Class(); TList* methods=cl->GetListOfMethods(); TMethod* method=0; TIter iM(methods); while ((method=iM())) std::cout << method->GetName() << std::endl;
Here is the documentation for TMethod, TClass, TList, TIter, and TSystem.
Cheers, Axel.

OK I was actually confused with the additional methods generated from ClassImp/ClassDef…
thanks.

JM