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

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

#include <mds_utils/python/container_operators.hpp>

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

Public Member Functions

void py_set_item (const Obj &idx, const Obj &val)
 Manages container write access through Python indices and slices. More...
 
- Public Member Functions inherited from mds_utils::python::support_random_access< Derived >
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_getset_access< Derived >

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

Using the Curiously Recurring Template Pattern (CRTP), enables the square brackets operator. Further to the requirements of the support_random_access class, the derived class must support these typedefs and methods:

  • value_type: the type of the elements contained by the container.
  • void set_el_at(size_type i,typename Derived::value_type val): this must set the value val at position i.

Inheriting from this class will add the support_random_getset_access::py_get_item and support_random_getset_access::py_set_item methods to the derived class. These methods are intended to be exported as the __getitem__ and the __setitem__ Python methods respectively.

Author
Michele De Stefano
Date
10/07/2014

Definition at line 144 of file container_operators.hpp.

Member Function Documentation

template<class Derived>
void mds_utils::python::support_random_getset_access< Derived >::py_set_item ( const Obj idx,
const Obj val 
)
inline

Manages container write access through Python indices and slices.

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

Parameters
idxA Python object which can be a numeric index or a numeric slice.
valThe value (or sequence of values) to be set at position (or positions) idx.
Author
Michele De Stefano
Date
10/07/2014

Definition at line 158 of file container_operators.hpp.


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