By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,192 Members | 858 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,192 IT Pros & Developers. It's quick & easy.

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

P: n/a
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!

Dec 14 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
|| 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..

Dec 14 '05 #2

P: n/a
<gr*********@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...

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/Produ...pFrontEnd.html.
Our front end handles ANSI, GNU, and all the Microsoft Dialects
of C++.
--
Ira D. Baxter, Ph.D., CTO 512-250-1018
Semantic Designs, Inc. www.semdesigns.com
Dec 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.