OffsetTypeInfo

Chad J gamerChad at _spamIsBad_gmail.com
Mon Aug 20 12:05:59 PDT 2007


Ender KaShae wrote:
> Chad J Wrote:
> 
>> 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
>>
> 
> 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?)

I agree this stuff would be quite useful if it worked.



More information about the Digitalmars-d mailing list