Regina 7.0 Calculation Engine
Public Member Functions | Static Public Member Functions | List of all members
regina::python::ConstArray< Array > Class Template Reference

A template class that references a constant one-dimensional "array-like" object. More...

#include <python/constarray.h>

Public Member Functions

 ConstArray (const Array &data, size_t size)
 Constructs a new wrapper object for the given array-like object. More...
 
 ConstArray (const ConstArray< Array > &)=default
 Constructs a new wrapper for the same underlying array as the given wrapper. More...
 
ConstArray< Array > & operator= (const ConstArray< Array > &)=default
 Sets this to wrap the same underlying array as the given wrapper. More...
 
size_t size () const
 Return the number of elements in this array. More...
 
auto getItem (size_t index) const
 Returns the array element at the given index. More...
 
std::ostream & writeText (std::ostream &out) const
 Writes a string representation of this array, including all of its elements, to the given output stream. More...
 

Static Public Member Functions

static void wrapClass (pybind11::module_ &m, const char *className)
 Constructs a Python wrapper for this class. More...
 

Detailed Description

template<typename Array>
class regina::python::ConstArray< Array >

A template class that references a constant one-dimensional "array-like" object.

This can be used with plain C-style arrays, or can also be used with constant "array-like" objects such as Perm<4>::S4, which behave like arrays but in fact compute their values on the fly.

The requirements for the type Array are:

In Python, the usual list operator [] can be used to access the elements of the array. Range checking is performed on any index that is passed.

For each different template parameter, the corresponding ConstArray class must be wrapped in Python before the first object of this class is wrapped. This wrapping is performed by calling wrapClass().

Precondition
The output operator << is defined for the objects contained in this array (i.e., for the return type of the square bracket operator).

Constructor & Destructor Documentation

◆ ConstArray() [1/2]

template<typename Array >
regina::python::ConstArray< Array >::ConstArray ( const Array &  data,
size_t  size 
)
inline

Constructs a new wrapper object for the given array-like object.

Precondition
This class has already been wrapped in Python by calling wrapClass().
Parameters
datathe array that is to be wrapped.
sizethe number of elements in this array.

◆ ConstArray() [2/2]

template<typename Array >
regina::python::ConstArray< Array >::ConstArray ( const ConstArray< Array > &  )
default

Constructs a new wrapper for the same underlying array as the given wrapper.

Note that the underlying array itself is not copied.

Member Function Documentation

◆ getItem()

template<typename Array >
auto regina::python::ConstArray< Array >::getItem ( size_t  index) const
inline

Returns the array element at the given index.

If the index is out of range, a Python error will be thrown.

Parameters
indexthe given array index.
Returns
the element at the given index.

◆ operator=()

template<typename Array >
ConstArray< Array > & regina::python::ConstArray< Array >::operator= ( const ConstArray< Array > &  )
default

Sets this to wrap the same underlying array as the given wrapper.

Note that the underlying array itself is not copied.

◆ size()

template<typename Array >
size_t regina::python::ConstArray< Array >::size ( ) const
inline

Return the number of elements in this array.

Returns
the number of elements.

◆ wrapClass()

template<typename Array >
static void regina::python::ConstArray< Array >::wrapClass ( pybind11::module_ &  m,
const char *  className 
)
inlinestatic

Constructs a Python wrapper for this class.

This routine must be called for each template parameter before the first object of this class is wrapped.

Parameters
mthe Python module in which these wrappers should be installed.
classNamethe name that will be assigned to this class in Python.

◆ writeText()

template<typename Array >
std::ostream & regina::python::ConstArray< Array >::writeText ( std::ostream &  out) const
inline

Writes a string representation of this array, including all of its elements, to the given output stream.

Parameters
outthe output stream to which to write.
Returns
a reference to out.

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