Michele De Stefano's C++ Utilities
mds_utils::python::support_random_access< Derived > Struct Template Reference

Adds support for random access operator (i.e. square brackets) to a class that has to be exposed to the Python interpreter. The access is only in read mode. More...

#include <mds_utils/python/container_operators.hpp>

Inheritance diagram for mds_utils::python::support_random_access< Derived >:
mds_utils::python::support_random_getset_access< Derived >

Public Member Functions

Obj py_get_item (const Obj &idx)
 Manages container read access through Python indices and slices. More...
 

Detailed Description

template<class Derived>
struct mds_utils::python::support_random_access< Derived >

Adds support for random access operator (i.e. square brackets) to a class that has to be exposed to the Python interpreter. The access is only in read mode.

Using the Curiously Recurring Template Pattern (CRTP), enables the square brackets operator. The derived class must support these methods:

  • size_type get_nel(): this must return the total number of elements into the container.
  • element_type get_el_at(size_type i): this must return the element at index i.

Inheriting from this class will add the support_random_access::py_get_item method to the derived class. This method is intended to be exported as the __getitem__ Python method. It will give only read access to the elements.

Author
Michele De Stefano
Date
10/07/2014

Definition at line 58 of file container_operators.hpp.

Member Function Documentation

template<class Derived>
Obj mds_utils::python::support_random_access< Derived >::py_get_item ( const Obj idx)
inline

Manages container read access through Python indices and slices.

It is intended to be exposed/used as the __getitem__ method.

Parameters
idxA Python object which can be a numeric index or a numeric slice.
Returns
The accessed element, if idx is an index; a list of elements if idx is a slice.
Remarks
This method gives only read access to the returned element.
Author
Michele De Stefano
Date
10/07/2014

Definition at line 76 of file container_operators.hpp.


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