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

A lightweight object that gives access to all immediate children of a given packet. More...

#include <packet/packet.h>

Public Types

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

Public Member Functions

 PacketChildren (const PacketChildren &)=default
 Default copy constructor. More...
 
 PacketChildren (std::shared_ptr< packet_type > parent)
 Creates a new object for iterating through the immediate children of the given packet. More...
 
PacketChildrenoperator= (const PacketChildren &)=default
 Default copy assignment operator. More...
 
ChildIterator< const_ > begin () const
 Returns an iterator at the beginning of the range of children. More...
 
ChildIterator< const_ > end () const
 Returns an iterator at the end of the range of children. More...
 
bool operator== (const PacketChildren &rhs) const
 Determines whether this and the given object are designed to iterate over children of the same parent packet. More...
 
bool operator!= (const PacketChildren &rhs) const
 Determines whether this and the given object are designed to iterate over children of different parent packets. More...
 

Detailed Description

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 C++11 range-based for loops:

std::shared_ptr<Packet> parent = ...;
for (Packet& child : parent->children()) { ... }

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

Member Typedef Documentation

◆ packet_type

template<bool const_>
using regina::PacketChildren< const_ >::packet_type = typename std::conditional<const_, const Packet, Packet>::type

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

Constructor & Destructor Documentation

◆ PacketChildren() [1/2]

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

Default copy constructor.

Python
Not present.

◆ PacketChildren() [2/2]

template<bool const_>
regina::PacketChildren< const_ >::PacketChildren ( std::shared_ptr< packet_type parent)
inline

Creates a new object for iterating through the immediate children of the given packet.

Python
Not present.
Parameters
parentthe packet whose children we will iterate through.

Member Function Documentation

◆ begin()

template<bool const_>
ChildIterator< const_ > regina::PacketChildren< const_ >::begin
inline

Returns an iterator at the beginning of the range of children.

Python
Not present; instead this class implements iter(), as described in the class notes.
Returns
the beginning iterator.

◆ end()

template<bool const_>
ChildIterator< const_ > regina::PacketChildren< const_ >::end
inline

Returns an iterator at the end of the range of children.

Python
Not present; instead this class implements iter(), as described in the class notes.
Returns
the past-the-end iterator.

◆ operator!=()

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

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

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

◆ operator=()

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

Default copy assignment operator.

Python
Not present.

◆ operator==()

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

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

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

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

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