digitalmars.D.learn - How to cast type from typeinfo in runtime?
- badmadevil (27/27) Feb 17 2008 Hi, i want to format complex number by Tango's Layout class.
- downs (3/3) Feb 17 2008 I'm not a Tango user, but I don't think so.
- badmadevil (2/7) Feb 19 2008 I see, thank you.
Hi, i want to format complex number by Tango's Layout class.
As a sub-problem, I need to convert Arg p to a proper typed variable u.
It can be done if convert p in _all_ 6 cases (like the ifloat case).
But can the type (of p) used in casting be directly derived from argument
_type_ (of Typeinfo)?
Thank for help.
----------
class ComplexLayout : Layout!(char) {
protected override char[] unknown (char[] output, char[] format, TypeInfo
type, Arg p) {
char[] s ;
creal u ;
// p is of type Arg, alias from void*
char tc = type.classinfo.name[9] ;
switch(tc) {
case 'q','r','c','j','p': // complex & imagery
u = cast(creal)( *cast(typeof(type.classinfo.create())*)p ) ; //
failed try
// u = cast(creal)( *cast(typeof(Object.factory(type.toString))*)p ) ; //
failed try
break ;
case 'o': // ifloat
u = cast(creal)( *cast(ifloat*)p ) ;
break ;
default:
return "{unhandled argument type: " ~ type.toString ~ '}';
}
// format u into s
return s ;
}
}
Feb 17 2008
I'm not a Tango user, but I don't think so. This is because typeinfo is a runtime value, but D types are completely compile-time only. --downs
Feb 17 2008
downs wrote:I'm not a Tango user, but I don't think so. This is because typeinfo is a runtime value, but D types are completely compile-time only. --downsI see, thank you.
Feb 19 2008








badmadevil <badmadevil gmail.com>