Regina Calculation Engine
|
Represents a packet of information that may be individually edited or operated upon. More...
#include <packet/packet.h>
Classes | |
class | ChangeEventSpan |
An object that facilitates firing packetToBeChanged() and packetWasChanged() events. More... | |
Public Types | |
typedef Packet | SafePointeeType |
The type of object being pointed to. More... | |
Public Member Functions | |
std::string | str () const |
Returns a short text representation of this object. More... | |
std::string | utf8 () const |
Returns a short text representation of this object using unicode characters. More... | |
std::string | detail () const |
Returns a detailed text representation of this object. More... | |
bool | hasSafePtr () const |
Is there one or more SafePtr currently pointing to this object? More... | |
Constructors and Destructors | |
Packet (Packet *parent=0) | |
Constructor that inserts the new packet into the overall tree structure. More... | |
virtual | ~Packet () |
Destructor that also orphans this packet and destroys all of its descendants. More... | |
static void | safeDelete (Packet *p) |
Either destroys or orphans the given packet, according to whether it has safe pointers that currently reference it. More... | |
Packet Dependencies | |
virtual bool | dependsOnParent () const =0 |
Determines if this packet depends upon its parent. More... | |
bool | isPacketEditable () const |
Determines whether this packet can be altered without invalidating or otherwise upsetting any of its immediate children. More... | |
File I/O | |
bool | save (const char *filename, bool compressed=true) const |
Saves the subtree rooted at this packet to the given Regina data file, using Regina's native XML file format. More... | |
bool | save (std::ostream &s, bool compressed=true) const |
Writes the subtree rooted at this packet to the given output stream, in the format of a Regina XML data file. More... | |
void | writeXMLFile (std::ostream &out) const |
Writes the subtree rooted at this packet to the given output stream in Regina's native XML file format. More... | |
std::string | internalID () const |
Returns a unique string ID that identifies this packet. More... | |
Packet (const Packet &)=delete | |
Packet & | operator= (const Packet &)=delete |
virtual void | writeTextShort (std::ostream &out) const =0 |
Writes a short text representation of this object to the given output stream. More... | |
virtual void | writeTextLong (std::ostream &out) const |
Writes a detailed text representation of this object to the given output stream. More... | |
bool | hasOwner () const |
Indicates whether some other object in the calculation engine is responsible for ultimately destroying this object. More... | |
static XMLPacketReader * | xmlReader (Packet *parent, XMLTreeResolver &resolver) |
Returns a newly created XML element reader that will read the contents of a single XML packet element. More... | |
virtual Packet * | internalClonePacket (Packet *parent) const =0 |
Makes a newly allocated copy of this packet. More... | |
void | writeXMLPacketTree (std::ostream &out) const |
Writes a chunk of XML containing the subtree with this packet as matriarch. More... | |
virtual void | writeXMLPacketData (std::ostream &out) const =0 |
Writes a chunk of XML containing the data for this packet only. More... | |
Represents a packet of information that may be individually edited or operated upon.
Packets are stored in a dependency tree, where child packets fit within the context of (or otherwise cannot live without) parent packets.
When deriving classes from Packet:
static XMLPacketReader* xmlReader(Packet* parent, XMLTreeResolver& resolver)
must be declared and implemented. See the notes for xmlReader() for further details. Note that external objects can listen for events on packets, such as when packets are changed or about to be destroyed. See the PacketListener class notes for details.
Packets are able to work with SafePtr smart pointers under fluid ownership rules: they may be owned either by this C++ engine or by external safe pointers at different times during the packet's lifespan. The general things to remember are:
If you are passing packets to an external interface that does use SafePtr to store them, then you must be careful when deleting packets from within C++ code. If you are at risk of destroying a packet that the external interface holds a safe pointer to, you should call Packet::safeDelete() instead of just delete
. This will test for the existence of safe pointers, and if there are any then it will preserve the packet (but remove it from the packet tree), thereby leaving the safe pointers in the external interface to manage its lifespan. Examples of such situations are when the user manually deletes a packet within a GUI, or where a child packet is deleted as a result of its parent packet being destroyed. (The Packet destructor calls safeDelete() instead of delete
on its child packets for exactly this reason.)
|
inherited |
The type of object being pointed to.
|
inherited |
Returns a detailed text representation of this object.
This text may span many lines, and should provide the user with all the information they could want. It should be human-readable, should not contain extremely long lines (which cause problems for users reading the output in a terminal), and should end with a final newline. There are no restrictions on the underlying character set.
|
inlineinherited |
Is there one or more SafePtr currently pointing to this object?
|
inherited |
Returns a short text representation of this object.
This text should be human-readable, should fit on a single line, and should not end with a newline. Where possible, it should use plain ASCII characters.
__str__()
.
|
inherited |
Returns a short text representation of this object using unicode characters.
Like str(), this text should be human-readable, should fit on a single line, and should not end with a newline. In addition, it may use unicode characters to make the output more pleasant to read. This string will be encoded in UTF-8.