Regina 7.3 Calculation Engine
|
An object that can be registered to listen for packet events. More...
#include <packet/packet.h>
Public Member Functions | |
Constructors and Destructors | |
virtual | ~PacketListener () |
Destroys this listener. More... | |
Packet Listener Interface | |
class | Packet |
Allow packets to automatically deregister listeners as they are destroyed. More... | |
bool | isListening () const |
Determines whether this object is listening for events on any packets at all. More... | |
void | unlisten () |
Unregisters this listener from all packets to which it is currently listening. More... | |
virtual void | packetToBeChanged (Packet &packet) |
Called before the contents of the packet are to be changed. More... | |
virtual void | packetWasChanged (Packet &packet) |
Called after the contents of the packet have been changed. More... | |
virtual void | packetToBeRenamed (Packet &packet) |
Called before the packet label or tags are to be changed. More... | |
virtual void | packetWasRenamed (Packet &packet) |
Called after the packet label or tags have been changed. More... | |
virtual void | packetBeingDestroyed (PacketShell packet) |
Called as the packet is being destroyed. More... | |
virtual void | childToBeAdded (Packet &packet, Packet &child) |
Called before a child packet is to be inserted directly beneath the packet. More... | |
virtual void | childWasAdded (Packet &packet, Packet &child) |
Called after a child packet has been inserted directly beneath the packet. More... | |
virtual void | childToBeRemoved (Packet &packet, Packet &child) |
Called before a child packet is to be removed from directly beneath the packet. More... | |
virtual void | childWasRemoved (Packet &packet, Packet &child) |
Called after a child packet has been removed from directly beneath the packet. More... | |
virtual void | childrenToBeReordered (Packet &packet) |
Called before the child packets directly beneath the packet are to be reordered. More... | |
virtual void | childrenWereReordered (Packet &packet) |
Called after the child packets directly beneath the packet have been reordered. More... | |
virtual void | childToBeRenamed (Packet &packet, Packet &child) |
Called before one of this packet's immediate children has its label or tags changed. More... | |
virtual void | childWasRenamed (Packet &packet, Packet &child) |
Called after one of this packet's immediate children has its label or tags changed. More... | |
virtual void | packetToBeChanged (Packet *) final |
A placeholder for an old form of a callback function that is no longer used. More... | |
virtual void | packetWasChanged (Packet *) final |
A placeholder for an old form of a callback function that is no longer used. More... | |
virtual void | packetToBeRenamed (Packet *) final |
A placeholder for an old form of a callback function that is no longer used. More... | |
virtual void | packetWasRenamed (Packet *) final |
A placeholder for an old form of a callback function that is no longer used. More... | |
virtual void | packetToBeDestroyed (PacketShell) final |
A placeholder for an old callback function that is no longer used. More... | |
virtual void | childToBeAdded (Packet *, Packet *) final |
A placeholder for an old form of a callback function that is no longer used. More... | |
virtual void | childWasAdded (Packet *, Packet *) final |
A placeholder for an old form of a callback function that is no longer used. More... | |
virtual void | childToBeRemoved (Packet *, Packet *) final |
A placeholder for an old form of a callback function that is no longer used. More... | |
virtual void | childWasRemoved (Packet *, Packet *) final |
A placeholder for an old form of a callback function that is no longer used. More... | |
virtual void | childrenToBeReordered (Packet *) final |
A placeholder for an old form of a callback function that is no longer used. More... | |
virtual void | childrenWereReordered (Packet *) final |
A placeholder for an old form of a callback function that is no longer used. More... | |
virtual void | childToBeRenamed (Packet *, Packet *) final |
A placeholder for an old form of a callback function that is no longer used. More... | |
virtual void | childWasRenamed (Packet *, Packet *) final |
A placeholder for an old form of a callback function that is no longer used. More... | |
PacketListener ()=default | |
Default constructor. More... | |
PacketListener (const PacketListener &src) | |
Copy constructor. More... | |
PacketListener & | operator= (const PacketListener &src) |
Copy assignment operator. More... | |
void | swapListeners (PacketListener &other) |
Swap operation. More... | |
An object that can be registered to listen for packet events.
A packet listener can be registered to listen for events on a packet by calling Packet::listen().
Each time that one of the events listed in this class occurs, the packet will call the appropriate callback routine for all registered listeners.
These events come in future/past pairs: packetToBeChanged() and packetWasChanged(), childToBeAdded() and childWasAdded(), and so on. These event pairs are mutually exclusive: any event will cause at most one pair of callback routines to be called for each (packet, listener) pair. For instance, if a packet is renamed then packetToBeRenamed() and packetWasRenamed() will be called but packetToBeChanged() and packetWasChanged() will not.
As a special case, when a packet is destroyed there is only the one event packetBeingDestroyed(), since this is called during the packet destructor (at a time when the set of listeners is still available, but some of the other packet data may have already been destroyed).
No guarantees are made as to the order in which the different packet listeners are notified of an event.
When a listener is destroyed, it is automatically unregistered from any packets to which it is currently listening. Similarly, when a packet is destroyed all listeners are automatically unregistered.
To listen for packet events using your own callback routines, you would typically implement a subclass of PacketListener that overrides only those callbacks that you are interested in. Be aware that:
|
inlinevirtual |
Destroys this listener.
This listener will be unregistered from any packets to which it is currently listening.
|
protecteddefault |
Default constructor.
The new listener will not be listening to any packets.
|
protected |
Copy constructor.
The new listener will be registered as listening to the same packets as src.
src | the listener to copy. |
|
inlinevirtual |
Called before the child packets directly beneath the packet are to be reordered.
Once the reordering is done, childrenWereReordered() will be called also.
The default implementation of this routine is to do nothing.
packet | the packet being listened to. |
|
inlinefinalvirtual |
A placeholder for an old form of a callback function that is no longer used.
This has been kept but marked final
to force a compile error if any subclass attempts to remimplement it.
The new form of the childrenToBeReordered() callback now takes its argument by reference, not by pointer.
|
inlinevirtual |
Called after the child packets directly beneath the packet have been reordered.
Before this reordering is done, childrenToBeReordered() will be called also.
The default implementation of this routine is to do nothing.
packet | the packet being listened to. |
|
inlinefinalvirtual |
A placeholder for an old form of a callback function that is no longer used.
This has been kept but marked final
to force a compile error if any subclass attempts to remimplement it.
The new form of the childrenWereReordered() callback now takes its argument by reference, not by pointer.
|
inlinevirtual |
Called before a child packet is to be inserted directly beneath the packet.
Once the child is inserted, childWasAdded() will be called also.
The default implementation of this routine is to do nothing.
packet | the packet being listened to. |
child | the child packet to be added. |
A placeholder for an old form of a callback function that is no longer used.
This has been kept but marked final
to force a compile error if any subclass attempts to remimplement it.
The new form of the childToBeAdded() callback now takes its arguments by reference, not by pointer.
|
inlinevirtual |
Called before a child packet is to be removed from directly beneath the packet.
Once the child is removed, childWasRemoved() will be called also.
Since Regina 7.0, this routine is no longer called from within either the parent or child packet's destructor. In particular, when a parent packet is destroyed, although it orphans all of its children as part of the destruction process, it does not call childToBeRemoved() or childWasRemoved when this happens.
The default implementation of this routine is to do nothing.
packet | the packet being listened to, or null if this routine is being called from within this packet's destructor. |
child | the child packet to be removed. |
A placeholder for an old form of a callback function that is no longer used.
This has been kept but marked final
to force a compile error if any subclass attempts to remimplement it.
The new form of the childToBeRemoved() callback now takes its arguments by reference, not by pointer, and is no longer called from within either the child or parent destructor.
|
inlinevirtual |
Called before one of this packet's immediate children has its label or tags changed.
Before this change, childToBeRenamed() will be called also.
The default implementation of this routine is to do nothing.
packet | the packet being listened to. |
child | the child packet to be renamed. |
A placeholder for an old form of a callback function that is no longer used.
This has been kept but marked final
to force a compile error if any subclass attempts to remimplement it.
The new form of the childToBeRenamed() callback now takes its arguments by reference, not by pointer.
|
inlinevirtual |
Called after a child packet has been inserted directly beneath the packet.
Before this child is added, childToBeAdded() will be called also.
The default implementation of this routine is to do nothing.
packet | the packet being listened to. |
child | the child packet that was added. |
A placeholder for an old form of a callback function that is no longer used.
This has been kept but marked final
to force a compile error if any subclass attempts to remimplement it.
The new form of the childWasAdded() callback now takes its arguments by reference, not by pointer.
|
inlinevirtual |
Called after a child packet has been removed from directly beneath the packet.
Before the child is removed, childToBeRemoved() will be called also.
Since Regina 7.0, this routine is no longer called from within either the parent or child packet's destructor. In particular, when a parent packet is destroyed, although it orphans all of its children as part of the destruction process, it does not call childToBeRemoved() or childWasRemoved when this happens.
The default implementation of this routine is to do nothing.
packet | the packet being listened to, or null if this routine is being called from within this packet's destructor. |
child | the child packet that was removed. |
A placeholder for an old form of a callback function that is no longer used.
This has been kept but marked final
to force a compile error if any subclass attempts to remimplement it.
The new form of the childWasRemoved() callback now takes its arguments by reference, not by pointer, and is no longer called from within either the child or parent destructor.
|
inlinevirtual |
Called after one of this packet's immediate children has its label or tags changed.
Before this change, childToBeRenamed() will be called also.
The default implementation of this routine is to do nothing.
packet | the packet being listened to. |
child | the child packet that was renamed. |
A placeholder for an old form of a callback function that is no longer used.
This has been kept but marked final
to force a compile error if any subclass attempts to remimplement it.
The new form of the childWasRenamed() callback now takes its arguments by reference, not by pointer.
|
inline |
Determines whether this object is listening for events on any packets at all.
true
if and only if this object is listening on at least one packet.
|
protected |
Copy assignment operator.
This listener will be unregistered from whatever packets it is currently listening to, and instead will be registered as listening to the same packets as src.
src | the listener to copy. |
|
inlinevirtual |
Called as the packet is being destroyed.
By the time this function is called, we are already inside the Packet destructor, and so most Packet member functions are no longer safe to call. Therefore the argument that is passed to this routine is a PacketShell, which exposes only those member functions of Packet that are still safe to call at this time. Importantly, you can safely compare a PacketShell against a Packet pointer, in case you need to identify which particular packet is being destroyed.
When a packet is destroyed, it will automatically unregister each listener before calling packetBeingDestroyed() on that listener. Therefore, for this (and only this) callback, it is safe for a listener to unregister itself (since this will be a harmless operation that does nothing). In particular, this makes it safe for a listener to delete itself during this callback.
When an entire packet subtree is to be destroyed, child packets will notify their listeners of the impending destruction before parent packets will.
The default implementation of this routine is to do nothing.
packet | gives access to the packet being listened to. |
|
inlinevirtual |
Called before the contents of the packet are to be changed.
Once the contents are changed, packetWasChanged() will be called also.
The default implementation of this routine is to do nothing.
packet | the packet being listened to. |
|
inlinefinalvirtual |
A placeholder for an old form of a callback function that is no longer used.
This has been kept but marked final
to force a compile error if any subclass attempts to remimplement it.
The new form of the packetToBeChanged() callback now takes its argument by reference, not by pointer.
|
inlinefinalvirtual |
A placeholder for an old callback function that is no longer used.
This has been kept but marked final
to force a compile error if any subclass attempts to remimplement it.
This callback has been renamed to packetBeingDestroyed(), to emphasise the fact that we are already well inside the packet destructor when this is called.
final
to prevent subclasses from overriding a function.
|
inlinevirtual |
Called before the packet label or tags are to be changed.
Once the label or tags are changed, packetWasRenamed() will be called also.
The default implementation of this routine is to do nothing.
packet | the packet being listened to. |
|
inlinefinalvirtual |
A placeholder for an old form of a callback function that is no longer used.
This has been kept but marked final
to force a compile error if any subclass attempts to remimplement it.
The new form of the packetToBeRenamed() callback now takes its argument by reference, not by pointer.
|
inlinevirtual |
Called after the contents of the packet have been changed.
Before the contents are changed, packetToBeChanged() will be called also.
The default implementation of this routine is to do nothing.
packet | the packet being listened to. |
|
inlinefinalvirtual |
A placeholder for an old form of a callback function that is no longer used.
This has been kept but marked final
to force a compile error if any subclass attempts to remimplement it.
The new form of the packetWasChanged() callback now takes its argument by reference, not by pointer.
|
inlinevirtual |
Called after the packet label or tags have been changed.
Before the label or tags are changed, packetToBeRenamed() will be called also.
The default implementation of this routine is to do nothing.
packet | the packet being listened to. |
|
inlinefinalvirtual |
A placeholder for an old form of a callback function that is no longer used.
This has been kept but marked final
to force a compile error if any subclass attempts to remimplement it.
The new form of the packetWasRenamed() callback now takes its argument by reference, not by pointer.
|
protected |
Swap operation.
This listener will be unregistered from whatever packets it is currently listening to and instead will be registered as listening to the same packets that src was originally listening to, and vice versa.
This operation is not constant time, since it needs to perform an internal adjustment for each packet that is affected.
other | the listener to swap with this. |
void regina::PacketListener::unlisten | ( | ) |
Unregisters this listener from all packets to which it is currently listening.
|
friend |
Allow packets to automatically deregister listeners as they are destroyed.