Re: Getting and using class hierarhy information in runtime

2014-02-14 Thread Uranuz
I solved it myself. I forget that I can use function as predicate import std.stdio, std.algorithm; class A: Exception { this(){ super(null); } } class B: A {} class C: B {} class D: A {} class E: A {} class F: E {} size_t countDerivations(TypeInfo_Class typeinfo) { size_t re

Re: Getting and using class hierarhy information in runtime

2014-02-14 Thread Uranuz
Also I have the following code but I get some error. I think it's because of std.algorithm.sort function that uses mixin to inject predcate. But it doesn't import symbols passed in predicate and fails. Is there some way of resolving this problem or I need to inject full code of function inside

Re: Getting and using class hierarhy information in runtime

2014-02-14 Thread Uranuz
// declare the function so we can access it (as an internal druntime // function, thee is no import to provide it, but we can call it anyway) extern(C) int _d_isbaseof(ClassInfo oc, ClassInfo c); Maybe implementing such functionality somewhere as standart function or method would be a a god

Re: Getting and using class hierarhy information in runtime

2014-02-13 Thread Adam D. Ruppe
On Friday, 14 February 2014 at 03:48:13 UTC, Uranuz wrote: { if( exc.inheritsOrIs(type) ) //Checking type of This function is basically the same as the cast function in druntime. Look for _d_isbaseof in the file dmd2/src/druntime/src/rt https://github.com/D-Programming-Language/d

Re: Getting and using class hierarhy information in runtime

2014-02-13 Thread Uranuz
Yes. I was thinking about this but I want some more "clear looking" way of attaching handlers for errors, because I could have a lot of them and using a lot of if operators is not good for me. Exception e = ...; if(auto b = cast(BaseHTTPException) e) { // use b of that type } else if(auto

Re: Getting and using class hierarhy information in runtime

2014-02-13 Thread Uranuz
I suddenly posted unfinished message. In my web application on D I want to implement some type of "event based error handling". I'm process some events of request handler with some wodified version of this: http://code.dlang.org/packages/std_event I'm trying to implement error handling in event

Re: Getting and using class hierarhy information in runtime

2014-02-13 Thread Adam D. Ruppe
The easiest way is to simply use cast: Exception e = ...; if(auto b = cast(BaseHTTPException) e) { // use b of that type } else if(auto s = cast(SpecializedHTTPException) e) { // use s, e is of this type } and so on. On Friday, 14 February 2014 at 03:37:16 UTC, Uranuz wrote: Is it possib

Getting and using class hierarhy information in runtime

2014-02-13 Thread Uranuz
In my web application on D I want to implement some type of "event based error handling". I'm process some events of request handler with some wodified version of this: http://code.dlang.org/packages/std_event I'm trying to implement error handling in event "onError". I pass Throwable object a