A lightweight object that gives access to all immediate children of a given packet.
More...
|
| PacketChildren (const PacketChildren &)=default |
| Creates a new object for iterating through the children of the same packet as the given object.
|
|
| PacketChildren (std::shared_ptr< packet_type > parent) |
| Creates a new object for iterating through the immediate children of the given packet.
|
|
PacketChildren & | operator= (const PacketChildren &)=default |
| Sets this object to iterate over the children of the same packet as the given object.
|
|
ChildIterator< const_ > | begin () const |
| Returns a C++ iterator pointing to the first immediate child packet.
|
|
ChildIterator< const_ > | end () const |
| Returns a C++ iterator pointing beyond the last immediate child packet.
|
|
auto | __iter__ () const |
| Returns a Python iterator over all immediate child packets.
|
|
bool | operator== (const PacketChildren &rhs) const |
| Determines whether this and the given object are designed to iterate over children of the same parent packet.
|
|
bool | operator!= (const PacketChildren &rhs) const |
| Determines whether this and the given object are designed to iterate over children of different parent packets.
|
|
template<bool const_>
class regina::PacketChildren< const_ >
A lightweight object that gives access to all immediate children of a given packet.
The purpose of this class is to support iteration through all children of a packet p using range-based for
loops:
std::shared_ptr<Packet> parent = ...;
for (
Packet& child : parent->children()) { ... }
Represents a packet of information that may be individually edited or operated upon.
Definition packet.h:219
In Python, PacketChildren is an iterable object:
parent = ...
for child in parent.children():
...
Each object of this class will hold a std::shared_ptr to the packet whose children 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 PacketChildren will iterate over the children of the same underlying packet.
- Template Parameters
-
const_ | Indicates whether this iterator should offer const or non-const access to the child packets. |
- Python
- Instead of the C++ interface described here, in Python the classes PacketChildren and ChildIterator together implement the Python iterable/iterator interface. The class PacketChildren has just the single function
__iter__()
, which returns a ChildIterator; then ChildIterator implements __next__()
, which either returns the next child 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
).