
Hi, Does Boost contain any features to get metadata of classes? For instance, Let Foo be some class class Foo { int m_var1; long* m_var2] char m_var3[100]; dooble m_var4; }; I would like to get the following info (as vector, file, etc) of its members: {" m_var1", "int", sizeof (m_var1), offset of (m_var1) }, {" m_var2", "long", "Pointer", sizeof (m_var2), sizeof (base-variable, i.e., long), offset of (m_var2 }, {" m_var3, "char", "array", sizeof (m_var3), sizeof (base-variable, i.e., char), offset of (m_var3 }, {" m_var4", "double", sizeof (m_var4), offset of (m_var4) }, That info I would like to get as a result of some feature (function, ...) applied to class Foo, not to each member of Foo. Alex.

On Fri, Dec 11, 2009 at 10:45 AM, Alex Vinokur
Hi,
Does Boost contain any features to get metadata of classes?
For instance,
Let Foo be some class
class Foo { int m_var1; long* m_var2] char m_var3[100]; dooble m_var4; };
I would like to get the following info (as vector, file, etc) of its members:
{" m_var1", "int", sizeof (m_var1), offset of (m_var1) }, {" m_var2", "long", "Pointer", sizeof (m_var2), sizeof (base-variable, i.e., long), offset of (m_var2 }, {" m_var3, "char", "array", sizeof (m_var3), sizeof (base-variable, i.e., char), offset of (m_var3 }, {" m_var4", "double", sizeof (m_var4), offset of (m_var4) },
That info I would like to get as a result of some feature (function, ...) applied to class Foo, not to each member of Foo.
C++ is not introspective nor reflective, hence there is no way to do that according to the language spec. However, you can use Fusion to 'convert' your stucts to a fusion map or vector (depending on if you need names or not) and work on it at compile time, and there is an introspective/reflective library in the sandbox if you do not mind adding things directly to your structs, it has more power for asking information about things instead of just operating on it like with Fusion, but you cannot operate on the things like you can with Fusion, depends on what you are needing to do... There are a few external things like gcc-xml that you can parse the info from as well. All in all, no easy way to do this. Would be nice if C++ had this ability built in (no real reason why it cannot for compile-time work), but meh...

"OvermindDL1"
On Fri, Dec 11, 2009 at 10:45 AM, Alex Vinokur
wrote: Hi,
Does Boost contain any features to get metadata of classes?
For instance,
Let Foo be some class
class Foo { int m_var1; long* m_var2] char m_var3[100]; dooble m_var4; };
I would like to get the following info (as vector, file, etc) of its members:
{" m_var1", "int", sizeof (m_var1), offset of (m_var1) }, {" m_var2", "long", "Pointer", sizeof (m_var2), sizeof (base-variable, i.e., long), offset of (m_var2 }, {" m_var3, "char", "array", sizeof (m_var3), sizeof (base-variable, i.e., char), offset of (m_var3 }, {" m_var4", "double", sizeof (m_var4), offset of (m_var4) },
That info I would like to get as a result of some feature (function, ...) applied to class Foo, not to each member of Foo.
C++ is not introspective nor reflective, hence there is no way to do that according to the language spec. However, you can use Fusion to 'convert' your stucts to a fusion map or vector (depending on if you need names or not)
Is there such a convertor (struct->map) in http://www.boost.org/doc/libs/1_41_0/libs/fusion/doc/html/index.html ? I am not familiar with boost::fusion. Thank you very much.
and work on it at compile time, and there is an introspective/reflective library in the sandbox if you do not mind adding things directly to your structs, it has more power for asking information about things instead of just operating on it like with Fusion, but you cannot operate on the things like you can with Fusion, depends on what you are needing to do... There are a few external things like gcc-xml that you can parse the info from as well.
All in all, no easy way to do this. Would be nice if C++ had this ability built in (no real reason why it cannot for compile-time work), but meh...
Thanks. Alex

On Sat, Dec 12, 2009 at 12:01 AM, Alex Vinokur
"OvermindDL1"
wrote in message news:3f49a9f40912111556w24850c47le205e9f9eb552cf5@mail.gmail.com... On Fri, Dec 11, 2009 at 10:45 AM, Alex Vinokur
wrote: Hi,
Does Boost contain any features to get metadata of classes?
For instance,
Let Foo be some class
class Foo { int m_var1; long* m_var2] char m_var3[100]; dooble m_var4; };
I would like to get the following info (as vector, file, etc) of its members:
{" m_var1", "int", sizeof (m_var1), offset of (m_var1) }, {" m_var2", "long", "Pointer", sizeof (m_var2), sizeof (base-variable, i.e., long), offset of (m_var2 }, {" m_var3, "char", "array", sizeof (m_var3), sizeof (base-variable, i.e., char), offset of (m_var3 }, {" m_var4", "double", sizeof (m_var4), offset of (m_var4) },
That info I would like to get as a result of some feature (function, ...) applied to class Foo, not to each member of Foo.
C++ is not introspective nor reflective, hence there is no way to do that according to the language spec. However, you can use Fusion to 'convert' your stucts to a fusion map or vector (depending on if you need names or not)
Is there such a convertor (struct->map) in http://www.boost.org/doc/libs/1_41_0/libs/fusion/doc/html/index.html ?
I am not familiar with boost::fusion.
Not a converter, it is an adapter, it lets you treat the struct as a fusion::map, but you still have to define it, just an easy way of defining it though, then you can use your struct as any normal fusion::map: http://www.boost.org/doc/libs/1_41_0/libs/fusion/doc/html/fusion/adapted/ada...

"OvermindDL1"
Not a converter, it is an adapter, it lets you treat the struct as a fusion::map, but you still have to define it, just an easy way of defining it though, then you can use your struct as any normal fusion::map: http://www.boost.org/doc/libs/1_41_0/libs/fusion/doc/html/fusion/adapted/ada...
Thank you. Alex

Alex Vinokur schrieb: [snip]
Does Boost contain any features to get metadata of classes?
There are some libraries under construction that might provide the features you need. You have to specify the actual introspection information yourself though. The libraries just help working with it in a convenient way. See https://svn.boost.org/trac/boost/wiki/LibrariesUnderConstruction#ReflectiveP... for more information. -Christopher
participants (3)
-
Alex Vinokur
-
Christopher Schmidt
-
OvermindDL1