1 module glued.stereotypes; 2 3 import std.meta; 4 5 public import glued.annotations; 6 import glued.utils; 7 8 struct Tracked {} 9 10 @Implies!Tracked 11 struct Stereotype {} 12 13 @Stereotype 14 @Implies!Stereotype 15 @Implies!Tracked 16 struct Component {} 17 18 @Stereotype 19 @Implies!Stereotype 20 @Implies!Tracked 21 struct Configuration {} 22 23 //import poodinis.context: PoodinisComponent = Component; 24 25 //template isStereotype(S) if (is(S == PoodinisComponent)) { 26 // enum isStereotype = true; 27 //} 28 //template isStereotype(alias S) if (is(typeof(S) == PoodinisComponent)) { 29 // enum isStereotype = true; 30 //} 31 32 /** 33 * "is S marked as an annotation indicating something being of a stereotype?" 34 * true for things like Component, Controller, etc 35 */ 36 enum isStereotype(S) = (is(S == struct) && hasAnnotation!(S, Stereotype)); 37 enum isStereotype(alias S) = (is(typeof(S) == struct) && hasAnnotation!(typeof(S), Stereotype)); 38 39 //template getAnnotations(T) if (is(T == PoodinisComponent)) { 40 // alias getAnnotations = AliasSeq!(Tracked()); 41 //} 42 //template getAnnotations(alias T) if (is(T == PoodinisComponent)){ 43 // alias getAnnotations = AliasSeq!(Tracked()); 44 //} 45 46 alias getStereotypes(alias M) = Filter!(isStereotype, getAnnotations!M); 47 48 template getStereotype(alias M, S) { 49 pragma(msg, "getStereotypes!", M, " -> ", getStereotypes!M); 50 alias found = AliasSeq!(Filter!(ofType!S, getStereotypes!M)); 51 // static assert(found.length == 1); 52 enum getStereotype = found; 53 }; 54 55 /** 56 * "is M marked as being of stereotype S?" 57 * true for example for M=UserController and S=Controller 58 */ 59 enum isMarkedAsStereotype(alias M, S) = getStereotype!(M, S).length > 0; 60 //enum isMarkedAsStereotype(alias M, S) = Filter!(ofType!S, getStereotypes!M).length > 0;