Doing run-time binding/introspection/reflection in C++ non-intrusively

G

greg.corson

Hi,

I'm in the process of building a complex system using a sort of "system
services" model. I'm looking at putting together various services like
serialization, networking, 2D/3D rendering, debugger-like class
inspection and other assorted stuff, but I need a way to bind them to
other people's C++ code at runtime using external scripting.

In particular I need a way to be able to access members of a class at
runtime by name, and I need the system to work in a non-intrusive way.
The classes being accessed are pre-existing (user code, toolkit
libraries...etc) and I can't add any code to the classes being accessed
or force them to inherit from a common base. In other words, the
dictionary information and code that does the introspection needs to be
completely outboard of the classes being inspected.

I've been searching the net awhile and have found a number of systems
for doing this, but most are very intrusive or compiler-specific. Can
anyone put up some pointers to systems/approaches they think might fit
the bill?

It's ok if some manual work is needed to generate the dictionary of
class members, it doesn't have to be totally automatic.

Specifically, the sort of things I want to use this for are:

1. A service that can be given a pointer to an object, then pull member
values out of that object and display them in an auto-generated GUI.
2. A service that can be given a pointer to an object, pull specific
member values out of the object and send them over a network link to a
"mirror" version of the object on another computer.
3. A service that can be given a pointer to a class and
serialize/deserialize select members to disk/xml.
4. Allowing scripts to bind to values in running objects ie: allowing a
script to push values into a class (such as a script that puts the
appropriate color, model...etc into an instance of "Car") or a script
that creates bindings between classes (ie: something that says "every
1/60th of a second grab car1.SteeringWheelPosition, convert it into a
rotation matrix and deposit it in rendererNode1.TransformationMatrix")
5. Allowing a 2d/3d renderer to be given a pointer to an object, look
up information on its class and connect to specific members containing
details about the type of the object, position, orentation...etc so it
can be rendered.

The main goal is to allow users to write their classes independent of
any specific application framework, then use this introspection
information and scripts to sort of "wire up" the system at runtime
(connect classes to each other and to the system services).

Any help/suggestions would be appreciated!
 
M

ma740988

|| Specifically, the sort of things I want to use this for are:

Item 1, 3 and 5, intrigues me but all five of 'things' are quite
interesting to say the least.
I'm of no help but I'm curious to know what you find out.

|| Allowing scripts to bind to values in running objects ...
Very interesting..
 
I

Ira Baxter

I need a way to bind them to
other people's C++ code at runtime using external scripting.

In particular I need a way to be able to access members of a class at
runtime by name, and I need the system to work in a non-intrusive way.
The classes being accessed are pre-existing (user code, toolkit
libraries...etc) and I can't add any code to the classes being accessed
or force them to inherit from a common base. In other words, the
dictionary information and code that does the introspection needs to be
completely outboard of the classes being inspected.

I've been searching the net awhile and have found a number of systems
for doing this, but most are very intrusive or compiler-specific. Can
anyone put up some pointers to systems/approaches they think might fit
the bill?

You fundamentally can't get information at runtime about structures
and types in C++. In essence, you have to get it from the source code.
This means you need to parse the source code and extract the
name and type information, and generate setters/getters for the
fields of interest.

This information can be extracted from the GNU compilers with
considerable effort, all you have to do is hack the source
code to extract what you want :-{ And, of course,
it is GNU specific.

We offer a full C++ front end with name/type
resolution (e.g., it determines everything a compiler's symbol table
has) and APIs to allow access to the parsed C++ source tree,
and all this name/type information, so that you could generate
the information you need. See
http://www.semanticdesigns.com/Products/FrontEnds/CppFrontEnd.html.
Our front end handles ANSI, GNU, and all the Microsoft Dialects
of C++.
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top