Regina 7.0 Calculation Engine
|
An object that facilitates firing packetToBeChanged() and packetWasChanged() events. More...
#include <packet/packet.h>
Public Member Functions | |
ChangeEventSpan (Packet &packet) | |
Creates a new change event object for the given packet. More... | |
~ChangeEventSpan () | |
Destroys this change event object. More... | |
ChangeEventSpan (const ChangeEventSpan &)=delete | |
ChangeEventSpan & | operator= (const ChangeEventSpan &)=delete |
An object that facilitates firing packetToBeChanged() and packetWasChanged() events.
Objects of this type should be created on the stack before data within a packet is changed. On creation, this object will fire a PacketListener::packetToBeChanged() event to all registered listeners. On destruction (i.e., when the object goes out of scope), it will fire a PacketListener::packetWasChanged() event.
It may be the case that several objects of this type all exist at the same time for the same packet. In this case, only the outermost object will fire events; that is, only the first object to be constructed will fire PacketListener::packetToBeChanged(), and only the last object to be destroyed will fire PacketListener::packetWasChanged(). This is because the "inner" ChangeEventSpan objects earlier represent smaller events that are part of a larger suite of changes.
If you are writing code that makes a large number of changes to a packet, it is highly recommended that you declare a ChangeEventSpan at the beginning of your code. This will ensure that listeners only receive one pair of events for the entire change set, instead of many events representing each individual modification.
ChangeEventSpan objects are not copyable, movable or swappable. In particular, Regina does not offer any way for a ChangeEventSpan to transfer its duty (i.e., firing events upon destruction) to another object.
|
inline |
Creates a new change event object for the given packet.
If this is the only ChangeEventSpan currently in existence for the given packet, this constructor will call PacketListener::packetToBeChanged() for all registered listeners for the given packet.
packet | the packet whose data is about to change. |
|
inline |
Destroys this change event object.
If this is the only ChangeEventSpan currently in existence for the given packet, this destructor will call PacketListener::packetWasChanged() for all registered listeners for the given packet.