Mercurial > projects > qtd
comparison qt/d2/qt/Signal.d @ 319:894d40eb89b6 signals
new signals and slots syntax. have to use prefixes now: signal_fooed and slot_onFooed
author | eldar_ins@eldar-laptop |
---|---|
date | Fri, 25 Dec 2009 21:48:32 +0500 |
parents | ce07227f00c1 |
children | 5c6455c4889b |
comparison
equal
deleted
inserted
replaced
318:ce07227f00c1 | 319:894d40eb89b6 |
---|---|
11 */ | 11 */ |
12 module qt.Signal; | 12 module qt.Signal; |
13 | 13 |
14 public import qt.QGlobal; | 14 public import qt.QGlobal; |
15 import qt.qtd.MetaMarshall; | 15 import qt.qtd.MetaMarshall; |
16 import qt.qtd.Meta; | |
16 | 17 |
17 import core.stdc.stdlib : crealloc = realloc, cfree = free; | 18 import core.stdc.stdlib : crealloc = realloc, cfree = free; |
18 import core.stdc.string : memmove; | 19 import core.stdc.string : memmove; |
19 import | 20 import |
20 core.thread, | 21 core.thread, |
27 std.conv, | 28 std.conv, |
28 std.string, | 29 std.string, |
29 std.metastrings; | 30 std.metastrings; |
30 | 31 |
31 | 32 |
32 // returns name, arguments or tuple of the function depending on type parameter | 33 /* returns name, arguments or tuple of the function depending on type parameter |
34 foo(int, float) | |
35 _Name: "foo" | |
36 _Tuple: "(int, float)" | |
37 _Args: "int, float" | |
38 */ | |
33 enum {_Name, _Tuple, _Args} | 39 enum {_Name, _Tuple, _Args} |
34 string getFunc(int type)(string fullName) | 40 string getFunc(int type)(string fullName) |
35 { | 41 { |
36 int pos = 0; | 42 int pos = 0; |
37 foreach(i, c; fullName) | 43 foreach(i, c; fullName) |
38 if (c == '(') | 44 if (c == '(') |
39 static if (type == _Tuple) | 45 static if (type == _Tuple) |
40 return fullName[i..$]; | 46 return fullName[i..$]; |
41 else if (type == _Name) | 47 else static if (type == _Name) |
42 return fullName[0..i]; | 48 return fullName[0..i]; |
43 else if (type == _Args) | 49 else static if (type == _Args) |
44 for(int j = fullName.length-1;; j--) | 50 for(int j = fullName.length-1; ; j--) |
45 if(fullName[j] == ')') | 51 if(fullName[j] == ')') |
46 return fullName[i+1 .. j]; | 52 return fullName[i+1 .. j]; |
47 return null; | 53 return null; |
48 } | 54 } |
49 | 55 |
134 // Compiler #BUG 3092 - evaluates MetaEntryOwner as a Tuple with one element | 140 // Compiler #BUG 3092 - evaluates MetaEntryOwner as a Tuple with one element |
135 } | 141 } |
136 | 142 |
137 template MetaEntryArgs(source...) | 143 template MetaEntryArgs(source...) |
138 { | 144 { |
139 alias source[3 .. $] MetaEntryArgs; // arguments-tuple starts from the fourth position | 145 alias ParameterTypeTuple!(source[1]) MetaEntryArgs; // arguments-tuple starts from the fourth position |
140 } | 146 } |
141 | 147 |
142 template TupleWrapper(A...) { alias A at; } | 148 template TupleWrapper(A...) { alias A at; } |
143 | 149 |
144 template isDg(Dg) | 150 template isDg(Dg) |
490 static if (is(typeof(mixin("T." ~ signalPrefix ~ toStringNow!(index))))) | 496 static if (is(typeof(mixin("T." ~ signalPrefix ~ toStringNow!(index))))) |
491 enum lastSignalIndexImpl = lastSignalIndexImpl!(T, index + 1); | 497 enum lastSignalIndexImpl = lastSignalIndexImpl!(T, index + 1); |
492 else | 498 else |
493 enum lastSignalIndexImpl = index - 1; | 499 enum lastSignalIndexImpl = index - 1; |
494 } | 500 } |
501 | |
502 // ------------------------------------------------------------------ | |
503 | |
504 string[] getSymbols(C)(string prefix) | |
505 { | |
506 string[] result; | |
507 auto allSymbols = __traits(derivedMembers, C); | |
508 foreach(s; allSymbols) | |
509 if(ctfeStartsWith(s, prefix)) | |
510 result ~= s; | |
511 return result; | |
512 } | |
513 | |
514 string removePrefix(string source) | |
515 { | |
516 foreach (i, c; source) | |
517 if (c == '_') | |
518 return source[i+1..$]; | |
519 return source; | |
520 } | |
521 | |
522 template Alias(T...) | |
523 { | |
524 alias T Alias; | |
525 } | |
526 | |
527 // recursive search in the static meta-information | |
528 template findSymbolsImpl2(C, alias signals, int id) | |
529 { | |
530 alias Alias!(__traits(getOverloads, C, signals[id])) current; | |
531 static if (signals.length - id - 1 > 0) | |
532 alias TypeTuple!(current, findSymbolsImpl2!(C, signals, id + 1).result) result; | |
533 else | |
534 alias current result; | |
535 } | |
536 | |
537 template findSymbols2(C, string prefix) | |
538 { | |
539 enum signals = getSymbols!(C)(prefix); | |
540 static if (signals) | |
541 alias findSymbolsImpl2!(C, signals, 0).result result; | |
542 else | |
543 alias TypeTuple!() result; | |
544 } | |
545 | |
546 template findSignals(C) | |
547 { | |
548 alias findSymbols2!(C, "signal_").result findSignals; | |
549 } | |
550 | |
551 template findSlots(C) | |
552 { | |
553 alias findSymbols2!(C, "slot_").result findSlots; | |
554 } | |
555 | |
556 | |
557 template metaMethods(alias func, int index, int defValsCount) | |
558 { | |
559 static if(defValsCount >= 0) { | |
560 alias TupleWrapper!(func, index) current; | |
561 // pragma(msg, __traits(identifier, (current.at)[0]) ~ " " ~ typeof(&(current.at)[0]).stringof); | |
562 alias metaMethods!(func, index+1, defValsCount-1).result next; | |
563 alias TypeTuple!(current, next) result; | |
564 } | |
565 else | |
566 { | |
567 alias TypeTuple!() result; | |
568 } | |
569 } | |
570 | |
571 template toMetaEntriesImpl(int id, Methods...) | |
572 { | |
573 static if (Methods.length > id) | |
574 { | |
575 alias typeof(&Methods[id]) Fn; | |
576 // enum defValsLength = 0; //ParameterTypeTuple!(Fn).length - requiredArgCount!(Methods[id])(); | |
577 // pragma(msg, __traits(identifier, Methods[id]) ~ " " ~ typeof(&Methods[id]).stringof); | |
578 // alias metaMethods!(Methods[id], 0, defValsLength).result subres; | |
579 alias TupleWrapper!(removePrefix(__traits(identifier, Methods[id])), typeof(&Methods[id])) subres; | |
580 alias TypeTuple!(subres, toMetaEntriesImpl!(id+1, Methods).result) result; | |
581 } | |
582 else | |
583 { | |
584 alias TypeTuple!() result; | |
585 } | |
586 } | |
587 | |
588 template toMetaEntries(Methods...) | |
589 { | |
590 alias TupleWrapper!(toMetaEntriesImpl!(0, Methods).result) toMetaEntries; | |
591 } | |
592 | |
593 | |
594 bool printRawFuncs(T...)() | |
595 { | |
596 pragma(msg, "---Raw---"); | |
597 foreach(i, _; T) | |
598 pragma(msg, __traits(identifier, T[i]) ~ " " ~ typeof(&T[i]).stringof); | |
599 return true; | |
600 } | |
601 | |
602 | |
603 bool printFuncs(alias T)() | |
604 { | |
605 pragma(msg, "---MetaEntries---"); | |
606 alias T.at tuple; | |
607 enum num = tuple.length; | |
608 foreach(i, _; Repeat!(void, num)) | |
609 pragma(msg, tuple[i].at[0] ~ " " ~ tuple[i].at[1].stringof); | |
610 // pragma(msg, typeof(&tuple[i].at[0]).stringof ~ " " ~ __toString(tuple[i].at[1])); | |
611 return true; | |
612 } |