1 module witchcraft.mixins.base; 2 3 import std.meta; 4 5 template TypeOfMeta(T) 6 { 7 import witchcraft; 8 9 static if(is(T == class)) 10 { 11 alias TypeOfMeta = Class; 12 } 13 else static if(is(T == struct)) 14 { 15 alias TypeOfMeta = Struct; 16 } 17 else static if(is(T == interface)) 18 { 19 alias TypeOfMeta = InterfaceType; 20 } 21 else static if(!is(T)) 22 { 23 alias TypeOfMeta = Module; 24 } 25 else 26 { 27 static assert(false); //todo: proper error 28 } 29 } 30 31 template ImplTypeOfMeta(T) 32 { 33 import witchcraft; 34 35 mixin WitchcraftClass; 36 mixin WitchcraftConstructor; 37 mixin WitchcraftField; 38 mixin WitchcraftInterface; 39 mixin WitchcraftMethod; 40 mixin WitchcraftStruct; 41 42 static if(is(T == class)) 43 { 44 alias ImplTypeOfMeta = ClassMixin!(T); 45 } 46 else static if(is(T == struct)) 47 { 48 alias ImplTypeOfMeta = StructMixin!(T); 49 } 50 else static if(is(T == interface)) 51 { 52 alias ImplTypeOfMeta = InterfaceTypeMixin!(T); 53 } 54 else static if(!is(T)) 55 { 56 alias ImplTypeOfMeta = ModuleImpl!(__traits(parent, T)); 57 } 58 else 59 { 60 static assert(false); //todo: proper error 61 } 62 } 63 64 TypeOfMeta!(T) getMeta(T)() 65 { 66 return new ImplTypeOfMeta!(T); 67 } 68 69 mixin template Witchcraft() 70 { 71 import witchcraft; 72 73 private static TypeOfMeta!(typeof(this)) __typeinfoext; 74 75 @property 76 static typeof(__typeinfoext) metaof() 77 { 78 if(__typeinfoext is null) 79 { 80 __typeinfoext = getMeta!(typeof(this))(); 81 } 82 83 return __typeinfoext; 84 } 85 86 static if(__traits(compiles, typeof(super).metaof)) 87 { 88 override typeof(__typeinfoext) getMetaType() 89 { 90 return typeof(this).metaof; 91 } 92 } 93 else static if(is(typeof(this))) 94 { 95 typeof(__typeinfoext) getMetaType() 96 { 97 return typeof(this).metaof; 98 } 99 } 100 else 101 { 102 typeof(__typeinfoext) getMetaType() 103 { 104 return metaof; 105 } 106 } 107 }