Something like Reflection possible in C++ ?

F

frankgerlach

I want to dynamically look up a (possibly virtual) method in c++ and
call it.
dlopen() and dlysm() provide me with addresses to the method.
Unfortunately, it seems that method pointers are NOT addresses, but
indices of a method table.
You might ask for what I need this ? The answer is that I want to build
an object request broker. Objects & methods which are exposed by this
broker are being invoked by network messages, which contain the object
ids (no problem to look them up from a table) and method names to be
called.
 
N

noel.yap

There's no C++ reflection mechanism built into the language.

In the past, I've been able to use SWIG to produce a XML representation
of the class. The XML can then be parsed to generate code, say,
CppUnit registration code in my situation.

HTH,
Noel
 
B

Branimir Maksimovic

I want to dynamically look up a (possibly virtual) method in c++ and
call it.
dlopen() and dlysm() provide me with addresses to the method.
Unfortunately, it seems that method pointers are NOT addresses, but
indices of a method table.
You might ask for what I need this ? The answer is that I want to build
an object request broker. Objects & methods which are exposed by this
broker are being invoked by network messages, which contain the object
ids (no problem to look them up from a table) and method names to be
called.
Make doMethod virtual function of base object.
class Base{
public:
virtual error_t doMethod(const string& method,
const argslist_t&, resultlist_t&)=0;
virtual ~Base(){}
};
Each derived class implements doMethod and calls what's appropitate
based on string method parameter,also implements stubs for arguments
and results.
Simple as it is. Make your argslist and resultlist to hold some type
like boost::any if needed.

Greetings, Bane.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top