1 2 module dquery.d; 3 4 import std.traits; 5 import std.typetuple; 6 7 public import dquery.attribute; 8 public import dquery.attributes; 9 public import dquery.element; 10 public import dquery.helper; 11 public import dquery.overload; 12 public import dquery.query; 13 14 /++ 15 + Produces a query over the given type. 16 + 17 + Returns: 18 + A query over the supplied type. 19 ++/ 20 auto query(QueryType)() 21 { 22 template MapToElement(string Name) 23 { 24 // Check for inaccessible members; we can only skip them. 25 static if(!__traits(compiles, GetMember!(QueryType, Name))) 26 { 27 alias MapToElement = TypeTuple!(); 28 } 29 // Check for functions; each overload is kept as an element. 30 else static if(is(typeof(GetMember!(QueryType, Name)) == function)) 31 { 32 alias MapToOverload(alias Overload) = Alias!( 33 DQueryElement!( 34 QueryType, Name, DQueryOverload!( 35 arity!Overload, ReturnType!Overload, ParameterTypeTuple!Overload 36 )() 37 )() 38 ); 39 40 alias MapToElement = staticMap!( 41 MapToOverload, __traits(getOverloads, QueryType, Name) 42 ); 43 } 44 // Normal members. 45 else 46 { 47 alias MapToElement = Alias!(DQueryElement!(QueryType, Name)()); 48 } 49 } 50 51 enum Elements = __traits(allMembers, QueryType); 52 return DQuery!(QueryType, staticMap!(MapToElement, Elements))(); 53 } 54 55 /++ 56 + Produces a query over the type of the supplied parameter. 57 + 58 + Params: 59 + value = A parameter to type query. 60 + 61 + Returns: 62 + A query over the parameter's type. 63 ++/ 64 auto query(QueryType)(QueryType value) 65 { 66 return query!QueryType; 67 }