29#ifndef PX_STRIDE_ITERATOR_H
30#define PX_STRIDE_ITERATOR_H
32#include "foundation/Px.h"
33#include "foundation/PxAssert.h"
91 struct StripConst<const X>
108 PX_ASSERT(mStride == 0 ||
sizeof(T) <= mStride);
117 : mPtr(strideIterator.
ptr()), mStride(strideIterator.
stride())
119 PX_ASSERT(mStride == 0 ||
sizeof(T) <= mStride);
159 return *byteAdd(mPtr, i *
stride());
167 mPtr = byteAdd(mPtr,
stride());
177 mPtr = byteAdd(mPtr,
stride());
186 mPtr = byteSub(mPtr,
stride());
196 mPtr = byteSub(mPtr,
stride());
221 mPtr = byteAdd(mPtr, i *
stride());
230 mPtr = byteSub(mPtr, i *
stride());
239 PX_ASSERT(isCompatible(other));
240 int byteDiff =
static_cast<int>(
reinterpret_cast<const PxU8*
>(mPtr) -
reinterpret_cast<const PxU8*
>(other.mPtr));
241 return byteDiff /
static_cast<int>(
stride());
249 PX_ASSERT(isCompatible(other));
250 return mPtr == other.mPtr;
258 PX_ASSERT(isCompatible(other));
259 return mPtr != other.mPtr;
267 PX_ASSERT(isCompatible(other));
268 return mPtr < other.mPtr;
276 PX_ASSERT(isCompatible(other));
277 return mPtr > other.mPtr;
285 PX_ASSERT(isCompatible(other));
286 return mPtr <= other.mPtr;
294 PX_ASSERT(isCompatible(other));
295 return mPtr >= other.mPtr;
301 return const_cast<T*
>(
reinterpret_cast<const T*
>(
reinterpret_cast<const PxU8*
>(
ptr) +
bytes));
306 return const_cast<T*
>(
reinterpret_cast<const T*
>(
reinterpret_cast<const PxU8*
>(
ptr) -
bytes));
309 PX_INLINE bool isCompatible(
const PxStrideIterator& other)
const
311 int byteDiff =
static_cast<int>(
reinterpret_cast<const PxU8*
>(mPtr) -
reinterpret_cast<const PxU8*
>(other.mPtr));
312 return (
stride() == other.stride()) && (abs(byteDiff) %
stride() == 0);
Iterator class for iterating over arrays of data that may be interleaved with other data.
Definition PxStrideIterator.h:81
PX_INLINE PxStrideIterator operator--(int)
Post-decrement operator.
Definition PxStrideIterator.h:193
PX_INLINE PxStrideIterator operator+(unsigned int i) const
Addition operator.
Definition PxStrideIterator.h:203
PX_INLINE int operator-(const PxStrideIterator &other) const
Iterator difference.
Definition PxStrideIterator.h:237
PX_INLINE T & operator[](unsigned int i) const
Indexing operator.
Definition PxStrideIterator.h:157
PX_INLINE T * operator->() const
Dereferencing operator.
Definition PxStrideIterator.h:149
PX_INLINE bool operator==(const PxStrideIterator &other) const
Equality operator.
Definition PxStrideIterator.h:247
PX_INLINE PxStrideIterator & operator+=(unsigned int i)
Addition compound assignment operator.
Definition PxStrideIterator.h:219
PX_INLINE PxStrideIterator & operator--()
Pre-decrement operator.
Definition PxStrideIterator.h:184
PX_INLINE PxU32 stride() const
Get stride.
Definition PxStrideIterator.h:133
PX_INLINE T * ptr() const
Get pointer to element.
Definition PxStrideIterator.h:125
PX_INLINE bool operator>=(const PxStrideIterator &other) const
Greater or equal than operator.
Definition PxStrideIterator.h:292
PX_INLINE T & operator*() const
Indirection operator.
Definition PxStrideIterator.h:141
PX_INLINE PxStrideIterator(const PxStrideIterator< typename StripConst< T >::Type > &strideIterator)
Copy constructor.
Definition PxStrideIterator.h:116
PX_INLINE bool operator<(const PxStrideIterator &other) const
Less than operator.
Definition PxStrideIterator.h:265
PX_INLINE bool operator!=(const PxStrideIterator &other) const
Inequality operator.
Definition PxStrideIterator.h:256
PX_INLINE PxStrideIterator operator++(int)
Post-increment operator.
Definition PxStrideIterator.h:174
PX_INLINE bool operator<=(const PxStrideIterator &other) const
Less or equal than operator.
Definition PxStrideIterator.h:283
PX_INLINE PxStrideIterator & operator++()
Pre-increment operator.
Definition PxStrideIterator.h:165
PX_INLINE bool operator>(const PxStrideIterator &other) const
Greater than operator.
Definition PxStrideIterator.h:274
PX_INLINE PxStrideIterator operator-(unsigned int i) const
Subtraction operator.
Definition PxStrideIterator.h:211
PX_INLINE PxStrideIterator(T *ptr=NULL, PxU32 stride=sizeof(T))
Constructor.
Definition PxStrideIterator.h:106
PX_INLINE PxStrideIterator & operator-=(unsigned int i)
Subtraction compound assignment operator.
Definition PxStrideIterator.h:228
#define PX_INLINE
Definition PxPreprocessor.h:320
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_INLINE PxStrideIterator< T > operator+(int i, PxStrideIterator< T > it)
Addition operator.
Definition PxStrideIterator.h:323
PX_INLINE PxStrideIterator< T > PxMakeIterator(T *ptr, PxU32 stride=sizeof(T))
Stride iterator factory function which infers the iterator type.
Definition PxStrideIterator.h:333