Regina 7.4 Calculation Engine
|
An object that facilitates firing packetToBeChanged() and packetWasChanged() events. More...
#include <packet/packet.h>
Public Member Functions | |
PacketChangeSpan (Packet &packet) | |
Creates a new change event object for the given packet. | |
~PacketChangeSpan () | |
Destroys this change event object. | |
PacketChangeSpan (const PacketChangeSpan &)=delete | |
PacketChangeSpan & | operator= (const PacketChangeSpan &)=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" PacketChangeSpan objects earlier represent smaller events that are part of a larger suite of changes.
If you are writing a block of code that makes a large number of changes to a packet, it is highly recommended that you declare a PacketChangeSpan at the beginning of this block. This will ensure that listeners only receive one pair of events for the entire change set, instead of many events representing each individual modification. If a PacketChangeSpan s is only for this purpose (i.e., the necessary events would have been fired without it, but s serves to merge many event pairs into just one event pair), then consider declaring s using the equivalent type PacketChangeGroup (which makes its purpose clearer to the reader).
PacketChangeSpan objects are not copyable, movable or swappable. In particular, Regina does not offer any way for a PacketChangeSpan 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 PacketChangeSpan 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 PacketChangeSpan currently in existence for the given packet, this destructor will call PacketListener::packetWasChanged() for all registered listeners for the given packet.