|
Boost Users : |
Subject: Re: [Boost-users] Getting metadata of class
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2009-12-12 03:25:40
On Sat, Dec 12, 2009 at 12:01 AM, Alex Vinokur
<alexvn_at_[hidden]> wrote:
>
>
> "OvermindDL1" <overminddl1_at_[hidden]> wrote in message
> news:3f49a9f40912111556w24850c47le205e9f9eb552cf5_at_mail.gmail.com...
>>
>> On Fri, Dec 11, 2009 at 10:45 AM, Alex Vinokur
>> <alexvn_at_[hidden]> 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/adapt_assoc.html
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net