1 static class Sigsig : DesObject 2 { 3 mixin DES; 4 Signal!string message; 5 Signal!float number; 6 7 Signal!(string,int) comp; 8 } 9 10 static class C1 : DesObject 11 { 12 mixin DES; 13 string[] messages; 14 void notSlot( float x ) { } 15 void listen( string msg ) { messages ~= msg; } 16 } 17 18 class C2 : C1 19 { 20 mixin DES; 21 float a; 22 void abcFunc12( float x ) { a = x + 3.15; } 23 } 24 25 class C3 : DesObject 26 { 27 mixin DES; 28 29 string str; 30 int num; 31 32 void cfunc( string s, int i ) 33 { 34 str = s; 35 num = i; 36 } 37 } 38 39 auto sigsig = new Sigsig; 40 auto client = new C2; 41 auto c3 = new C3; 42 43 sigsig.message.connect( client.newSlot( &(client.listen) ) ); 44 auto client_abcFunc12_slot = sigsig.number.connect( client.newSlot( &(client.abcFunc12) ) ); 45 46 sigsig.message( "hello" ); 47 48 assert( client.messages.length == 1 ); 49 assert( client.messages[0] == "hello" ); 50 51 sigsig.number( 0 ); 52 53 import std.math; 54 assert( abs(client.a - 3.15) < float.epsilon ); 55 56 sigsig.number.disconnect( client_abcFunc12_slot ); 57 58 sigsig.number( 2 ); 59 assert( abs(client.a - 3.15) < float.epsilon ); 60 sigsig.number.connect( client_abcFunc12_slot ); 61 sigsig.number( 2 ); 62 assert( abs(client.a - 5.15) < float.epsilon ); 63 64 sigsig.comp.connect( c3.newSlot( &c3.cfunc ) ); 65 sigsig.comp( "okda", 13 ); 66 assert( c3.str == "okda" ); 67 assert( c3.num == 13 );