Regina 7.3 Calculation Engine
Public Types | Public Member Functions | List of all members
regina::PacketDescendants< const_ > Class Template Reference

A lightweight object that gives access to all strict descendants of a given packet. More...

#include <packet/packet.h>

Public Types

using packet_type = std::conditional_t< const_, const Packet, Packet >
 Either Packet or const Packet, according to the template argument const_. More...
 

Public Member Functions

 PacketDescendants (const PacketDescendants &)=default
 Creates a new object for iterating through the strict descendants of the same packet as the given object. More...
 
 PacketDescendants (std::shared_ptr< packet_type > subtree)
 Creates a new object for iterating through the strict descendants of the given packet. More...
 
PacketDescendantsoperator= (const PacketDescendants &)=default
 Sets this object to iterate over the strict descendants of the same packet as the given object. More...
 
SubtreeIterator< const_ > begin () const
 Returns a C++ iterator at the beginning of the range of strict descendant packets. More...
 
SubtreeIterator< const_ > end () const
 Returns a C++ iterator at the end of the range of strict descendant packets. More...
 
auto __iter__ () const
 Returns a Python iterator over all strict descendant packets. More...
 
bool operator== (const PacketDescendants &rhs) const
 Determines whether this and the given object are designed to iterate over strict descendants of the same packet. More...
 
bool operator!= (const PacketDescendants &rhs) const
 Determines whether this and the given object are designed to iterate over strict descendants of different packets. More...
 

Detailed Description

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()) { ... }

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).

Member Typedef Documentation

◆ packet_type

template<bool const_>
using regina::PacketDescendants< const_ >::packet_type = std::conditional_t<const_, const Packet, Packet>

Either Packet or const Packet, according to the template argument const_.

Constructor & Destructor Documentation

◆ PacketDescendants() [1/2]

template<bool const_>
regina::PacketDescendants< const_ >::PacketDescendants ( const PacketDescendants< const_ > &  )
default

Creates a new object for iterating through the strict descendants of the same packet as the given object.

Python
Not present. The only way to create a PacketDescendants object is via Packet::descendants().

◆ PacketDescendants() [2/2]

template<bool const_>
regina::PacketDescendants< const_ >::PacketDescendants ( std::shared_ptr< packet_type subtree)
inline

Creates a new object for iterating through the strict descendants of the given packet.

Python
Not present. The only way to create a PacketDescendants object is via Packet::descendants().
Parameters
subtreethe packet whose strict descendants we will iterate through.

Member Function Documentation

◆ __iter__()

template<bool const_>
auto regina::PacketDescendants< const_ >::__iter__ ( ) const

Returns a Python iterator over all strict descendant packets.

C++
Not present. For C++ users, PacketDescendants provides the usual begin() and end() functions instead. In particular, this allows you to iterate through all strict descendant packets in the usual way using a range-based for loop.
Returns
an iterator over all strict descendant packets.

◆ begin()

template<bool const_>
SubtreeIterator< const_ > regina::PacketDescendants< const_ >::begin
inline

Returns a C++ iterator at the beginning of the range of strict descendant packets.

This will point to the first child packet (if one exists) of the packet whose descendants we are iterating over.

Python
Not present. For Python users, PacketDescendants implements the Python iterable interface. You can iterate over the strict descendant packets in the usual Python way, by treating this PacketDescendants object as you would any native Python container.
Returns
the beginning iterator.

◆ end()

template<bool const_>
SubtreeIterator< const_ > regina::PacketDescendants< const_ >::end
inline

Returns a C++ iterator at the end of the range of strict descendant packets.

Python
Not present. For Python users, PacketDescendants implements the Python iterable interface. You can iterate over the strict descendant packets in the usual Python way, by treating this PacketDescendants object as you would any native Python container.
Returns
the past-the-end iterator.

◆ operator!=()

template<bool const_>
bool regina::PacketDescendants< const_ >::operator!= ( const PacketDescendants< const_ > &  rhs) const

Determines whether this and the given object are designed to iterate over strict descendants of different packets.

Returns
true if and only if this object and rhs iterate over descendants of different packets.

◆ operator=()

template<bool const_>
PacketDescendants & regina::PacketDescendants< const_ >::operator= ( const PacketDescendants< const_ > &  )
default

Sets this object to iterate over the strict descendants of the same packet as the given object.

Returns
a reference to this object.

◆ operator==()

template<bool const_>
bool regina::PacketDescendants< const_ >::operator== ( const PacketDescendants< const_ > &  rhs) const

Determines whether this and the given object are designed to iterate over strict descendants of the same packet.

Returns
true if and only if this object and rhs iterate over descendants of the same packet.

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

Copyright © 1999-2023, 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).