idioskopos (Greek: idio- inward, within, private; -skopos look, aim, target) is a C++ library that simplifies (hopefully) the addition of object reflection and introspection to C++ classes.
RPMS for Fedora Core 5, 6 and 7 are available for i386, x86_64 and ppc in Fedora Extras (see the downloads page for links).
The approach taken is an intrusive approach. One advantage is that special preprocessors are not necessary; either for your own code, or for those that use your code. A disadvantage of an intrusive approach is just that; it's intrusive, meaning you must explicitly state what class members are properties and instantiate them in your constructors.
There are numerous libraries that provide object introspection, but are generally part of some framework such as:
Support for object reflection and introspection are 'hot' topics in C++ and already have some groups pushing for inclusion in the next ANSI/ISO C++ standard. If you're looking for more information on the subject, this might be a good starting point.
So, why does the world need yet another library supporting reflection and introspection? It probably doesn't, but the reason I decided to create one anyway was due to the fact that I was writing an application that needed support for reflection. After scouring Freshmeat, Sourceforge, the GNU Savannah, and the nonGNU Savannah as well as googling for a solution, I felt that the current approaches suffered from one of the following issues:
The idioskopos library is based heavily on several concepts used in Gtkmm to wrap the gobject interface. However, it is a standalone library and depends only on libsigc++.
The following illustrates the code necessary to create reflective properties: a static property x
and a dynamic property y
.
class Example: public Idioskopos::Object { public: Example::Example(); Idioskopos::Property<double> x; }; Example::Example(): x(*this, "x", 2.0), { create_property<double>("y", 1.0); }
Introspection can be accomplished using the iterators provided by Idioskopos::Object:
Example ex; Idioskopos::Object::iterator i; cout << "All properties in class Example:\n"; for (i = ex.properties_begin(); i != ex.properties_end(); i++) cout << " " << i->name() << " Type: " << i->type().name() << " Value: " << i->value() << std::endl;