A lightweight object that gives access to all strict descendants of a given packet.
More...
|
| PacketDescendants (const PacketDescendants &)=default |
| Creates a new object for iterating through the strict descendants of the same packet as the given object.
|
|
| PacketDescendants (std::shared_ptr< packet_type > subtree) |
| Creates a new object for iterating through the strict descendants of the given packet.
|
|
PacketDescendants & | operator= (const PacketDescendants &)=default |
| Sets this object to iterate over the strict descendants of the same packet as the given object.
|
|
SubtreeIterator< const_ > | begin () const |
| Returns a C++ iterator at the beginning of the range of strict descendant packets.
|
|
SubtreeIterator< const_ > | end () const |
| Returns a C++ iterator at the end of the range of strict descendant packets.
|
|
auto | __iter__ () const |
| Returns a Python iterator over all strict descendant packets.
|
|
bool | operator== (const PacketDescendants &rhs) const |
| Determines whether this and the given object are designed to iterate over strict descendants of the same packet.
|
|
bool | operator!= (const PacketDescendants &rhs) const |
| Determines whether this and the given object are designed to iterate over strict descendants of different packets.
|
|
template<bool const_>
class regina::PacketDescendants< const_ >
A lightweight object that gives access to all strict descendants of a given packet.
The purpose of this class is to support iteration through all strict descendants of a packet p using range-based for
loops:
std::shared_ptr<Packet> parent = ...;
for (
Packet& desc : parent->descendants()) { ... }
Represents a packet of information that may be individually edited or operated upon.
Definition packet.h:219
In Python, PacketDescendants is an iterable object:
parent = ...
for desc in parent.descendants():
...
Each object of this class will hold a std::shared_ptr to the packet whose descendants it gives access to. This guarantees that the packet will not be destroyed during iteration, but it also means that you must ensure that you dispose of these objects once you are finished with them.
These are lightweight objects, small enough to pass by value and swap with std::swap(), with no need for any specialised move operations or swap functions. Copies of a PacketDescendants will iterate over the descendants of the same underlying packet.
- Template Parameters
-
const_ | Indicates whether this iterator should offer const or non-const access to the packet tree. |
- Python
- Instead of the C++ interface described here, in Python the classes PacketDescendants and SubtreeIterator together implement the Python iterable/iterator interface. The class PacketDescendants has just the single function
__iter__()
, which returns a SubtreeIterator; then SubtreeIterator implements __next__()
, which either returns the next descendant packet in the iteration or else throws a StopException
if there are no more children to return. All iteration in Python is non-const (i.e., Python exclusively uses the classes where const_ is false
).