www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Derived classes? Reflection

reply "Tofu Ninja" <emmons0 purdue.edu> writes:
Currently is there a way to get all of the subclasses of a class 
at compile time?
It seems like something that should be possible using traits but 
I can't seems to see how.

Something like

class A{...}
class B:A{...}
class C:A{...}

...

foreach(auto t ; getsubclass(A))
{
    ...
}

Any help would be grateful.
Tofu
Apr 13 2013
next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 4/13/13, Tofu Ninja <emmons0 purdue.edu> wrote:
 Currently is there a way to get all of the subclasses of a class
 at compile time?
There might be things like using .moduleinfo and traversing imports to find all classes, but I think separate compilation makes this unreliable. There is however BaseClassTuple in std.traits, so you can pass a leaf class to get the class hierarchy.
Apr 13 2013
prev sibling parent reply "Namespace" <rswhite4 googlemail.com> writes:
On Saturday, 13 April 2013 at 16:16:03 UTC, Tofu Ninja wrote:
 Currently is there a way to get all of the subclasses of a 
 class at compile time?
 It seems like something that should be possible using traits 
 but I can't seems to see how.

 Something like

 class A{...}
 class B:A{...}
 class C:A{...}

 ...

 foreach(auto t ; getsubclass(A))
 {
    ...
 }

 Any help would be grateful.
 Tofu
Maybe this is helpfully: http://forum.dlang.org/thread/scgjnudclnwlbdqqdsyn forum.dlang.org
Apr 13 2013
parent reply "Tofu Ninja" <emmons0 purdue.edu> writes:
 Maybe this is helpfully:
 http://forum.dlang.org/thread/scgjnudclnwlbdqqdsyn forum.dlang.org
Oddly enough, I found that at about the same time you posted it.
Apr 13 2013
parent reply "Tofu Ninja" <emmons0 purdue.edu> writes:
On Saturday, 13 April 2013 at 17:45:12 UTC, Tofu Ninja wrote:
 Maybe this is helpfully:
 http://forum.dlang.org/thread/scgjnudclnwlbdqqdsyn forum.dlang.org
Oddly enough, I found that at about the same time you posted it.
Sadly this does not provide a compile time solution, only runtime.
Apr 13 2013
parent Benjamin Thaut <code benjamin-thaut.de> writes:
Am 13.04.2013 19:49, schrieb Tofu Ninja:
 On Saturday, 13 April 2013 at 17:45:12 UTC, Tofu Ninja wrote:
 Maybe this is helpfully:
 http://forum.dlang.org/thread/scgjnudclnwlbdqqdsyn forum.dlang.org
Oddly enough, I found that at about the same time you posted it.
Sadly this does not provide a compile time solution, only runtime.
Do you need all derived classes or or only all derived classes within one module? Because the former is most likely impossible because it would break the compilation model. Kind Regards Benjamin Thaut
Apr 14 2013