View mode: basic / threaded / horizontal-split · Log in · Help
August 19, 2007
Re: OffsetTypeInfo
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?)
August 20, 2007
Re: OffsetTypeInfo
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.
Top | Discussion index | About this forum | D home