μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
iterator Class Reference

\rst Wraps a Python iterator so that it can also be used as a C++ input iterator More...

#include </builds/ipbus/ipbus-software/uhal/python/pybind11-python2/include/pybind11/pytypes.h>

Inheritance diagram for iterator:
[legend]
Collaboration diagram for iterator:
[legend]

Public Types

using iterator_category = std::input_iterator_tag
 
using difference_type = ssize_t
 
using value_type = handle
 
using reference = const handle
 
using pointer = const handle *
 
using iterator_category = std::input_iterator_tag
 
using difference_type = ssize_t
 
using value_type = handle
 
using reference = const handle
 
using pointer = const handle *
 

Public Member Functions

iteratoroperator++ ()
 
iterator operator++ (int)
 
reference operator* () const
 
pointer operator-> () const
 
iteratoroperator++ ()
 
iterator operator++ (int)
 
reference operator* () const
 
pointer operator-> () const
 
- Public Member Functions inherited from object
 object ()=default
 
 PYBIND11_DEPRECATED ("Use reinterpret_borrow<object>() or reinterpret_steal<object>()") object(handle h
 
 object (const object &o)
 Copy constructor; always increases the reference count. More...
 
 object (object &&other) noexcept
 Move constructor; steals the object from other and preserves its reference count. More...
 
 ~object ()
 Destructor; automatically calls handle::dec_ref() More...
 
handle release ()
 \rst Resets the internal pointer to nullptr without decreasing the object's reference count. More...
 
objectoperator= (const object &other)
 
objectoperator= (object &&other) noexcept
 
template<typename T >
cast () const &
 
template<typename T >
cast () &&
 
 object (handle h, borrowed_t)
 
 object (handle h, stolen_t)
 
 object ()=default
 
 PYBIND11_DEPRECATED ("Use reinterpret_borrow<object>() or reinterpret_steal<object>()") object(handle h
 
 object (const object &o)
 Copy constructor; always increases the reference count. More...
 
 object (object &&other) noexcept
 Move constructor; steals the object from other and preserves its reference count. More...
 
 ~object ()
 Destructor; automatically calls handle::dec_ref() More...
 
handle release ()
 \rst Resets the internal pointer to nullptr without decreasing the object's reference count. More...
 
objectoperator= (const object &other)
 
objectoperator= (object &&other) noexcept
 
template<typename T >
cast () const &
 
template<typename T >
cast () &&
 
 object (handle h, borrowed_t)
 
 object (handle h, stolen_t)
 
template<typename T >
cast () const &
 
template<typename T >
cast () &&
 
template<>
void cast () const &
 
template<>
void cast () &&
 
- Public Member Functions inherited from handle
 handle ()=default
 The default constructor creates a handle with a nullptr-valued pointer. More...
 
 handle (PyObject *ptr)
 Creates a handle from the given raw Python object pointer. More...
 
PyObject * ptr () const
 Return the underlying PyObject * pointer. More...
 
PyObject *& ptr ()
 
const handleinc_ref () const &
 \rst Manually increase the reference count of the Python object. More...
 
const handledec_ref () const &
 \rst Manually decrease the reference count of the Python object. More...
 
template<typename T >
cast () const
 \rst Attempt to cast the Python object into the given C++ type. More...
 
 operator bool () const
 Return true when the handle wraps a valid Python object. More...
 
bool operator== (const handle &h) const
 \rst Deprecated: Check that the underlying pointers are the same. More...
 
bool operator!= (const handle &h) const
 
bool check () const
 
 handle ()=default
 The default constructor creates a handle with a nullptr-valued pointer. More...
 
template<typename T , detail::enable_if_t< detail::is_pyobj_ptr_or_nullptr_t< T >::value, int > = 0>
 handle (T ptr)
 Enable implicit conversion from PyObject * and nullptr. More...
 
template<typename T , detail::enable_if_t< detail::all_of< detail::none_of< std::is_base_of< handle, T >, detail::is_pyobj_ptr_or_nullptr_t< T > >, std::is_convertible< T, PyObject * > >::value, int > = 0>
 handle (T &obj)
 Enable implicit conversion through T::operator PyObject *(). More...
 
PyObject * ptr () const
 Return the underlying PyObject * pointer. More...
 
PyObject *& ptr ()
 
const handleinc_ref () const &
 \rst Manually increase the reference count of the Python object. More...
 
const handledec_ref () const &
 \rst Manually decrease the reference count of the Python object. More...
 
template<typename T >
cast () const
 \rst Attempt to cast the Python object into the given C++ type. More...
 
 operator bool () const
 Return true when the handle wraps a valid Python object. More...
 
bool operator== (const handle &h) const
 \rst Deprecated: Check that the underlying pointers are the same. More...
 
bool operator!= (const handle &h) const
 
bool check () const
 
template<>
void cast () const
 

Static Public Member Functions

static iterator sentinel ()
 \rst The value which marks the end of the iteration. More...
 
static iterator sentinel ()
 \rst The value which marks the end of the iteration. More...
 
- Static Public Member Functions inherited from handle
static std::size_t inc_ref_counter ()
 

Private Member Functions

void advance ()
 
void advance ()
 

Private Attributes

object value = {}
 

Friends

bool operator== (const iterator &a, const iterator &b)
 
bool operator!= (const iterator &a, const iterator &b)
 
bool operator== (const iterator &a, const iterator &b)
 
bool operator!= (const iterator &a, const iterator &b)
 

Additional Inherited Members

- Public Attributes inherited from object
bool is_borrowed: handle(h) { if (is_borrowed) { inc_ref()
 
- Protected Attributes inherited from handle
PyObject * m_ptr = nullptr
 

Detailed Description

\rst Wraps a Python iterator so that it can also be used as a C++ input iterator

Caveat: copying an iterator does not (and cannot) clone the internal state of the Python iterable. This also applies to the post-increment operator. This iterator should only be used to retrieve the current value using operator*(). \endrst

Caveat: copying an iterator does not (and cannot) clone the internal state of the Python iterable. This also applies to the post-increment operator. This iterator should only be used to retrieve the current value using operator*(). \endrst

Definition at line 1102 of file pytypes.h.

Member Typedef Documentation

◆ difference_type [1/2]

Definition at line 1105 of file pytypes.h.

◆ difference_type [2/2]

Definition at line 1370 of file pytypes.h.

◆ iterator_category [1/2]

using iterator::iterator_category = std::input_iterator_tag

Definition at line 1104 of file pytypes.h.

◆ iterator_category [2/2]

using iterator::iterator_category = std::input_iterator_tag

Definition at line 1369 of file pytypes.h.

◆ pointer [1/2]

using iterator::pointer = const handle *

Definition at line 1108 of file pytypes.h.

◆ pointer [2/2]

using iterator::pointer = const handle *

Definition at line 1373 of file pytypes.h.

◆ reference [1/2]

using iterator::reference = const handle

Definition at line 1107 of file pytypes.h.

◆ reference [2/2]

using iterator::reference = const handle

Definition at line 1372 of file pytypes.h.

◆ value_type [1/2]

Definition at line 1106 of file pytypes.h.

◆ value_type [2/2]

Definition at line 1371 of file pytypes.h.

Member Function Documentation

◆ advance() [1/2]

void iterator::advance ( )
inlineprivate

Definition at line 1156 of file pytypes.h.

References handle::m_ptr, and value.

Referenced by operator++().

◆ advance() [2/2]

void iterator::advance ( )
inlineprivate

Definition at line 1421 of file pytypes.h.

References handle::m_ptr, handle::ptr(), and value.

◆ operator*() [1/2]

reference iterator::operator* ( ) const
inline

Definition at line 1124 of file pytypes.h.

References handle::m_ptr, handle::ptr(), self, and value.

Referenced by operator->().

◆ operator*() [2/2]

reference iterator::operator* ( ) const
inline

Definition at line 1389 of file pytypes.h.

References handle::m_ptr, handle::ptr(), self, and value.

◆ operator++() [1/4]

iterator & iterator::operator++ ( )
inline

Definition at line 1112 of file pytypes.h.

References advance().

◆ operator++() [2/4]

iterator & iterator::operator++ ( )
inline

Definition at line 1377 of file pytypes.h.

References advance().

◆ operator++() [3/4]

iterator iterator::operator++ ( int  )
inline

Definition at line 1117 of file pytypes.h.

References advance().

◆ operator++() [4/4]

iterator iterator::operator++ ( int  )
inline

Definition at line 1382 of file pytypes.h.

References advance().

◆ operator->() [1/2]

pointer iterator::operator-> ( ) const
inline

Definition at line 1132 of file pytypes.h.

References operator*(), and value.

◆ operator->() [2/2]

pointer iterator::operator-> ( ) const
inline

Definition at line 1397 of file pytypes.h.

References operator*(), and value.

◆ sentinel() [1/2]

static iterator iterator::sentinel ( )
inlinestatic

\rst The value which marks the end of the iteration.

it == iterator::sentinel() is equivalent to catching StopIteration in Python.

.. code-block:: cpp

void foo(py::iterator it) {
    while (it != py::iterator::sentinel()) {

use *it ++it; } } \endrst

Definition at line 1150 of file pytypes.h.

Referenced by object_api< Derived >::end().

◆ sentinel() [2/2]

static iterator iterator::sentinel ( )
inlinestatic

\rst The value which marks the end of the iteration.

it == iterator::sentinel() is equivalent to catching StopIteration in Python.

.. code-block:: cpp

void foo(py::iterator it) {
    while (it != py::iterator::sentinel()) {

use *it ++it; } } \endrst

Definition at line 1415 of file pytypes.h.

Friends And Related Function Documentation

◆ operator!= [1/2]

bool operator!= ( const iterator a,
const iterator b 
)
friend

Definition at line 1153 of file pytypes.h.

◆ operator!= [2/2]

bool operator!= ( const iterator a,
const iterator b 
)
friend

Definition at line 1418 of file pytypes.h.

◆ operator== [1/2]

bool operator== ( const iterator a,
const iterator b 
)
friend

Definition at line 1152 of file pytypes.h.

◆ operator== [2/2]

bool operator== ( const iterator a,
const iterator b 
)
friend

Definition at line 1417 of file pytypes.h.

Member Data Documentation

◆ value

object iterator::value = {}
private

Definition at line 1164 of file pytypes.h.

Referenced by advance(), operator*(), and operator->().


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