Regina 7.3 Calculation Engine
|
A packet that can hold an arbitrary file attachment. More...
#include <packet/attachment.h>
Public Types | |
enum | OwnershipPolicy { OWN_MALLOC , OWN_NEW , DEEP_COPY } |
Describes how an attachment packet should claim ownership of a block of binary data. More... | |
Public Member Functions | |
Attachment () | |
Creates a packet with no attachment stored. More... | |
Attachment (const char *pathname) | |
Creates a new attachment containing the contents of the given file. More... | |
Attachment (char *data, size_t size, OwnershipPolicy alloc, std::string filename) | |
Creates a new attachment containing the given binary data. More... | |
Attachment (const Attachment &src) | |
Creates a new deep copy of the given attachment. More... | |
~Attachment () override | |
Destroys this attachment packet and deallocates data if required. More... | |
Attachment & | operator= (const Attachment &src) |
Sets this to be a deep copy of the given attachment. More... | |
void | swap (Attachment &other) |
Swaps the contents of this and the given attachment. More... | |
bool | isNull () const |
Determines whether this packet is currently holding a non-empty attachment. More... | |
const char * | data () const |
Returns a pointer to the block of raw data that forms this attachment. More... | |
size_t | size () const |
Returns the size of this attachment in bytes. More... | |
const std::string & | filename () const |
Returns the filename associated with this attachment. More... | |
std::string | extension () const |
Returns the extension of the filename associated with this attachment. More... | |
void | reset () |
Empties this packet so that no attachment is stored. More... | |
void | reset (char *data, size_t size, OwnershipPolicy alloc, std::string filename) |
Refills this attachment packet with the given binary data. More... | |
bool | save (const char *pathname) const |
Saves the contents of this attachment to the given file. More... | |
bool | operator== (const Attachment &other) const |
Determines if this and the given attachment hold identical data. More... | |
bool | operator!= (const Attachment &other) const |
Determines if this and the given attachment hold different data. More... | |
void | writeTextShort (std::ostream &out) const override |
Writes a short text representation of this object to the given output stream. More... | |
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... | |
Packet Identification | |
virtual PacketType | type () const =0 |
Returns the unique integer ID representing this type of packet. More... | |
virtual std::string | typeName () const =0 |
Returns an English name for this type of packet. More... | |
const std::string & | label () const |
Returns the label associated with this individual packet. More... | |
std::string | humanLabel () const |
Returns the label associated with this individual packet, adjusted if necessary for human-readable output. More... | |
std::string | adornedLabel (const std::string &adornment) const |
Returns the label of this packet adorned with the given string. More... | |
void | setLabel (const std::string &label) |
Sets the label associated with this individual packet. More... | |
std::string | fullName () const |
Returns a descriptive text string for the packet. More... | |
Tags | |
bool | hasTag (const std::string &tag) const |
Determines whether this packet has the given associated tag. More... | |
bool | hasTags () const |
Determines whether this packet has any associated tags at all. More... | |
bool | addTag (const std::string &tag) |
Associates the given tag with this packet. More... | |
bool | removeTag (const std::string &tag) |
Removes the association of the given tag with this packet. More... | |
void | removeAllTags () |
Removes all associated tags from this packet. More... | |
const std::set< std::string > & | tags () const |
Returns the set of all tags associated with this packet. More... | |
Event Handling | |
bool | listen (PacketListener *listener) |
Registers the given packet listener to listen for events on this packet. More... | |
bool | isListening (PacketListener *listener) |
Determines whether the given packet listener is currently listening for events on this packet. More... | |
bool | unlisten (PacketListener *listener) |
Unregisters the given packet listener so that it no longer listens for events on this packet. More... | |
Tree Queries | |
bool | samePacket (const Packet &other) const |
Determines whether this and the given object refer to the same packet. More... | |
bool | hasParent () const |
Determines if this packet has a parent in the tree structure. More... | |
std::shared_ptr< Packet > | parent () const |
Determines the parent packet in the tree structure. More... | |
std::shared_ptr< Packet > | firstChild () const |
Determines the first child of this packet in the tree structure. More... | |
std::shared_ptr< Packet > | lastChild () const |
Determines the last child of this packet in the tree structure. More... | |
std::shared_ptr< Packet > | nextSibling () const |
Determines the next sibling of this packet in the tree structure. More... | |
std::shared_ptr< Packet > | prevSibling () const |
Determines the previous sibling of this packet in the tree structure. More... | |
std::shared_ptr< Packet > | root () const |
Determines the root of the tree to which this packet belongs. More... | |
unsigned | levelsDownTo (const Packet &descendant) const |
Counts the number of levels between this packet and its given descendant in the tree structure. More... | |
unsigned | levelsUpTo (const Packet &ancestor) const |
Counts the number of levels between this packet and its given ancestor in the tree structure. More... | |
bool | isAncestorOf (const Packet &descendant) const |
Determines if this packet is equal to or an ancestor of the given packet in the tree structure. More... | |
size_t | countChildren () const |
Returns the number of immediate children of this packet. More... | |
size_t | countDescendants () const |
Returns the total number of strict descendants of this packet. More... | |
size_t | totalTreeSize () const |
Determines the total number of packets in the tree or subtree for which this packet is matriarch. More... | |
Tree Manipulation | |
void | prepend (std::shared_ptr< Packet > child) |
Inserts the given packet as the first child of this packet. More... | |
void | insertChildFirst (std::shared_ptr< Packet > child) |
Deprecated routine that inserts the given packet as the first child of this packet. More... | |
void | append (std::shared_ptr< Packet > child) |
Inserts the given packet as the last child of this packet. More... | |
void | insertChildLast (std::shared_ptr< Packet > child) |
Deprecated routine that inserts the given packet as the last child of this packet. More... | |
void | insert (std::shared_ptr< Packet > newChild, std::shared_ptr< Packet > prevChild) |
Inserts the given packet as a child of this packet at the given location in this packet's child list. More... | |
void | insertChildAfter (std::shared_ptr< Packet > newChild, std::shared_ptr< Packet > prevChild) |
Deprecated routine that inserts the given packet as a child of this packet at the given location in this packet's child list. More... | |
void | makeOrphan () |
Cuts this packet away from its parent in the tree structure and instead makes it the root of its own tree. More... | |
void | reparent (const std::shared_ptr< Packet > &newParent, bool first=false) |
Cuts this packet away from its parent in the tree structure, and inserts it as a child of the given packet instead. More... | |
void | transferChildren (const std::shared_ptr< Packet > &newParent) |
Cuts all of this packet's children out of the packet tree, and reinserts them as children of the given packet instead. More... | |
void | swapWithNextSibling () |
Swaps this packet with its next sibling in the sequence of children beneath their common parent packet. More... | |
void | moveUp (unsigned steps=1) |
Moves this packet the given number of steps towards the beginning of its sibling list. More... | |
void | moveDown (unsigned steps=1) |
Moves this packet the given number of steps towards the end of its sibling list. More... | |
void | moveToFirst () |
Moves this packet to be the first in its sibling list. More... | |
void | moveToLast () |
Moves this packet to be the last in its sibling list. More... | |
void | sortChildren () |
Sorts the immediate children of this packet according to their packet labels. More... | |
Searching and Iterating | |
SubtreeIterator< false > | begin () |
Returns a C++ non-const iterator at the beginning of the range of packets in the subtree rooted at this packet. More... | |
SubtreeIterator< true > | begin () const |
Returns a C++ const iterator at the beginning of the range of packets in the subtree rooted at this packet. More... | |
SubtreeIterator< false > | end () |
Returns a C++ non-const iterator beyond the end of the range of packets in the subtree rooted at this packet. More... | |
SubtreeIterator< true > | end () const |
Returns a C++ const iterator beyond the end of the range of packets in the subtree rooted at this packet. More... | |
auto | __iter__ () const |
Returns a Python iterator over the packets in the subtree rooted at this packet. More... | |
PacketDescendants< false > | descendants () |
Returns a lightweight object for iterating through all strict descendants of this packet in the packet tree. More... | |
PacketDescendants< true > | descendants () const |
Returns a lightweight object for iterating through all strict descendants of this packet in the packet tree. More... | |
PacketChildren< false > | children () |
Returns a lightweight object for iterating through the immediate children of this packet. More... | |
PacketChildren< true > | children () const |
Returns a lightweight object for iterating through the immediate children of this packet. More... | |
std::shared_ptr< Packet > | nextTreePacket () |
Finds the next packet after this in a complete depth-first iteration of the entire tree structure to which this packet belongs. More... | |
std::shared_ptr< const Packet > | nextTreePacket () const |
Finds the next packet after this in a complete depth-first iteration of the entire tree structure to which this packet belongs. More... | |
std::shared_ptr< Packet > | nextTreePacket (PacketType type) |
Finds the next packet after this of the requested type in a complete depth-first iteration of the entire tree structure. More... | |
std::shared_ptr< const Packet > | nextTreePacket (PacketType type) const |
Finds the next packet after this of the requested type in a complete depth-first iteration of the entire tree structure. More... | |
std::shared_ptr< Packet > | firstTreePacket (PacketType type) |
Finds the first packet of the requested type in a complete depth-first iteration of the tree structure. More... | |
std::shared_ptr< const Packet > | firstTreePacket (PacketType type) const |
Finds the first packet of the requested type in a complete depth-first iteration of the tree structure. More... | |
std::shared_ptr< Packet > | findPacketLabel (const std::string &label) |
Finds the packet with the requested label in the tree or subtree for which this packet is matriarch. More... | |
std::shared_ptr< const Packet > | findPacketLabel (const std::string &label) const |
Finds the packet with the requested label in the tree or subtree for which this packet is matriarch. More... | |
Cloning | |
std::shared_ptr< Packet > | cloneAsSibling (bool cloneDescendants=false, bool end=true) const |
Clones this packet (and possibly its descendants), assigns to it a suitable unused label and inserts the clone into the tree as a sibling of this packet. More... | |
Protected Member Functions | |
std::shared_ptr< Packet > | internalClonePacket () const override |
Makes a new copy of this packet. More... | |
void | writeXMLPacketData (std::ostream &out, FileFormat format, bool anon, PacketRefs &refs) const override |
Writes a chunk of XML containing the full subtree with this packet as matriarch. More... | |
File I/O | |
bool | save (const char *filename, bool compressed=true, FileFormat format=REGINA_CURRENT_FILE_FORMAT) 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, FileFormat format=REGINA_CURRENT_FILE_FORMAT) 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, FileFormat format=REGINA_CURRENT_FILE_FORMAT) 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... | |
virtual void | writeTextLong (std::ostream &out) const |
Writes a detailed text representation of this object to the given output stream. More... | |
template<typename... Args> | |
void | writeXMLHeader (std::ostream &out, const char *element, FileFormat format, bool anon, PacketRefs &refs, bool newline, std::pair< const char *, Args >... attr) const |
Writes the opening XML tag for this packet. More... | |
void | writeXMLTreeData (std::ostream &out, FileFormat format, PacketRefs &refs) const |
Writes any generic XML sub-elements for this packet that come from the packet tree. More... | |
void | writeXMLFooter (std::ostream &out, const char *element, FileFormat format) const |
Writes the closing XML tag for this packet. More... | |
void | writeXMLAnon (std::ostream &out, FileFormat format, PacketRefs &refs, const Packet &p) const |
Writes the given packet inside its own anonymous block. More... | |
virtual void | addPacketRefs (PacketRefs &refs) const |
Records which other packets this packet refers to within the overall packet tree. More... | |
using | PacketRefs = std::map< const Packet *, bool > |
Used during the XML output routines to manage references between packets in an XML data file. More... | |
A packet that can hold an arbitrary file attachment.
The attachment is stored as a block of data in memory. If the attachment was originally read from the filesystem, this link is not maintained (i.e., if the source file subsequently changes, the attachment data stored in this packet will not change to reflect this).
This packet may or may not contain an attachment at any given time. This can be tested by calling isNull(), and can be changed by calling reset().
This class does not distinguish between an empty file attachment versus no attachment at all. In both cases, isNull() will return true
.
Like all packet types, this class does not support C++ move semantics since this would interfere with the structure of the packet tree. It does support copy construction, copy assignment and swaps; however, these operations only copy/swap the mathematical content, not the packet infrastructure (e.g., they do not touch packet labels, or the packet tree, or event listeners).
Until Regina 6.0.1, this class was called PDF. It was renamed and expanded in Regina 7.0 to allow for any kind of file to be attached.
|
protectedinherited |
Used during the XML output routines to manage references between packets in an XML data file.
If some packet needs to refer to a packet P, then P will appear as a key this map; the corresponding value will be false
initially, and will change to true
once P has been written to the XML file.
Describes how an attachment packet should claim ownership of a block of binary data.
|
inline |
regina::Attachment::Attachment | ( | const char * | pathname | ) |
Creates a new attachment containing the contents of the given file.
The file will be read immediately, but no ongoing link will be maintained. That is, if the given file should later change its contents on the filesystem, the change will not be reflected in this attachment packet.
If the file could not be read or is empty, then no attachment will be stored. You can test this by calling isNull().
The filename that is stored with this attachment (i.e., the string that will be returned by filename()) will be the argument pathname with any directory prefixes removed (i.e., just the final filename component). If an error occurs when attempting to remove directory prefixes, the filename will be the empty string.
pathname | the full pathname of the attachment to read. |
|
inline |
Creates a new attachment containing the given binary data.
The data array must contain a block of binary data, of size bytes. There is no notion of null termination: the data block may contain null bytes within it, and does not need to be terminated by a null byte at the end.
The alloc argument shows if/how this packet claims ownership of the data. In particular, unless alloc is DEEP_COPY, this packet will claim ownership of the given data block and will deallocate it when the packet is destroyed. If alloc is DEEP_COPY then the given block of data will not be modified in any way.
It is possible to pass a null pointer as the data array, in which case the new packet will have no attachment stored (so isNull() will return true
).
bytes
object. The size and alloc arguments are not present, since a bytes
object knows its size, and in Python the only available ownership policy is to make a deep copy.data | the block of binary data that forms the attachment, or null if no attachment is to be stored. |
size | the number of bytes in this block of binary data; if actual data is passed (i.e., data is not null ) then this must be strictly positive. |
alloc | describes if/how this packet should claim ownership of the given block of data; see the notes above for details. |
filename | the filename to associated with this attachment; typically this would be a filename only, with no directory prefixes. See filename() for details on how this string will be used. |
|
inline |
Creates a new deep copy of the given attachment.
Like all packet types, this only copies the content of the attachment, not the packet infrastructure (e.g., it will not copy the packet label, it will not clone the given packet's children, and it will not insert the new packet into any packet tree).
This is safe to call even if src does not contain a non-empty attachment (i.e., if src.isNull()
returns true
).
src | the attachment packet whose contents should be copied. |
|
inlineoverride |
Destroys this attachment packet and deallocates data if required.
|
inherited |
Returns a Python iterator over the packets in the subtree rooted at this packet.
Subtree iteration is depth-first, where a parent packet is always processed before its descendants. In particular, this packet (as the root of the subtree) will be processed first.
In Python, each packet can be treated as an iterable object, with the effect of iterating through the corresponding subtree:
Regina also supplies Python users with a member function Packet.subtree()
, which returns an iterable object. Iterating over Packet.subtree()
is exactly the same as iterating the packet itself; the subtree()
function is offered because the intention may be clearer for readers.
See also descendants() for iterating through just the strict descendants in the subtree (i.e., excluding this packet itself), and children() for iterating just through the immediate children of this packet (not the full subtree).
for
loop.
|
inlineprotectedvirtualinherited |
Records which other packets this packet refers to within the overall packet tree.
For each packet p that this packet refers to, this routine should insert the pair (p, false
) into the given map.
This will be run before writing the packet tree to an XML data file. By recording that this packet refers to some other packet p, this will ensure that the XML header for p will include an explicit ID that this packet can then refer to.
Later on, as the XML is written, the value refs[p]
will be changed from false
to true
once p has been written.
If your packet requires that the contents of p appear before this packet it the XML data file, then writeXMLPacketData() should check refs to see if p has already been written, and if not, it should write p in a new anonymous block.
It is fine if p does not actually belong to this packet tree. However, in this case writeXMLPacketData() must take responsibility to ensure that p is written to file. This would need to be done via writeXMLAnon(); moreover, as before, it should only be done only after checking refs to ensure this p has not already been written.
The default implementation of this routine does nothing.
refs | the map in which any dependencies should be recorded. |
Reimplemented in regina::PacketOf< Held >, and regina::Script.
|
inherited |
Associates the given tag with this packet.
Each packet can have an arbitrary set of string tags associated with it. The tags are not used by this calculation engine; the feature is provided for whatever use a developer or user chooses to make of it.
Tags are case-sensitive. Tags associated with a single packet must be distinct, i.e., a particular tag cannot be associated more than once with the same packet.
tag | the tag to add. |
true
if the given tag was successfully added, or false
if the given tag was already present beforehand.
|
inherited |
Returns the label of this packet adorned with the given string.
An adornment typically shows how a packet has been created and/or modified. For instance, the adornment argument might be "Filled", or "Summand #1".
The way in which the packet label is adorned depends upon the label itself (in particular, an empty packet label will be handled in a sensible way). The way in which the packet label is adorned is subject to change in future versions of Regina.
Note that, whilst this routine returns a modified version of the packet label, the label itself will not be permamently changed.
adornment | the string that will be used to adorn this packet label. The adornment should just be a piece of English, ideally beginning with an upper-case letter. It should not contain any surrounding punctuation such as brackets or a dash (this will be added automatically by this routine as required). |
|
inherited |
Inserts the given packet as the last child of this packet.
This packet will take ownership of child, in the sense that every parent packet stores (either directly or indirectly) a shared_ptr to every one of its descendants in the packet tree.
In Regina 7.0 and earlier, this routine was called insertChildLast().
This routine takes small constant time.
InvalidArgument | The argument child already has a parent packet. Note that, although this tests one of our preconditions, there are other preconditions that are not tested, and for which no exceptions are thrown. |
child | the child to insert. |
|
inlineinherited |
Returns a C++ non-const iterator at the beginning of the range of packets in the subtree rooted at this packet.
Subtree iteration is depth-first, where a parent packet is always processed before its descendants. In particular, the iterator returned by begin() will always point to this packet itself.
In C++, these begin() and end() routines allow you to iterate through an entire packet subtree using range-based for
loops:
Since Regina 7.0, the return type is templated in order to support both const and non-const iteration. It is recommended that you just use auto
if you need to store a local copy of the returned iterator.
See also descendants() for iterating through just the strict descendants in the subtree (i.e., excluding this packet itself), and children() for iterating just through the immediate children of this packet (not the full subtree).
|
inlineinherited |
Returns a C++ const iterator at the beginning of the range of packets in the subtree rooted at this packet.
Subtree iteration is depth-first, where a parent packet is always processed before its descendants. In particular, the iterator returned by begin() will always point to this packet itself.
In C++, these begin() and end() routines allow you to iterate through an entire packet subtree using range-based for
loops:
Since Regina 7.0, the return type is templated in order to support both const and non-const iteration. It is recommended that you just use auto
if you need to store a local copy of the returned iterator.
See also descendants() for iterating through just the strict descendants in the subtree (i.e., excluding this packet itself), and children() for iterating just through the immediate children of this packet (not the full subtree).
|
inlineinherited |
Returns a lightweight object for iterating through the immediate children of this packet.
This routine allows you to iterate through the immediate children of a given packet using range-based for
loops:
In Python, this routine returns an iterable object:
This function returns a lightweight object in the sense that it does not generate a full list of children in advance, but instead just returns a small iterator that visits each child as required. In particular, this routine has small constant time and memory.
Since Regina 7.0, the return type is templated in order to support both const and non-const iteration. It is recommended that you just use auto
if you need to store a local copy of the returned object.
See begin() and end(), as well as descendants(), for iterating through the subtree rooted at this packet (not just the immediate children).
|
inlineinherited |
Returns a lightweight object for iterating through the immediate children of this packet.
This routine allows you to iterate through the immediate children of a given packet using range-based for
loops:
This function returns a lightweight object in the sense that it does not generate a full list of children in advance, but instead just returns a small iterator that visits each child as required. In particular, this routine has small constant time and memory.
Since Regina 7.0, the return type is templated in order to support both const and non-const iteration. It is recommended that you just use auto
if you need to store a local copy of the returned object.
See begin() and end(), as well as descendants(), for iterating through the subtree rooted at this packet (not just the immediate children).
|
inherited |
Clones this packet (and possibly its descendants), assigns to it a suitable unused label and inserts the clone into the tree as a sibling of this packet.
Note that any string tags associated with this packet will not be cloned.
If this packet has no parent in the tree structure, no clone will be created and null
will be returned.
In Regina 6.0.1 and earlier, this function was called clone(). It was renamed in Regina 7.0 to emphasise that this is not just a deep copy, and is not guaranteed to succeed.
cloneDescendants | true if the descendants of this packet should also be cloned and inserted as descendants of the new packet. If this is passed as false (the default), only this packet will be cloned. |
end | true if the new packet should be inserted at the end of the parent's list of children (the default), or false if the new packet should be inserted as the sibling immediately after this packet. |
null
if this packet has no parent.
|
inherited |
Returns the number of immediate children of this packet.
Grandchildren and so on are not counted.
|
inlineinherited |
Returns the total number of strict descendants of this packet.
This includes children, grandchildren and so on. This packet is not included in the count.
|
inline |
Returns a pointer to the block of raw data that forms this attachment.
The number of bytes in this block can be found by calling size().
If this packet does not currently hold a non-empty attachment (i.e., if isNull() returns true
), then this routine will return null
.
bytes
object. Unlike the C++ version of this routine, the Python version returns a deep copy of the raw data (so this routine becomes slower, but the resulting byte sequence can be freely modified).
|
inlineinherited |
Returns a lightweight object for iterating through all strict descendants of this packet in the packet tree.
The order of iteration is exactly the same as when iterating over the full subtree rooted at this packet (as offered by Packet::begin() and Packet::end()), except that the iteration excludes this packet itself. In particular, the iteration is depth-first, and each packet in the subtree is processed before its own descendants.
This routine allows you to iterate through all strict descendants of a given packet using range-based for
loops:
In Python, this routine returns an iterable object:
This function returns a lightweight object in the sense that it does not generate a full list of descendants in advance, but instead just returns a small iterator that visits each descendant as required. In particular, this routine has small constant time and memory.
Since Regina 7.0, the return type is templated in order to support both const and non-const iteration. It is recommended that you just use auto
if you need to store a local copy of the returned object.
See also begin() and end() for iterating through the entire subtree including this packet, and children() for iterating over just this packet's immediate children.
|
inlineinherited |
Returns a lightweight object for iterating through all strict descendants of this packet in the packet tree.
The order of iteration is exactly the same as when iterating over the full subtree rooted at this packet (as offered by Packet::begin() and Packet::end()), except that the iteration excludes this packet itself. In particular, the iteration is depth-first, and each packet in the subtree is processed before its own descendants.
This routine allows you to iterate through all strict descendants of a given packet using range-based for
loops:
This function returns a lightweight object in the sense that it does not generate a full list of descendants in advance, but instead just returns a small iterator that visits each descendant as required. In particular, this routine has small constant time and memory.
Since Regina 7.0, the return type is templated in order to support both const and non-const iteration. It is recommended that you just use auto
if you need to store a local copy of the returned object.
See also begin() and end() for iterating through the entire subtree including this packet, and children() for iterating over just this packet's immediate children.
|
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 |
Returns a C++ non-const iterator beyond the end of the range of packets in the subtree rooted at this packet.
In C++, these begin() and end() routines allow you to iterate through an entire packet subtree using range-based for
loops.
See the begin() documentation for further details.
|
inlineinherited |
Returns a C++ const iterator beyond the end of the range of packets in the subtree rooted at this packet.
In C++, these begin() and end() routines allow you to iterate through an entire packet subtree using range-based for
loops.
See the begin() documentation for further details.
std::string regina::Attachment::extension | ( | ) | const |
Returns the extension of the filename associated with this attachment.
The user interface may use the result of filename() and/or extension() to determine which external viewer to launch when the user asks to view the attachment.
The extension will include the leading period. So, for example, if filename() returns "file.pdf", then extension() will return ".pdf".
If the associated filename has no extension, or if an error occurred when attempting to deduce it, then this routine will return the empty string.
|
inline |
Returns the filename associated with this attachment.
Typically this would be a filename only, with no path information.
The user interface may use the result of filename() and/or extension() to determine which external viewer to launch when the user asks to view the attachment.
There are no guarantees on the contents of this string, and user interfaces should treat it as a hint only (i.e., they may modify or even completely override it when saving the attachment as a local file). It is possible in some scenarios that this could be the empty string, or could be some other string that is not a valid filename on the current platform.
|
inherited |
Finds the packet with the requested label in the tree or subtree for which this packet is matriarch.
Note that label comparisons are case sensitive.
label | the label to search for. |
null
if there is no such packet.
|
inherited |
Finds the packet with the requested label in the tree or subtree for which this packet is matriarch.
Note that label comparisons are case sensitive.
label | the label to search for. |
null
if there is no such packet.
|
inlineinherited |
Determines the first child of this packet in the tree structure.
This routine takes small constant time.
null
if there is none.
|
inlineinherited |
Finds the first packet of the requested type in a complete depth-first iteration of the tree structure.
Note that this packet must be the matriarch of the entire tree.
A parent packet is always reached before its children. The tree matriarch will be the first packet visited in a complete depth-first iteration.
type | the type of packet to search for. |
null
if there are no packets of the requested type.
|
inlineinherited |
Finds the first packet of the requested type in a complete depth-first iteration of the tree structure.
Note that this packet must be the matriarch of the entire tree.
A parent packet is always reached before its children. The tree matriarch will be the first packet visited in a complete depth-first iteration.
type | the type of packet to search for. |
null
if there are no packets of the requested type.
|
inherited |
Returns a descriptive text string for the packet.
The string is of the form label (packet-type).
The packet label will be adjusted for human-readable output according to the behaviour of humanLabel().
|
inlineinherited |
Determines if this packet has a parent in the tree structure.
This is equivalent to, but slightly faster than, testing whether parent() returns a null pointer.
if
and only if this packet has a parent.
|
inlineinherited |
Determines whether this packet has the given associated tag.
Each packet can have an arbitrary set of string tags associated with it. The tags are not used by this calculation engine; the feature is provided for whatever use a developer or user chooses to make of it.
Tags are case-sensitive. Tags associated with a single packet must be distinct, i.e., a particular tag cannot be associated more than once with the same packet.
tag | the tag to search for. |
true
if the given tag is found, false
otherwise.
|
inlineinherited |
Determines whether this packet has any associated tags at all.
Each packet can have an arbitrary set of string tags associated with it. The tags are not used by this calculation engine; the feature is provided for whatever use a developer or user chooses to make of it.
Tags are case-sensitive. Tags associated with a single packet must be distinct, i.e., a particular tag cannot be associated more than once with the same packet.
true
if this packet has any tags, false
otherwise.
|
inlineinherited |
Returns the label associated with this individual packet, adjusted if necessary for human-readable output.
In particular, if the packet has no label assigned then this routine will return "(no label)", not the empty string.
|
inherited |
Inserts the given packet as a child of this packet at the given location in this packet's child list.
This packet will take ownership of child, in the sense that every parent packet stores (either directly or indirectly) a shared_ptr to every one of its descendants in the packet tree.
In Regina 7.0 and earlier, this routine was called insertChildAfter().
This routine takes small constant time.
InvalidArgument | The argument newChild already has a parent packet, and/or the argument prevChild is non-null and does not have this packet as its parent. Note that, although this tests some of our preconditions, there are other preconditions that are not tested, and for which no exceptions are thrown. |
newChild | the child to insert. |
prevChild | the preexisting child of this packet after which newChild will be inserted, or null if newChild is to be the first child of this packet. |
|
inlineinherited |
Deprecated routine that inserts the given packet as a child of this packet at the given location in this packet's child list.
InvalidArgument | The argument newChild already has a parent packet, and/or the argument prevChild is non-null and does not have this packet as its parent. Note that, although this tests some of our preconditions, there are other preconditions that are not tested, and for which no exceptions are thrown. |
newChild | the child to insert. |
prevChild | the preexisting child of this packet after which newChild will be inserted, or null if newChild is to be the first child of this packet. |
|
inlineinherited |
Deprecated routine that inserts the given packet as the first child of this packet.
InvalidArgument | The argument child already has a parent packet. Note that, although this tests one of our preconditions, there are other preconditions that are not tested, and for which no exceptions are thrown. |
child | the child to insert. |
|
inlineinherited |
Deprecated routine that inserts the given packet as the last child of this packet.
InvalidArgument | The argument child already has a parent packet. Note that, although this tests one of our preconditions, there are other preconditions that are not tested, and for which no exceptions are thrown. |
child | the child to insert. |
|
inlineoverrideprotectedvirtual |
Makes a new copy of this packet.
This routine should not insert the new packet into the tree structure, clone the packet's associated tags or give the packet a label. It should also not clone any descendants of this packet.
You may assume that the new packet will eventually be inserted into the tree beneath either the same parent as this packet or a clone of that parent.
Implements regina::Packet.
|
inherited |
Returns a unique string ID that identifies this packet.
The user has no control over this ID, and it is not human readable. It is guaranteed to remain fixed throughout the lifetime of the program for a given packet, and it is guaranteed not to clash with the ID of any other packet.
If you change the contents of a packet, its ID will not change.
If you clone a packet, the new clone will receive a different ID. If you save and then load a packet to/from file, the ID will change. These behaviours are necessary to ensure that IDs remain unique (since, for instance, you could load several copies of the same data file into memory simultaneously).
The ID is implemented as an encoding of the underlying C++ pointer. This encoding is subject to change in later versions of Regina.
|
inherited |
Determines if this packet is equal to or an ancestor of the given packet in the tree structure.
descendant | the other packet whose relationships we are examining. |
true
if and only if this packet is equal to or an ancestor of descendant
.
|
inlineinherited |
Determines whether the given packet listener is currently listening for events on this packet.
See the PacketListener class notes for details.
listener | the listener to search for. |
true
if the given listener is currently registered with this packet, or false
otherwise.
|
inline |
Determines whether this packet is currently holding a non-empty attachment.
true
if and only if this packet is holding a non-empty attachment.
|
inlineinherited |
Returns the label associated with this individual packet.
An example is MyTriangulation
.
|
inlineinherited |
Determines the last child of this packet in the tree structure.
This routine takes small constant time.
null
if there is none.
|
inherited |
Counts the number of levels between this packet and its given descendant in the tree structure.
If descendant
is this packet, the number of levels is zero.
descendant
, or can be obtained from descendant
using only child-to-parent steps.FailedPrecondition | The argument descendant is not equal to or a descendant of this packet. |
descendant | the packet whose relationship with this packet we are examining. |
|
inlineinherited |
Counts the number of levels between this packet and its given ancestor in the tree structure.
If ancestor
is this packet, the number of levels is zero.
ancestor
, or can be obtained from ancestor
using only parent-to-child steps.FailedPrecondition | This packet is not equal to or a descendant of the argument descendant. |
ancestor | the packet whose relationship with this packet we are examining. |
|
inherited |
Registers the given packet listener to listen for events on this packet.
See the PacketListener class notes for details.
listener | the listener to register. |
true
if the given listener was successfully registered, or false
if the given listener was already registered beforehand.
|
inherited |
Cuts this packet away from its parent in the tree structure and instead makes it the root of its own tree.
The tree information for both this packet and its parent will be updated.
The old parent will relinquish ownership of this packet. This means that, even if the old parent remains alive, once the last shared_ptr to this packet is destroyed then this packet itself will be destroyed also.
This makeOrphan() function is the preferred way to "delete" a packet p from a larger packet tree: simply orphan p and then dispose of any outstanding shared pointers to it (if you have any).
Even if you are not holding a shared_ptr to this packet yourself, this routine is still safe to use: it will keep an internal shared_ptr as a "guard" until makeOrphan() has completed its work, at which point the packet will be safely destroyed.
This routine takes small constant time. It is safe to use regardless of whether this packet currently has a parent or not.
|
inherited |
Moves this packet the given number of steps towards the end of its sibling list.
If the number of steps is larger than the greatest possible movement, the packet will be moved to the very end of its sibling list.
This routine takes time proportional to the number of steps.
steps | the number of steps down to move. |
|
inherited |
Moves this packet to be the first in its sibling list.
This routine takes small constant time.
|
inherited |
Moves this packet to be the last in its sibling list.
This routine takes small constant time.
|
inherited |
Moves this packet the given number of steps towards the beginning of its sibling list.
If the number of steps is larger than the greatest possible movement, the packet will be moved to the very beginning of its sibling list.
This routine takes time proportional to the number of steps.
steps | the number of steps up to move. |
|
inlineinherited |
Determines the next sibling of this packet in the tree structure.
This is the child of the parent that follows this packet.
This routine takes small constant time.
null
if there is none.
|
inherited |
Finds the next packet after this in a complete depth-first iteration of the entire tree structure to which this packet belongs.
Note that this packet need not be the tree matriarch.
A parent packet is always reached before its children. The tree matriarch will be the first packet visited in a complete depth-first iteration.
null
if this is the last packet in such an iteration.
|
inherited |
Finds the next packet after this in a complete depth-first iteration of the entire tree structure to which this packet belongs.
Note that this packet need not be the tree matriarch.
A parent packet is always reached before its children. The tree matriarch will be the first packet visited in a complete depth-first iteration.
null
if this is the last packet in such an iteration.
|
inlineinherited |
Finds the next packet after this of the requested type in a complete depth-first iteration of the entire tree structure.
Note that this packet need not be the tree matriarch. The order of tree searching is described in firstTreePacket().
type | the type of packet to search for. |
null
if this is the last packet of the requested type in such an iteration.
|
inlineinherited |
Finds the next packet after this of the requested type in a complete depth-first iteration of the entire tree structure.
Note that this packet need not be the tree matriarch. The order of tree searching is described in firstTreePacket().
type | the type of packet to search for. |
null
if this is the last packet of the requested type in such an iteration.
|
inline |
Determines if this and the given attachment hold different data.
The filenames will not be compared.
It is safe to call this operator if one or both attachments is empty (i.e., isNull() returns true
), in which case an empty attachment will compare as equal to any other empty attachment.
other | the attachment to compare with this. |
true
if and only if this and the given attachment contain different data.
|
inline |
Sets this to be a deep copy of the given attachment.
Like all packet types, this only copies the content of the attachment, not the packet infrastructure (e.g., it will not copy the packet label, or change this packet's location in any packet tree).
This is safe to call even if src does not contain a non-empty attachment (i.e., if src.isNull()
returns true
).
src | the attachment packet whose contents should be copied. |
|
inline |
Determines if this and the given attachment hold identical data.
The filenames will not be compared.
It is safe to call this operator if one or both attachments is empty (i.e., isNull() returns true
), in which case an empty attachment will compare as equal to any other empty attachment.
other | the attachment to compare with this. |
true
if and only if this and the given attachment contain identical data.
|
inlineinherited |
Determines the parent packet in the tree structure.
This routine takes small constant time.
null
if there is none.
|
inherited |
Inserts the given packet as the first child of this packet.
This packet will take ownership of child, in the sense that every parent packet stores (either directly or indirectly) a shared_ptr to every one of its descendants in the packet tree.
In Regina 7.0 and earlier, this routine was called insertChildFirst().
This routine takes small constant time.
InvalidArgument | The argument child already has a parent packet. Note that, although this tests one of our preconditions, there are other preconditions that are not tested, and for which no exceptions are thrown. |
child | the child to insert. |
|
inlineinherited |
Determines the previous sibling of this packet in the tree structure.
This is the child of the parent that precedes this packet.
This routine takes small constant time.
null
if there is none.
|
inherited |
Removes all associated tags from this packet.
Each packet can have an arbitrary set of string tags associated with it. The tags are not used by this calculation engine; the feature is provided for whatever use a developer or user chooses to make of it.
Tags are case-sensitive. Tags associated with a single packet must be distinct, i.e., a particular tag cannot be associated more than once with the same packet.
|
inherited |
Removes the association of the given tag with this packet.
Each packet can have an arbitrary set of string tags associated with it. The tags are not used by this calculation engine; the feature is provided for whatever use a developer or user chooses to make of it.
Tags are case-sensitive. Tags associated with a single packet must be distinct, i.e., a particular tag cannot be associated more than once with the same packet.
tag | the tag to remove. |
true
if the given tag was removed, or false
if the given tag was not actually associated with this packet.
|
inherited |
Cuts this packet away from its parent in the tree structure, and inserts it as a child of the given packet instead.
This routine is essentially a combination of makeOrphan() followed by either prepend() or append().
Even if you are not holding a shared_ptr to this packet yourself, this routine is still safe to use: it will maintain a shared_ptr as a "guard" so that this packet is not inadvertently destroyed during the transfer.
You may pass newParent as null
, in which case this routine behaves in the same way as makeOrphan() (and is similarly safe to use even if there are no other shared pointers to this packet).
This routine takes small constant time. It is safe to use regardless of whether this packet currently has a parent or not.
If you wish to reparent all of the children of a given packet, see transferChildren() instead.
newParent | the new parent of this packet, i.e., the packet beneath which this packet will be inserted. |
first | true if this packet should be inserted as the first child of the given parent, or false (the default) if it should be inserted as the last child. |
void regina::Attachment::reset | ( | ) |
Empties this packet so that no attachment is stored.
After calling this routine, isNull() will return true
.
The old data will be deallocated if required.
void regina::Attachment::reset | ( | char * | data, |
size_t | size, | ||
OwnershipPolicy | alloc, | ||
std::string | filename | ||
) |
Refills this attachment packet with the given binary data.
The old data will be deallocated if required.
This routine behaves like the class constructor; see the constructor documentation for details.
bytes
object. The size and alloc arguments are not present, since a bytes
object knows its size, and in Python the only available ownership policy is to make a deep copy.data | the block of binary data that forms the new attachment, or null if no attachment is to be stored. |
size | the number of bytes in this new block of binary data; if actual data is passed (i.e., data is not null ) then this must be strictly positive. |
alloc | describes if/how this packet should claim ownership of the given block of data; see the notes above for details. |
filename | the new filename to associated with this attachment; this will override the previously stored filename. Typically this would be a filename only, with no directory prefixes. See filename() for details on how this string will be used. |
|
inherited |
Determines the root of the tree to which this packet belongs.
|
inlineinherited |
Determines whether this and the given object refer to the same packet.
This is exactly the same as testing whether the underlying Packet pointers are equal, and so this routine is unnecessary for C++ users.
Instead, this routine is designed for Python users, since:
is
will not work, because there could be many different Python wrappers all pointing to the same C++ object;A use case for this function could be (for example) iterating through a packet tree and identifying when a particular known packet has been found.
other | the packet to compare with this. |
true
if and only if this and the given object refer to the same underlying packet.
|
inherited |
Saves the subtree rooted at this packet to the given Regina data file, using Regina's native XML file format.
The XML file may be optionally compressed (Regina can happily read both compressed and uncompressed XML).
This is the preferred way of saving a Regina data file. Typically this will be called from the root of the packet tree, which will save the entire packet tree to file.
filename | the pathname of the file to write to. |
compressed | true if the XML data should be compressed, or false if it should be written as plain text. |
format | indicates which of Regina's XML file formats to write. You should use the default (REGINA_CURRENT_FILE_FORMAT) unless you need your file to be readable by older versions of Regina. This must not be REGINA_BINARY_GEN_1, which is no longer supported. |
true
if and only if the file was successfully written. bool regina::Attachment::save | ( | const char * | pathname | ) | const |
Saves the contents of this attachment to the given file.
If this packet does not currently hold a non-empty attachment (i.e., if isNull() returns true
), then this routine will do nothing and simply return false
.
pathname | the full pathname of the file to write. |
true
if the file was successfully written, or false
otherwise.
|
inherited |
Writes the subtree rooted at this packet to the given output stream, in the format of a Regina XML data file.
The data file may be optionally compressed (Regina can happily read both compressed and uncompressed XML).
Typically this will be called from the root of the packet tree, which will write the entire packet tree to the given output stream.
s | the output stream to which to write. |
compressed | true if the XML data should be compressed, or false if it should be written as plain text. |
format | indicates which of Regina's XML file formats to write. You should use the default (REGINA_CURRENT_FILE_FORMAT) unless you need your file to be readable by older versions of Regina. This must not be REGINA_BINARY_GEN_1, which is no longer supported. |
true
if and only if the data was successfully written.
|
inherited |
Sets the label associated with this individual packet.
label | the new label to give this packet. |
|
inline |
Returns the size of this attachment in bytes.
If this packet does not currently hold a non-empty attachment (i.e., if isNull() returns true
), then this routine will return zero.
|
inherited |
Sorts the immediate children of this packet according to their packet labels.
Note that this routine is not recursive (for instance, grandchildren will not be sorted within each child packet).
This routine takes quadratic time in the number of immediate children (and it's slow quadratic at that).
|
inherited |
Returns a short text representation of this object.
This text should be human-readable, should use plain ASCII characters where possible, and should not contain any newlines.
Within these limits, this short text ouptut should be as information-rich as possible, since in most cases this forms the basis for the Python __str__()
and __repr__()
functions.
__str__()
will use precisely this function, and for most classes the Python __repr__()
function will incorporate this into its output.
|
inline |
Swaps the contents of this and the given attachment.
Like all packet types, this only swaps the content of the attachments, not the packet infrastructure (e.g., it will not swap packet labels, or change either packet's location in any packet tree).
This is safe to call even if this packet and/or other does not contain a non-empty attachment (i.e., if isNull() returns true
).
other | the attachment packet whose contents should be swapped with this. |
|
inherited |
Swaps this packet with its next sibling in the sequence of children beneath their common parent packet.
Calling this routine is equivalent to calling moveDown().
This routine takes small constant time.
If this packet has no next sibling then this routine safely does nothing.
|
inlineinherited |
Returns the set of all tags associated with this packet.
Each packet can have an arbitrary set of string tags associated with it. The tags are not used by this calculation engine; the feature is provided for whatever use a developer or user chooses to make of it.
Tags are case-sensitive. Tags associated with a single packet must be distinct, i.e., a particular tag cannot be associated more than once with the same packet.
|
inherited |
Determines the total number of packets in the tree or subtree for which this packet is matriarch.
This packet is included in the count.
|
inherited |
Cuts all of this packet's children out of the packet tree, and reinserts them as children of the given packet instead.
The children of this packet will be appended to the end of the new parent's child list, in the same order as they were previously.
This is equivalent to calling reparent() on each child, but should be somewhat faster if there are many children to move.
Even if you are not holding a shared_ptr to any of this packet's children, this routine is still safe to use: it will ensure there is always some shared_ptr to guard against any children being inadvertently destroyed during the transfer.
You may pass newParent as null
, in which case this routine is equivalent to calling makeOrphan() on each child (and is similarly safe to use even if there are no other shared pointers to this packet).
newParent | the new parent beneath which the children will be inserted. |
|
pure virtualinherited |
Returns the unique integer ID representing this type of packet.
This is the same for all packets of this class.
|
pure virtualinherited |
Returns an English name for this type of packet.
An example is Triangulation3
. This is the same for all packets of this class.
|
inherited |
Unregisters the given packet listener so that it no longer listens for events on this packet.
See the PacketListener class notes for details.
listener | the listener to unregister. |
true
if the given listener was successfully unregistered, or false
if the given listener was not registered in the first place.
|
inherited |
Returns a short text representation of this object using unicode characters.
Like str(), this text should be human-readable, should not contain any newlines, and (within these constraints) should be as information-rich as is reasonable.
Unlike str(), this function may use unicode characters to make the output more pleasant to read. The string that is returned will be encoded in UTF-8.
|
inlinevirtualinherited |
Writes a detailed text representation of this object to the given output stream.
This may be reimplemented by subclasses, but the parent Packet class offers a reasonable default implementation.
out | the output stream to which to write. |
Reimplemented in regina::PacketOf< Held >, regina::Script, and regina::Text.
|
inlineoverridevirtual |
Writes a short text representation of this object to the given output stream.
This must be reimplemented by subclasses.
out | the output stream to which to write. |
Implements regina::Packet.
|
protectedinherited |
Writes the given packet inside its own anonymous block.
This could (for example) be called as the first step in writeXMLPacketData() if the packet needs some dependency p to have been explicitly written to file and this has not been done yet.
This function simply creates an anon
XML block, and within it calls p.writeXMLPacketData()
with the anon argument set to true
.
out | the output stream to which the anonymous block should be written. |
format | indicates which of Regina's XML file formats to write. |
refs | manages the necessary references between packets in the XML file; see the PacketRefs documentation for details. |
p | the packet to write inside the anonymous block. |
|
inherited |
Writes the subtree rooted at this packet to the given output stream in Regina's native XML file format.
Ths is similar to calling save(), except that (i) the user has a more flexible choice of output stream, and (ii) the XML will always be written in plain text (i.e., it will not be compressed).
If you simply wish to save your data to a file on the filesystem, you should call save() instead.
Typically this will be called from the root of the packet tree, which will write the entire packet tree to the output stream.
out | the output stream to which the XML data file should be written. |
format | indicates which of Regina's XML file formats to write. You should use the default (REGINA_CURRENT_FILE_FORMAT) unless you need your file to be readable by older versions of Regina. This must not be REGINA_BINARY_GEN_1, which is no longer supported. |
|
protectedinherited |
Writes the closing XML tag for this packet.
This is typically called at the end of writeXMLPacketData().
There will be no whitespace before the closing XML tag. The tag will be followed by a newline.
out | the output stream to which the closing XML tag should be written. |
element | the name of the XML tag. If we are writing to the REGINA_XML_GEN_2 format, then this will be ignored (and may be null ), and the tag name packet will be used instead. |
format | indicates which of Regina's XML file formats to write. |
|
protectedinherited |
Writes the opening XML tag for this packet.
This is typically called at the beginning of writeXMLPacketData().
The generic packet attributes (such as label
, id
if required, and type
/ typeid
if we are writing to the second-generation format REGINA_XML_GEN_2) will be included.
If we are writing to the third-generation file format or newer, then any additional attributes specified in attr will also be included. If we are writing to the second-generation format REGINA_XML_GEN_2, then attr will be ignored.
If this packet appears as a key in the refs map, or if the anon argument indicates that we are in an anonymous block, then this routine will set refs[this]
as true
to record that this packet is now being written to XML.
out | the output stream to which the opening XML tag should be written. |
element | the name of the XML tag. If we are writing to the REGINA_XML_GEN_2 format, then this will be ignored (and may be null ), and the tag name packet will be used instead. |
format | indicates which of Regina's XML file formats to write. |
anon | true if this packet is being written within an anonymous block. If so, then the packet ID will always be written. |
refs | manages the necessary references between packets in the XML file; see the PacketRefs documentation for details. |
newline | indicates whether the opening XML tag should be followed by a newline. Normally this would be true , but if you need to avoid whitespace between the opening XML tag and the packet contents then you should pass false instead. |
attr | any additional attributes to write to the XML tag; each attribute should a pair of the form (attribute, value). When writing to the REGINA_XML_GEN_2 format, this will be ignored. |
|
overrideprotectedvirtual |
Writes a chunk of XML containing the full subtree with this packet as matriarch.
This should contain:
For native packet types, these five stages are typically implemented using:
false
;For wrapped packet types that use a PacketOf<Held> wrapper, you should instead just specialise the routines from XMLWriter<Held>. The PacketOf wrapper will take care of the tree-specific code (in particular, it will handle the calls to writeXMLAnon() and writeXMLTreeData()).
The output from this routine is only a piece of XML; it should not be used as a complete XML file. For a complete XML file, see routine writeXMLFile() instead.
out | the output stream to which the XML should be written. |
format | indicates which of Regina's XML file formats to write. |
anon | true if this packet is being written within an anonymous block. If so, then the packet ID must be included, and any packet tags and/or child packets must be excluded. |
refs | manages the necessary references between packets in the XML file; see the PacketRefs documentation for details. |
Implements regina::Packet.
|
protectedinherited |
Writes any generic XML sub-elements for this packet that come from the packet tree.
This is typically called towards the end of writeXMLPacketData(), just before the final call to writeXMLFooter().
The generic sub-elements include Regina's packet tags, as well as any child packets in the packet tree.
There will be no whitespace before the first sub-element (and so if there are no sub-elements at all then this routine will output nothing).
out | the output stream to which the closing XML tag should be written. |
format | indicates which of Regina's XML file formats to write. |
refs | manages the necessary references between packets in the XML file; see the PacketRefs documentation for details. |