digitalmars.D - OffsetTypeInfo
- Ender KaShaea (1/1) Aug 17 2007 How do you use the OffsetTypeInfo class, or the offti function of the cl...
- Chad J (30/31) Aug 18 2007 I'm assuming you've already tried, and it didn't work.
- Carlos Santander (5/9) Aug 18 2007 Maybe I'm misunderstanding you, but have you checked if .offsetof does w...
- Ender KaShae (2/13) Aug 18 2007 what is .offsetof I have not heard of it
- Carlos Santander (4/18) Aug 18 2007 Look for "Field Properties" in http://www.digitalmars.com/d/class.html
- Ender KaShae (2/7) Aug 18 2007 this bug descibes the behavior perfectly
- Ender KaShae (18/25) Aug 19 2007 this is rather depressing as it had some rather neat reflection capabili...
- Chad J (2/31) Aug 20 2007 I agree this stuff would be quite useful if it worked.
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
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
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
Carlos Santander Wrote:Ender KaShaea escribió:what is .offsetof I have not heard of itHow 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
Ender KaShae escribió:Carlos Santander Wrote:Look for "Field Properties" in http://www.digitalmars.com/d/class.html -- Carlos Santander BernalEnder KaShaea escribió:what is .offsetof I have not heard of itHow 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
ChOtherwise, if you just don't know how to use it at all, well, I'm sorrybut I don't know for sad J Wrote: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=1348this bug descibes the behavior perfectly
Aug 18 2007
Chad J Wrote:Ender KaShaea wrote:this is rather depressing as it had some rather neat reflection capabilities if it worked the way I thought it would, ex: a deep copy: Type copy(Type: Object)(Type t){ OffsetTypeInfo[] ot = t.classinfo.offTi; void* ptr = cast(void*)t; Type result = new result;// don't know how else to create instance void* v = cast(void*) result; foreach(o; ot){ if(!is(typeof(o.ti): TypeInfo_Class)){ v[o.offset] = ptr[o.offset]; break; } v[o.offset] = copy(cast(Object)ptr); } return result; } I'm not sure if that would work(especially indexing a void pointer, i'm not sure if that's allowed or how it counts) and could have added functionality (like support for structs and arrays) but it shows how useful it could be (it would be even more useful if there was a way to dynamically cast using a typeinfo (maybe by using templates and alias's?)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
Aug 19 2007
Ender KaShae wrote:Chad J Wrote:I agree this stuff would be quite useful if it worked.Ender KaShaea wrote:this is rather depressing as it had some rather neat reflection capabilities if it worked the way I thought it would, ex: a deep copy: Type copy(Type: Object)(Type t){ OffsetTypeInfo[] ot = t.classinfo.offTi; void* ptr = cast(void*)t; Type result = new result;// don't know how else to create instance void* v = cast(void*) result; foreach(o; ot){ if(!is(typeof(o.ti): TypeInfo_Class)){ v[o.offset] = ptr[o.offset]; break; } v[o.offset] = copy(cast(Object)ptr); } return result; } I'm not sure if that would work(especially indexing a void pointer, i'm not sure if that's allowed or how it counts) and could have added functionality (like support for structs and arrays) but it shows how useful it could be (it would be even more useful if there was a way to dynamically cast using a typeinfo (maybe by using templates and alias's?)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
Aug 20 2007