Regina Calculation Engine
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
regina::Script Class Referenceabstract

A packet representing a Python script that can be run. More...

#include <packet/script.h>

Inheritance diagram for regina::Script:
regina::Packet regina::PacketListener regina::Output< Packet > regina::SafePointeeBase< Packet >

Public Types

typedef Packet SafePointeeType
 The type of object being pointed to. More...
 

Public Member Functions

 Script ()
 Initialises to a script with no text and no variables. 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...
 
PacketvariableValue (size_t index) const
 Returns the value of the requested variable associated with this script. More...
 
PacketvariableValue (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, Packet *value)
 Changes the value of an existing variable associated with this script. More...
 
bool addVariable (const std::string &name, Packet *value)
 Attempts to add a new variable to be associated with this script. More...
 
const std::string & addVariableName (const std::string &name, 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...
 
virtual void writeTextShort (std::ostream &out) const override
 Writes a short text representation of this object to the given output stream. More...
 
virtual void writeTextLong (std::ostream &out) const override
 Writes a detailed text representation of this object to the given output stream. More...
 
virtual bool dependsOnParent () const override
 Determines if this packet depends upon its parent. More...
 
virtual void packetWasRenamed (Packet *packet) override
 Called after the packet label or tags have been changed. More...
 
virtual void packetToBeDestroyed (PacketShell packet) override
 Called before the packet is about to be destroyed. 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...
 
bool hasSafePtr () const
 Is there one or more SafePtr currently pointing to this object? More...
 

Static Public Member Functions

static XMLPacketReaderxmlReader (Packet *parent, XMLTreeResolver &resolver)
 

Protected Member Functions

virtual PacketinternalClonePacket (Packet *parent) const override
 Makes a newly allocated copy of this packet. More...
 
virtual void writeXMLPacketData (std::ostream &out) const override
 Writes a chunk of XML containing the data for this packet only. More...
 

File I/O

bool save (const char *filename, bool compressed=true) const
 Saves the subtree rooted at this packet to the given Regina data file, using Regina's native XML file format. More...
 
bool save (std::ostream &s, bool compressed=true) const
 Writes the subtree rooted at this packet to the given output stream, in the format of a Regina XML data file. More...
 
void writeXMLFile (std::ostream &out) const
 Writes the subtree rooted at this packet to the given output stream in Regina's native XML file format. More...
 
std::string internalID () const
 Returns a unique string ID that identifies this packet. More...
 
bool hasOwner () const
 Indicates whether some other object in the calculation engine is responsible for ultimately destroying this object. More...
 
void writeXMLPacketTree (std::ostream &out) const
 Writes a chunk of XML containing the subtree with this packet as matriarch. More...
 

Packet Listener Interface

void unregisterFromAllPackets ()
 Unregisters this listener from any packets to which it is currently listening. More...
 
virtual void packetToBeChanged (Packet *packet)
 Called before the contents of the packet are to be changed. More...
 
virtual void packetWasChanged (Packet *packet)
 Called after the contents of the packet have been changed. More...
 
virtual void packetToBeRenamed (Packet *packet)
 Called before the packet label or tags are to be changed. More...
 
virtual void childToBeAdded (Packet *packet, Packet *child)
 Called before a child packet is to be inserted directly beneath the packet. More...
 
virtual void childWasAdded (Packet *packet, Packet *child)
 Called after a child packet has been inserted directly beneath the packet. More...
 
virtual void childToBeRemoved (Packet *packet, Packet *child)
 Called before a child packet is to be removed from directly beneath the packet. More...
 
virtual void childWasRemoved (Packet *packet, Packet *child)
 Called after a child packet has been removed from directly beneath the packet. More...
 
virtual void childrenToBeReordered (Packet *packet)
 Called before the child packets directly beneath the packet are to be reordered. More...
 
virtual void childrenWereReordered (Packet *packet)
 Called after the child packets directly beneath the packet have been reordered. More...
 
virtual void childToBeRenamed (Packet *packet, Packet *child)
 Called before one of this packet's immediate children has its label or tags changed. More...
 
virtual void childWasRenamed (Packet *packet, Packet *child)
 Called after one of this packet's immediate children has its label or tags changed. More...
 

Detailed Description

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 values of variables are given by pointers to packets (not packet labels, as in some old versions of Regina). This affects how variables react to changes in the packets that they point to. In particular, if a variable V points to some packet P, then:

Member Typedef Documentation

◆ SafePointeeType

The type of object being pointed to.

Member Function Documentation

◆ detail()

std::string regina::Output< Packet , false >::detail ( ) const
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.

Returns
a detailed text representation of this object.

◆ hasSafePtr()

bool regina::SafePointeeBase< Packet >::hasSafePtr
inlineinherited

Is there one or more SafePtr currently pointing to this object?

◆ str()

std::string regina::Output< Packet , false >::str ( ) const
inherited

Returns a short text representation of this object.

This text should be human-readable, should fit on a single line, and should not end with a newline. Where possible, it should use plain ASCII characters.

Python:\n In addition to str(), this is also used as the
Python "stringification" function __str__().
Returns
a short text representation of this object.

◆ utf8()

std::string regina::Output< Packet , false >::utf8 ( ) const
inherited

Returns a short text representation of this object using unicode characters.

Like str(), this text should be human-readable, should fit on a single line, and should not end with a newline. In addition, it may use unicode characters to make the output more pleasant to read. This string will be encoded in UTF-8.

Returns
a short text representation of this object.

The documentation for this class was generated from the following file:

Copyright © 1999-2018, The Regina development team
This software is released under the GNU General Public License, with some additional permissions; see the source code for details.
For further information, or to submit a bug or other problem, please contact Ben Burton (bab@maths.uq.edu.au).