473,383 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Something like Reflection possible in C++ ?

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.

Dec 3 '05 #1
3 1546
Must be dlsym() !

Dec 3 '05 #2
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

Dec 3 '05 #3
fr**********@gmail.com wrote:
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.
Dec 3 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Rachel Suddeth | last post by:
I'm trying to use reflection to create an object at runtime where the type is given by a string. I thought we should be able to do that, but so far it's not working. I'm trying to work on...
9
by: Oriane | last post by:
Hi, I'm currently a method attribute which is used to check the "validity" of this method against a rule. I wrote the isValid method, to be used inside the otriginal method: For instance: //...
2
by: Jeff | last post by:
I am trying to dynamically load an assembly via reflection and then invoke a method of that assembly that will populate a custom type collection passed into the method byref. I am able to...
2
by: Ronchese | last post by:
Hi all. Is possible I coerce a value to a determined type informed by a string? See the sample: dim obj as Object obj = SomeConversionType(2, "System.Windows.Forms.DockStyle")
4
by: Mike TI | last post by:
April 22, 2006 Hi all I want to execute a command stored in a variable, eg I may store: Form1.Show() or Form2.Show()
2
by: Philip Limbeck | last post by:
Hi, I am currently stuck with a problem concerning reflection. We have to remove a Custom class attribute from an instance before giving the instance to another subsystem. Is this possible...
3
by: S. Lorétan | last post by:
Hi guys, I'm coding an application connected to a database. I have some clients that use this program with 2 or 3 computers, and I use MsSQL Express for them. But if the client needs more...
0
by: Coder Guy | last post by:
I am trying to subscribe to an event using reflection. The guarantee is that the the event delegate will be of type EventHandler or at least the e parameter inherits from EventArgs. Hard coding...
6
by: Cralis | last post by:
Hi guys, Someone once said, 'You can do that with reflection'. I can't recall what it was I was trying to do at the time, but then he said, 'Any developer knows what reflection is...'. I kept...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.