www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - OffsetTypeInfo

reply Ender KaShaea <astrothayne gmail.com> writes:
How do you use the OffsetTypeInfo class, or the offti function of the classinfo
or typeinfo classes? I was expecting them to give the type and offfset of each
member of a class or struct, though I can't figure out how to get that
information.
Aug 17 2007
next sibling parent Chad J <gamerChad _spamIsBad_gmail.com> writes:
Ender KaShaea wrote:
 How do you use the OffsetTypeInfo class, or the offti function of the
classinfo or typeinfo classes? I was expecting them to give the type and
offfset of each member of a class or struct, though I can't figure out how to
get that information.

I'm assuming you've already tried, and it didn't work. You may want to have a look at bug 1348. http://d.puremagic.com/issues/show_bug.cgi?id=1348 Otherwise, if you just don't know how to use it at all, well, I'm sorry but I don't know for sure either. They don't work, so I have no way of testing! Anyhow, I was trying to use them to iterate through members of an arbitrary class and, based on the type of a member, do something with it. Here's some untested code: // This code is placed inside the said "arbitrary class" OffsetTypeInfo[] otis = typeid(typeof(this)).offTi; foreach( oti; otis ) { char[] typeName = oti.toString(); if ( typeName !is null ) { // Just a tricky/hackey way of turning a typeinfo into a classinfo. ClassInfo ci = ClassInfo.find( oti.toString() ); // Suppose I want to know if this member class is a direct or indirect descendant of some class type known as "Foo" // Here's how it's done. ClassInfo temp = ci; bool descendsFoo = false; while ( temp !is Object.classinfo && temp !is Foo.classinfo ) temp = temp.base; if ( temp is Foo.classinfo ) descendsFoo = true; } }
Aug 18 2007
prev sibling parent Carlos Santander <csantander619 gmail.com> writes:
Ender KaShaea escribió:
 How do you use the OffsetTypeInfo class, or the offti function of the
 classinfo or typeinfo classes? I was expecting them to give the type and
 offfset of each member of a class or struct, though I can't figure out how to
 get that information.

Maybe I'm misunderstanding you, but have you checked if .offsetof does what you want to do? -- Carlos Santander Bernal
Aug 18 2007