Mercurial > projects > qtd
comparison qt/d2/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 | cf6a4cd0e3f2 |
comparison
equal
deleted
inserted
replaced
252:37eed70de029 | 253:073b9153ed8a |
---|---|
69 { | 69 { |
70 if (a.length > 1) | 70 if (a.length > 1) |
71 memmove(a.ptr + dest, a.ptr + src, length * T.sizeof); | 71 memmove(a.ptr + dest, a.ptr + src, length * T.sizeof); |
72 } | 72 } |
73 | 73 |
74 enum SignalEventId | |
75 { | |
76 firstSlotConnected, | |
77 lastSlotDisconnected | |
78 } | |
74 | 79 |
75 public class SignalException : Exception | 80 public class SignalException : Exception |
76 { | 81 { |
77 this(string msg) | 82 this(string msg) |
78 { | 83 { |
329 static if (!strong) | 334 static if (!strong) |
330 cfree(data.ptr); | 335 cfree(data.ptr); |
331 } | 336 } |
332 } | 337 } |
333 | 338 |
334 public alias void delegate(int signalId) SignalEvent; | 339 public alias void delegate(int signalId, SignalEventId event) SignalEvent; |
335 | 340 |
336 struct SignalConnections | 341 struct SignalConnections |
337 { | 342 { |
338 bool isInUse; | 343 bool isInUse; |
339 | 344 |
442 public class SignalHandler | 447 public class SignalHandler |
443 { | 448 { |
444 SignalConnections[] connections; | 449 SignalConnections[] connections; |
445 Object owner; | 450 Object owner; |
446 int blocked; | 451 int blocked; |
447 | 452 |
448 // Called after a slot has been connected to an empty signal | 453 SignalEvent signalEvent; |
449 SignalEvent firstSlotConnected; | 454 |
450 // Called after the last slot has been disconnected from a signal | |
451 SignalEvent lastSlotDisconnected; | |
452 | |
453 alias SignalConnections.SlotType SlotType; | 455 alias SignalConnections.SlotType SlotType; |
454 alias SignalConnections.ReceiverType ReceiverType; | 456 alias SignalConnections.ReceiverType ReceiverType; |
455 | 457 |
456 public this(Object owner_) { | 458 public this(Object owner_) { |
457 owner = owner_; | 459 owner = owner_; |
469 { | 471 { |
470 if (signalId >= connections.length) | 472 if (signalId >= connections.length) |
471 connections.length = signalId + 1; | 473 connections.length = signalId + 1; |
472 auto slot = connections[signalId].addSlot!(slotListId)(SlotType!(slotListId)(receiver, invoker)); | 474 auto slot = connections[signalId].addSlot!(slotListId)(SlotType!(slotListId)(receiver, invoker)); |
473 | 475 |
474 if (firstSlotConnected && connections[signalId].slotCount == 1) | 476 if (signalEvent && connections[signalId].slotCount == 1) |
475 firstSlotConnected(signalId); | 477 signalEvent(signalId, SignalEventId.firstSlotConnected); |
476 | 478 |
477 return slot; | 479 return slot; |
478 } | 480 } |
479 | 481 |
480 private void removeSlot(int slotListId)(int signalId, int slotId) | 482 private void removeSlot(int slotListId)(int signalId, int slotId) |
481 { | 483 { |
482 connections[signalId].removeSlot!(slotListId)(slotId); | 484 connections[signalId].removeSlot!(slotListId)(slotId); |
483 | 485 |
484 if (lastSlotDisconnected && !connections[signalId].slotCount) | 486 if (signalEvent && !connections[signalId].slotCount) |
485 lastSlotDisconnected(signalId); | 487 signalEvent(signalId, SignalEventId.lastSlotDisconnected); |
486 } | 488 } |
487 | 489 |
488 private SlotType!(slotListId)* addObjectSlot(int slotListId)(size_t signalId, Object obj, Dg receiver, | 490 private SlotType!(slotListId)* addObjectSlot(int slotListId)(size_t signalId, Object obj, Dg receiver, |
489 Dg invoker) | 491 Dg invoker) |
490 { | 492 { |