Mercurial > projects > qtd
comparison qt/d1/qt/Signal.d @ 253:073b9153ed8a
Rev. 264 done right.
Problems:
- classwizard segfaults on exit due to a bug in signals/slots or runtime.
- hellogl doesn't compile with dmd2 due to a bug in the compiler backend
author | maxter |
---|---|
date | Sun, 30 Aug 2009 09:59:12 +0000 |
parents | 7e589f525254 |
children | 501128ac7a2c |
comparison
equal
deleted
inserted
replaced
252:37eed70de029 | 253:073b9153ed8a |
---|---|
98 { | 98 { |
99 if (a.length > 1) | 99 if (a.length > 1) |
100 memmove(a.ptr + dest, a.ptr + src, length * T.sizeof); | 100 memmove(a.ptr + dest, a.ptr + src, length * T.sizeof); |
101 } | 101 } |
102 | 102 |
103 enum SignalEventId | |
104 { | |
105 firstSlotConnected, | |
106 lastSlotDisconnected | |
107 } | |
103 | 108 |
104 public class SignalException : Exception | 109 public class SignalException : Exception |
105 { | 110 { |
106 this(char[] msg) | 111 this(char[] msg) |
107 { | 112 { |
366 static if (!strong) | 371 static if (!strong) |
367 cfree(data.ptr); | 372 cfree(data.ptr); |
368 } | 373 } |
369 } | 374 } |
370 | 375 |
371 public alias void delegate(int signalId) SignalEvent; | 376 public alias void delegate(int signalId, SignalEventId event) SignalEvent; |
372 | 377 |
373 struct SignalConnections | 378 struct SignalConnections |
374 { | 379 { |
375 bool isInUse; | 380 bool isInUse; |
376 | 381 |
479 public class SignalHandler | 484 public class SignalHandler |
480 { | 485 { |
481 SignalConnections[] connections; | 486 SignalConnections[] connections; |
482 Object owner; | 487 Object owner; |
483 int blocked; | 488 int blocked; |
484 | 489 |
485 // Called after a slot has been connected to an empty signal | 490 SignalEvent signalEvent; |
486 SignalEvent firstSlotConnected; | 491 |
487 // Called after the last slot has been disconnected from a signal | |
488 SignalEvent lastSlotDisconnected; | |
489 | |
490 alias SignalConnections.SlotType SlotType; | 492 alias SignalConnections.SlotType SlotType; |
491 alias SignalConnections.ReceiverType ReceiverType; | 493 alias SignalConnections.ReceiverType ReceiverType; |
492 | 494 |
493 public this(Object owner_) { | 495 public this(Object owner_) { |
494 owner = owner_; | 496 owner = owner_; |
506 { | 508 { |
507 if (signalId >= connections.length) | 509 if (signalId >= connections.length) |
508 connections.length = signalId + 1; | 510 connections.length = signalId + 1; |
509 auto slot = connections[signalId].addSlot!(slotListId)(SlotType!(slotListId)(receiver, invoker)); | 511 auto slot = connections[signalId].addSlot!(slotListId)(SlotType!(slotListId)(receiver, invoker)); |
510 | 512 |
511 if (firstSlotConnected && connections[signalId].slotCount == 1) | 513 if (signalEvent && connections[signalId].slotCount == 1) |
512 firstSlotConnected(signalId); | 514 signalEvent(signalId, SignalEventId.firstSlotConnected); |
513 | 515 |
514 return slot; | 516 return slot; |
515 } | 517 } |
516 | 518 |
517 private void removeSlot(int slotListId)(int signalId, int slotId) | 519 private void removeSlot(int slotListId)(int signalId, int slotId) |
518 { | 520 { |
519 connections[signalId].removeSlot!(slotListId)(slotId); | 521 connections[signalId].removeSlot!(slotListId)(slotId); |
520 | 522 |
521 if (lastSlotDisconnected && !connections[signalId].slotCount) | 523 if (signalEvent && !connections[signalId].slotCount) |
522 lastSlotDisconnected(signalId); | 524 signalEvent(signalId, SignalEventId.lastSlotDisconnected); |
523 } | 525 } |
524 | 526 |
525 private SlotType!(slotListId)* addObjectSlot(int slotListId)(size_t signalId, Object obj, Dg receiver, | 527 private SlotType!(slotListId)* addObjectSlot(int slotListId)(size_t signalId, Object obj, Dg receiver, |
526 Dg invoker) | 528 Dg invoker) |
527 { | 529 { |