comparison d2/qtd/Attribute.d @ 347:970332a88b72

lowered the marshall in rank
author maxter <spambox@d-coding.com>
date Sat, 15 May 2010 00:22:47 +0300
parents 2691dd58d7e1
children 29ea6511681f
comparison
equal deleted inserted replaced
346:2691dd58d7e1 347:970332a88b72
24 /** 24 /**
25 Allows multiple attributes of the same category to be associated with the symbol. 25 Allows multiple attributes of the same category to be associated with the symbol.
26 */ 26 */
27 allowMultiple = 0x0000_0001, 27 allowMultiple = 0x0000_0001,
28 28
29 /* internal */ inner = 0x0000_0002 29 /* internal */ inner = 0x0000_0002,
30
31 /**
32 Attribute data are in key-value form.
33 */
34 named = 0x0000_0004
35 }
36
37 /**
38 When mixed in an aggregate, converts a compile-time tuple to
39 members of that aggregate.
40 */
41 mixin template tupleToMembers!(string nameSpace, size_t index, A...)
42 {
43 static if (index < A.length)
44 {
45 enum indexStr = to!string(index);
46
47 static if (is(__traits(compiles, { struct { typeof(A[index]) x; } }() })))
48 mixin("typeof(A[" ~ indexStr ~ "]) " ~ nameSpace ~ ~ " = A[" ~ indexStr ~"];\n" ~ next;
49 else
50 mixin("alias A[" ~ indexStr ~ "] " ~ nameSpace ~ indexStr ~ ";\n" ~ next;
51
52 mixin tupleToFields!(nameSpace, index + 1, A);
53 }
54 }
55
56 /**
57 When mixed in an aggregate, converts a compile-time tuple of name-value pairs to
58 members of that aggregate.
59 */
60 struct NamedValueTupleToFields(A...)
61 {
62
63 }
64
65 version (QtdUnittest)
66 {
67 unittest
68 {
69 static int foo()
70 {
71 return 42;
72 }
73
74 static struct S
75 {
76 mixin TupleToFields!("field", 0,
77 int,
78 "a",
79 22,
80 foo);
81 }
82
83 static assert(is(S.field0 == int));
84 S s;
85 assert(s.field1 == "a");
86 assert(s.field2 == "22");
87 assert(S.foo() == 42);
88 }
30 } 89 }
31 90
32 private template attributeId(alias symbol, uint index = 0) 91 private template attributeId(alias symbol, uint index = 0)
33 { 92 {
34 enum attributeId = standardNamespace ~ "_attr_" ~ uniqueId!symbol ~ "_" ~ to!string(index); 93 enum attributeId = standardNamespace ~ "_attr_" ~ uniqueId!symbol ~ "_" ~ to!string(index);
155 mixin AttributeImpl!(symbol, attrClass, opts, index + 1, A); 214 mixin AttributeImpl!(symbol, attrClass, opts, index + 1, A);
156 } 215 }
157 else 216 else
158 mixin ("alias TypeTuple!(attrClass, A) " ~ attrId ~ ";"); 217 mixin ("alias TypeTuple!(attrClass, A) " ~ attrId ~ ";");
159 } 218 }
219
220 /**
221 Base class for run time attributes
222 */
223 abstract class MetaAttribute
224 {
225 }
226
227 /**
228 Default implementation of run time attributes
229 */
230 final class MetaAttributeVariant : MetaAttribute
231 {
232 private:
233 Variant[] values_;
234
235 public:
236 Variant values()
237 {
238 return values_;
239 }
240
241 static MetaAttributeVariant create(string category, AttributeOptions opts, A...)()
242 {
243 }
244 }
245
246 class MetaAttributeTypedImpl(A...)
247 {
248 }
249
250
251 abstract class MetaAtributeTyped : MetaAttribute
252 {
253 void construct(A...)()
254 {
255 }
256 }
257
258
160 259
161 private string stringOfFunction(alias symbol)() 260 private string stringOfFunction(alias symbol)()
162 { 261 {
163 auto ptrType = typeof(&symbol).stringof; 262 auto ptrType = typeof(&symbol).stringof;
164 auto paramList = ParameterTypeTuple!(symbol).stringof; 263 auto paramList = ParameterTypeTuple!(symbol).stringof;