Regina 7.3 Calculation Engine
|
A packet representing a Python script that can be run. More...
#include <packet/script.h>
Public Member Functions | |
Script ()=default | |
Initialises to a script with no text and no variables. More... | |
Script (const Script &)=default | |
Creates a new copy of the given script packet. More... | |
Script & | operator= (const Script &src) |
Sets this to be a copy of the given script packet. More... | |
void | swap (Script &other) |
Swaps the contents of this and the given script packet. More... | |
const std::string & | text () const |
Returns the complete text of this script. More... | |
void | setText (const std::string &newText) |
Replaces the complete text of this script with the given string. More... | |
void | append (const std::string &extraText) |
Adds the given text to the end of this script. More... | |
size_t | countVariables () const |
Returns the number of variables associated with this script. More... | |
const std::string & | variableName (size_t index) const |
Returns the name of the requested variable associated with this script. More... | |
long | variableIndex (const std::string &name) const |
Returns the index of the variable stored with the given name. More... | |
std::shared_ptr< Packet > | variableValue (size_t index) const |
Returns the value of the requested variable associated with this script. More... | |
std::shared_ptr< Packet > | variableValue (const std::string &name) const |
Returns the value of the variable stored with the given name. More... | |
void | setVariableName (size_t index, const std::string &name) |
Changes the name of an existing variable associated with this script. More... | |
void | setVariableValue (size_t index, std::weak_ptr< Packet > value={}) |
Changes the value of an existing variable associated with this script. More... | |
bool | addVariable (const std::string &name, std::weak_ptr< Packet > value={}) |
Attempts to add a new variable to be associated with this script. More... | |
const std::string & | addVariableName (const std::string &name, std::weak_ptr< Packet > value={}) |
Adds a new variable to be associated with this script, changing its name if necessary. More... | |
void | removeVariable (const std::string &name) |
Removes the variable stored with the given name. More... | |
void | removeVariable (size_t index) |
Removes the variable stored at the given index. More... | |
void | removeAllVariables () |
Removes all variables associated with this script. More... | |
void | listenVariables (PacketListener *listener) |
Registers the given packet listener to listen for events on all of packets identified by this script's variables. More... | |
void | unlistenVariables (PacketListener *listener) |
Deregisters the given packet listener from listening for events on all of packets identified by this script's variables. More... | |
bool | operator== (const Script &other) const |
Determines if this and the given script are identical. More... | |
bool | operator!= (const Script &other) const |
Determines if this and the given script are not identical. More... | |
void | writeTextShort (std::ostream &out) const override |
Writes a short text representation of this object to the given output stream. More... | |
void | writeTextLong (std::ostream &out) const override |
Writes a detailed 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... | |
void | addPacketRefs (PacketRefs &refs) const override |
Records which other packets this packet refers to within the overall packet tree. 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... | |
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... | |
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 representing a Python script that can be run.
A script consists of two parts: (i) the text, which contains the Python code; and (ii) a set of variables, which refer to packets in your packet tree. When running a script, the variables should be instantiated in the default namespace before the script is run.
The way variables are stored has changed as of Regina 7.0:
This means that:
For historical reference, the previous behaviour was:
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).
|
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.
|
default |
Initialises to a script with no text and no variables.
|
default |
Creates a new copy of the given script packet.
Like all packet types, this only copies the script content, 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).
|
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.
|
inlineoverrideprotectedvirtual |
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 from regina::Packet.
|
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.
|
inline |
Attempts to add a new variable to be associated with this script.
If a variable with the given name is already stored, this routine will do nothing.
If you need to ensure that a new variable is always added, even if the variable name needs to change, see the routine addVariableName() instead.
name | the name of the new variable. |
value | the value of the new variable. This is allowed to be a null pointer, and if the argument is omitted then a null pointer will be used. |
true
if the variable was successfully added, or false
if a variable with the given name was already stored. const std::string & regina::Script::addVariableName | ( | const std::string & | name, |
std::weak_ptr< Packet > | value = {} |
||
) |
Adds a new variable to be associated with this script, changing its name if necessary.
If the given variable name does not already exist as a variable name in this script, then it will be used without modification. Otherwise a new variable name will be constructed by appending additional characters to name.
name | the string upon which the new variable name will be based. |
value | the value of the new variable. This is allowed to be a null pointer, and if the argument is omitted then a null pointer will be used. |
|
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). |
|
inline |
Adds the given text to the end of this script.
extraText | the text to add. |
|
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 the number of variables associated with this script.
|
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.
|
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. |
|
overrideprotectedvirtual |
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.
|
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.
|
inline |
Registers the given packet listener to listen for events on all of packets identified by this script's variables.
This is a one-off operation: if the script variables should change later on, the given listener will not be registered and/or deregistered to reflect the new variable values.
This routine is safe to call if some variables have null values, and/or if the same packet is identified by multiple variables.
listener | the listener to register with all packets identified by the script variables. |
|
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 script are not identical.
Here identical means that both scripts contain exactly the same text, and they have the same set of variables. For two variables to be considered the same, they must have the same variable name, and their values must be either both null
or both pointers to the same packet.
other | the script to compare with this. |
true
if and only if this and the given script are not identical. Sets this to be a copy of the given script packet.
Like all packet types, this only copies the script content, not the packet infrastructure (e.g., it will not copy the packet label, or change this packet's location in any packet tree).
src | the script packet whose contents should be copied. |
bool regina::Script::operator== | ( | const Script & | other | ) | const |
Determines if this and the given script are identical.
Here identical means that both scripts contain exactly the same text, and they have the same set of variables. For two variables to be considered the same, they must have the same variable name, and their values must be either both null
or both pointers to the same packet.
other | the script to compare with this. |
true
if and only if this and the given script are identical.
|
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.
|
inline |
Removes all variables associated with this script.
|
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. void regina::Script::removeVariable | ( | const std::string & | name | ) |
Removes the variable stored with the given name.
If no variable is stored with the given name, this routine will do nothing.
name | the name of the variable to remove; note that names are case sensitive. |
void regina::Script::removeVariable | ( | size_t | index | ) |
Removes the variable stored at the given index.
index | the index of the variable to remove; this must be between 0 and countVariables()-1 inclusive. |
|
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. |
|
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.
|
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 |
Replaces the complete text of this script with the given string.
Variables are not considered part of the text; you can get and set them through other member functions (see below).
newText | the new text for this script. |
void regina::Script::setVariableName | ( | size_t | index, |
const std::string & | name | ||
) |
Changes the name of an existing variable associated with this script.
index | the index of the variable whose name should change; this must be between 0 and countVariables()-1 inclusive. |
name | the new name to assign to the variable. |
void regina::Script::setVariableValue | ( | size_t | index, |
std::weak_ptr< Packet > | value = {} |
||
) |
Changes the value of an existing variable associated with this script.
index | the index of the variable whose value should change; this must be between 0 and countVariables()-1 inclusive. |
value | the new value to assign to the variable. This is allowed to be a null pointer, and if the argument is omitted then a null pointer will be used. |
|
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.void regina::Script::swap | ( | Script & | other | ) |
Swaps the contents of this and the given script packet.
Like all packet types, this only swaps the script content, not the packet infrastructure (e.g., it will not swap packet labels, or change either packet's location in any packet tree).
other | the script 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.
|
inline |
Returns the complete text of this script.
Variables are not considered part of the text; you can get and set them through other member functions (see below).
|
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.
|
inline |
Deregisters the given packet listener from listening for events on all of packets identified by this script's variables.
Like listenVariables(), this is a one-off operation: it will not make any further adjustments if the script variables should change later on.
This routine is safe to call if some variables have null values, and/or if the same packet is identified by multiple variables.
listener | the listener to deregister from all packets identified by the script variables. |
|
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.
long regina::Script::variableIndex | ( | const std::string & | name | ) | const |
Returns the index of the variable stored with the given name.
name | the name of the requested variable; note that names are case sensitive. |
const std::string & regina::Script::variableName | ( | size_t | index | ) | const |
Returns the name of the requested variable associated with this script.
index | the index of the requested variable; this must be between 0 and countVariables()-1 inclusive. |
std::shared_ptr< Packet > regina::Script::variableValue | ( | const std::string & | name | ) | const |
Returns the value of the variable stored with the given name.
Variables may take the value null
.
If no variable is stored with the given name, then null
will likewise be returned.
name | the name of the requested variable; note that names are case sensitive. |
std::shared_ptr< Packet > regina::Script::variableValue | ( | size_t | index | ) | const |
Returns the value of the requested variable associated with this script.
Variables may take the value null
.
index | the index of the requested variable; this must be between 0 and countVariables()-1 inclusive. |
|
overridevirtual |
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 from regina::Packet.
|
overridevirtual |
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. |