PxStrideIterator

Defined in include/foundation/PxStrideIterator.h

template<typename T>
class PxStrideIterator

Iterator class for iterating over arrays of data that may be interleaved with other data.

This class is used for iterating over arrays of elements that may have a larger element to element offset, called the stride, than the size of the element itself (non-contiguous).

The template parameter T denotes the type of the element accessed. The stride itself is stored as a member field so multiple instances of a PxStrideIterator class can have different strides. This is useful for cases were the stride depends on runtime configuration.

The stride iterator can be used for index based access, e.g.:

PxStrideIterator<PxVec3> strideArray(...);
for (unsigned i = 0; i < 10; ++i)
{
    PxVec3& vec = strideArray[i];
    ...
}
or iteration by increment, e.g.:
PxStrideIterator<PxVec3> strideBegin(...);
PxStrideIterator<PxVec3> strideEnd(strideBegin + 10);
for (PxStrideIterator<PxVec3> it = strideBegin; it < strideEnd; ++it)
{
    PxVec3& vec = *it;
    ...
}

Two special cases:

  • A stride of sizeof(T) represents a regular c array of type T.

  • A stride of 0 can be used to describe re-occurrence of the same element multiple times.

Public Functions

inline explicit PxStrideIterator(T *ptr = NULL, PxU32 stride = sizeof(T))

Constructor.

Optionally takes a pointer to an element and a stride.

Parameters
  • ptr[in] pointer to element, defaults to NULL.

  • stride[in] stride for accessing consecutive elements, defaults to the size of one element.

inline PxStrideIterator(const PxStrideIterator<typename StripConst<T>::Type> &strideIterator)

Copy constructor.

Parameters

strideIterator[in] PxStrideIterator to be copied.

inline T *ptr() const

Get pointer to element.

inline PxU32 stride() const

Get stride.

inline T &operator*() const

Indirection operator.

inline T *operator->() const

Dereferencing operator.

inline T &operator[](unsigned int i) const

Indexing operator.

inline PxStrideIterator &operator++()

Pre-increment operator.

inline PxStrideIterator operator++(int)

Post-increment operator.

inline PxStrideIterator &operator--()

Pre-decrement operator.

inline PxStrideIterator operator--(int)

Post-decrement operator.

inline PxStrideIterator operator+(unsigned int i) const

Addition operator.

inline PxStrideIterator operator-(unsigned int i) const

Subtraction operator.

inline PxStrideIterator &operator+=(unsigned int i)

Addition compound assignment operator.

inline PxStrideIterator &operator-=(unsigned int i)

Subtraction compound assignment operator.

inline int operator-(const PxStrideIterator &other) const

Iterator difference.

inline bool operator==(const PxStrideIterator &other) const

Equality operator.

inline bool operator!=(const PxStrideIterator &other) const

Inequality operator.

inline bool operator<(const PxStrideIterator &other) const

Less than operator.

inline bool operator>(const PxStrideIterator &other) const

Greater than operator.

inline bool operator<=(const PxStrideIterator &other) const

Less or equal than operator.

inline bool operator>=(const PxStrideIterator &other) const

Greater or equal than operator.