[C++-sig] Using Boost Pyhton as a C++ Reflection Library
David Abrahams
dave at boost-consulting.com
Fri May 9 18:23:55 CEST 2003
"Arora, Vivek" <varora at bofasecurities.com> writes:
> In addition to exposing C++ classes to Python is Boost a good option
> for use as a reflection library? i.e. is it possible to enumerate and
> invoke methods and access fields reflected by the Boost Macros(or Pyste)
> directly within C++. Offcourse one obvious way is to invoke methods
> indirectly via the Python interpreter but this will be quite inefficient.
I don't think Boost.Python is a particularly good tool for that unless
you need Python bindings anyway... and even then, some information
about argument lists, overloads, etc., would be lost. I *have* been
thinking for some time that a Pyste-like system could be used to
generate MPL-compatible class descriptions that could be explored at
compile-time or at runtime.
For example, given:
class X
{
int f(double);
char* x;
static int y;
};
You might generate, as a starting point:
template <class T, T v, char const*> struct member {};
template <class T> struct members;
template <>
struct members<X>
: mpl::vector<
member<int(X::*)(double), &X::f, "f">
, member<char*(X::*), &X::x, "x">
, member<int&, X::y, "y">
>
{
};
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list