30#ifndef PXFOUNDATION_PXSTRIDEITERATOR_H
31#define PXFOUNDATION_PXSTRIDEITERATOR_H
33#include "foundation/Px.h"
34#include "foundation/PxSharedAssert.h"
92 struct StripConst<const X>
109 PX_SHARED_ASSERT(mStride == 0 ||
sizeof(T) <= mStride);
118 : mPtr(strideIterator.
ptr()), mStride(strideIterator.
stride())
120 PX_SHARED_ASSERT(mStride == 0 ||
sizeof(T) <= mStride);
160 return *byteAdd(mPtr, i *
stride());
168 mPtr = byteAdd(mPtr,
stride());
178 mPtr = byteAdd(mPtr,
stride());
187 mPtr = byteSub(mPtr,
stride());
197 mPtr = byteSub(mPtr,
stride());
222 mPtr = byteAdd(mPtr, i *
stride());
231 mPtr = byteSub(mPtr, i *
stride());
240 PX_SHARED_ASSERT(isCompatible(other));
241 int byteDiff =
static_cast<int>(
reinterpret_cast<const PxU8*
>(mPtr) -
reinterpret_cast<const PxU8*
>(other.mPtr));
242 return byteDiff /
static_cast<int>(
stride());
250 PX_SHARED_ASSERT(isCompatible(other));
251 return mPtr == other.mPtr;
259 PX_SHARED_ASSERT(isCompatible(other));
260 return mPtr != other.mPtr;
268 PX_SHARED_ASSERT(isCompatible(other));
269 return mPtr < other.mPtr;
277 PX_SHARED_ASSERT(isCompatible(other));
278 return mPtr > other.mPtr;
286 PX_SHARED_ASSERT(isCompatible(other));
287 return mPtr <= other.mPtr;
295 PX_SHARED_ASSERT(isCompatible(other));
296 return mPtr >= other.mPtr;
302 return const_cast<T*
>(
reinterpret_cast<const T*
>(
reinterpret_cast<const PxU8*
>(
ptr) +
bytes));
307 return const_cast<T*
>(
reinterpret_cast<const T*
>(
reinterpret_cast<const PxU8*
>(
ptr) -
bytes));
310 PX_INLINE bool isCompatible(
const PxStrideIterator& other)
const
312 int byteDiff =
static_cast<int>(
reinterpret_cast<const PxU8*
>(mPtr) -
reinterpret_cast<const PxU8*
>(other.mPtr));
313 return (
stride() == other.stride()) && (abs(byteDiff) %
stride() == 0);
336 return PxStrideIterator<T>(ptr, stride);
345 return PxStrideIterator<const T>(ptr, stride);
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:194
PX_INLINE PxStrideIterator operator+(unsigned int i) const
Addition operator.
Definition PxStrideIterator.h:204
PX_INLINE int operator-(const PxStrideIterator &other) const
Iterator difference.
Definition PxStrideIterator.h:238
PX_INLINE T & operator[](unsigned int i) const
Indexing operator.
Definition PxStrideIterator.h:158
PX_INLINE T * operator->() const
Dereferencing operator.
Definition PxStrideIterator.h:150
PX_INLINE bool operator==(const PxStrideIterator &other) const
Equality operator.
Definition PxStrideIterator.h:248
PX_INLINE PxStrideIterator & operator+=(unsigned int i)
Addition compound assignment operator.
Definition PxStrideIterator.h:220
PX_INLINE PxStrideIterator & operator--()
Pre-decrement operator.
Definition PxStrideIterator.h:185
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:293
PX_INLINE T & operator*() const
Indirection operator.
Definition PxStrideIterator.h:142
PX_INLINE PxStrideIterator(const PxStrideIterator< typename StripConst< T >::Type > &strideIterator)
Copy constructor.
Definition PxStrideIterator.h:117
PX_INLINE bool operator<(const PxStrideIterator &other) const
Less than operator.
Definition PxStrideIterator.h:266
PX_INLINE bool operator!=(const PxStrideIterator &other) const
Inequality operator.
Definition PxStrideIterator.h:257
PX_INLINE PxStrideIterator operator++(int)
Post-increment operator.
Definition PxStrideIterator.h:175
PX_INLINE bool operator<=(const PxStrideIterator &other) const
Less or equal than operator.
Definition PxStrideIterator.h:284
PX_INLINE PxStrideIterator & operator++()
Pre-increment operator.
Definition PxStrideIterator.h:166
PX_INLINE bool operator>(const PxStrideIterator &other) const
Greater than operator.
Definition PxStrideIterator.h:275
PX_INLINE PxStrideIterator operator-(unsigned int i) const
Subtraction operator.
Definition PxStrideIterator.h:212
PX_INLINE PxStrideIterator(T *ptr=NULL, PxU32 stride=sizeof(T))
Constructor.
Definition PxStrideIterator.h:107
PX_INLINE PxStrideIterator & operator-=(unsigned int i)
Subtraction compound assignment operator.
Definition PxStrideIterator.h:229
#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