1 /**
2 License:
3 Boost Software License - Version 1.0 - August 17th, 2003
4 5 Permission is hereby granted, free of charge, to any person or organization
6 obtaining a copy of the software and accompanying documentation covered by
7 this license (the "Software") to use, reproduce, display, distribute,
8 execute, and transmit the Software, and to prepare derivative works of the
9 Software, and to permit third-parties to whom the Software is furnished to
10 do so, all subject to the following:
11 12 The copyright notices in the Software and this entire statement, including
13 the above license grant, this restriction and the following disclaimer,
14 must be included in all copies of the Software, in whole or in part, and
15 all derivative works of the Software, unless such copies or derivative
16 works are solely in the form of machine-executable object code generated by
17 a source language processor.
18 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26 27 Authors:
28 Alexandru Ermicioi
29 **/30 moduleaermicioi.aedi_property_reader.convertor.traits;
31 32 importstd.traits : functionAttributes, variadicFunctionStyle, Variadic, FunctionAttribute, arity;
33 34 /**
35 Tests if field is property getter.
36 **/37 templateisPropertyGetter(aliasfunc) {
38 boolisPropertyGetter() {
39 staticforeach (overload; __traits(getOverloads, func)) {
40 41 if (
42 (variadicFunctionStyle!overload == Variadic.no) &&
43 (arity!overload == 0) && (functionAttributes!overload & FunctionAttribute.property)
44 ) {
45 returntrue;
46 }
47 }
48 49 returnfalse;
50 }
51 }
52 53 /**
54 Tests if field is property setter
55 **/56 templateisPropertyPropertySetter(aliasType, stringmember) {
57 staticforeach (overload; __traits(getOverloads, Type, member)) {
58 staticif (!is(found) && isPropertyPropertySetter!overload) {
59 enumfound = true;
60 enumisPropertyPropertySetter = found;
61 }
62 }
63 64 staticif (!is(found) && isPropertyPropertySetter!overload) {
65 enumisPropertyPropertySetter = false;
66 }
67 68 }
69 70 /**
71 ditto
72 **/73 enumisPropertyPropertySetter(aliasfunc) = (variadicFunctionStyle!func == Variadic.no) &&
74 (arity!func == 1) && (functionAttributes!func & FunctionAttribute.property);
75 76 templatematch(aliaspredicate, Types...) {
77 78 staticforeach (aliasT; Types) {
79 staticif (!is(typeof(found)) && predicate!T) {
80 enumfound = true;
81 aliasmatch = T;
82 }
83 }
84 85 staticif (!is(typeof(found)) || !found) {
86 87 staticassert(false, "No match found for passed template args");
88 }
89 }
90 91 /**
92 Well, it's a nothrow wrapper usable for logger to allow logging in nothrow functions.
93 **/94 Tn(T)(lazyTvalue) nothrow {
95 try {
96 staticif (is(T == void)) {
97 98 value();
99 } else {
100 101 returnvalue();
102 }
103 } catch (Exceptione) {
104 assert(false, "An exception was thrown where it wasn't expected to.");
105 }
106 }
107 108 enumisD(T, X) = is(T : X);
109 110 interfacePureSafeNothrowToString {
111 stringtoString() @safepurenothrow;
112 }