32#include "foundation/PxAssert.h"
33#include "foundation/PxMathIntrinsics.h"
34#include "foundation/PxAllocator.h"
35#include "foundation/PxBasicTemplates.h"
36#include "foundation/PxMemory.h"
51template <class T, class Alloc = typename PxAllocatorTraits<T>::Type>
56 typedef const T* ConstIterator;
61 mCapacity |= PX_SIGN_BITMASK;
67 PX_INLINE explicit PxArray(
const Alloc& alloc = Alloc()) : Alloc(alloc), mData(0), mSize(0), mCapacity(0)
75 : Alloc(alloc), mData(0), mSize(0), mCapacity(0)
106 : Alloc(alloc), mSize(last < first ? 0 : uint32_t(last - first)), mCapacity(mSize)
108 mData = allocate(mSize);
109 copy(mData, mData + mSize, first);
117 destroy(mData, mData + mSize);
134 copy(mData, mData + rhs.mSize, rhs.mData);
142 return operator=<Alloc>(t);
154 PX_ASSERT(i < mSize);
167 PX_ASSERT(i < mSize);
194 return mData + mSize;
199 return mData + mSize;
227 return mData[mSize - 1];
233 return mData[mSize - 1];
252 destroy(mData, mData + mSize);
275 for(index = 0; index < mSize && mData[index] != a; index++)
277 return mData + index;
283 for(index = 0; index < mSize && mData[index] != a; index++)
285 return mData + index;
301 PX_PLACEMENT_NEW(
reinterpret_cast<void*
>(mData + mSize), T)(a);
303 return mData[mSize++];
314 T t = mData[mSize - 1];
329 grow(capacityIncrement());
331 T* ptr = mData + mSize++;
332 PX_PLACEMENT_NEW(ptr, T);
347 PX_ASSERT(i < mSize);
348 mData[i] = mData[--mSize];
371 while(index < mSize && mData[index] != a)
390 PX_ASSERT(i < mSize);
396 PX_PLACEMENT_NEW(it, T(mData[i]));
415 PX_ASSERT(
begin < mSize);
416 PX_ASSERT((
begin + count) <= mSize);
418 for(uint32_t i = 0; i < count; i++)
419 mData[
begin + i].~T();
421 T* dest = &mData[
begin];
422 T* src = &mData[
begin + count];
423 uint32_t move_count = mSize - (
begin + count);
425 for(uint32_t i = 0; i < move_count; i++)
427 PX_PLACEMENT_NEW(dest, T(*src));
474 const PxU32 s =
size();
499 return mCapacity & ~PX_SIGN_BITMASK;
509 PX_ASSERT(
size <= mCapacity);
520 PxSwap(mData, other.mData);
521 PxSwap(mSize, other.mSize);
522 PxSwap(mCapacity, other.mCapacity);
532 resizeUninitialized(uint32_t(last - first));
540 return mCapacity & PX_SIGN_BITMASK;
552 : Alloc(alloc), mData(memory), mSize(
size), mCapacity(
capacity | PX_SIGN_BITMASK)
563 T* p =
reinterpret_cast<T*
>(Alloc::allocate(
sizeof(T) *
size, __FILE__, __LINE__));
572 Alloc::deallocate(mem);
575 static PX_INLINE void create(T* first, T* last,
const T& a)
577 for(; first < last; ++first)
578 ::PX_PLACEMENT_NEW(first, T(a));
581 static PX_INLINE void copy(T* first, T* last,
const T* src)
586 for(; first < last; ++first, ++src)
587 ::PX_PLACEMENT_NEW(first, T(*src));
590 static PX_INLINE void destroy(T* first, T* last)
592 for(; first < last; ++first)
610 PX_ASSERT(this->
capacity() < capacity);
625 PX_INLINE uint32_t capacityIncrement()
const
628 return capacity == 0 ? 1 :
capacity * 2;
636template <
class T,
class Alloc>
640 create(mData + mSize, mData + size, a);
641 destroy(mData + size, mData + mSize);
645template <
class T,
class Alloc>
651 mData = allocate(mSize = mCapacity = other.
size());
652 copy(mData, mData + mSize, other.
begin());
667template <
class T,
class Alloc>
668PX_NOINLINE void PxArray<T, Alloc>::resizeUninitialized(
const uint32_t size)
674template <
class T,
class Alloc>
677 uint32_t capacity = capacityIncrement();
679 T* newData = allocate(capacity);
680 PX_ASSERT((!capacity) || (newData && (newData != mData)));
681 copy(newData, newData + mSize, mData);
685 PX_PLACEMENT_NEW(
reinterpret_cast<void*
>(newData + mSize), T)(a);
687 destroy(mData, mData + mSize);
688 if(!isInUserMemory())
692 mCapacity = capacity;
694 return mData[mSize++];
697template <
class T,
class Alloc>
700 T* newData = allocate(capacity);
701 PX_ASSERT((!capacity) || (newData && (newData != mData)));
703 copy(newData, newData + mSize, mData);
704 destroy(mData, mData + mSize);
705 if(!isInUserMemory())
709 mCapacity = capacity;
712template <
class T,
class Alloc>
PX_INLINE PxArray(uint32_t size, const T &a=T(), const Alloc &alloc=Alloc())
Definition PxArray.h:74
PX_INLINE void shrink()
Definition PxArray.h:450
PX_INLINE Iterator find(const T &a)
Definition PxArray.h:272
PX_INLINE PxArray(const PxArray< T, A > &other, const Alloc &alloc=Alloc())
Definition PxArray.h:84
PX_NOINLINE T & growAndPushBack(const T &a)
Definition PxArray.h:675
PX_INLINE void assign(const T *first, const T *last)
Definition PxArray.h:530
PX_INLINE Alloc & getAllocator()
return reference to allocator
Definition PxArray.h:544
PX_FORCE_INLINE ConstIterator end() const
Definition PxArray.h:192
PX_NOINLINE void resize(const uint32_t size, const T &a=T())
Definition PxArray.h:637
PX_FORCE_INLINE uint32_t size() const
Definition PxArray.h:242
PX_FORCE_INLINE void forceSize_Unsafe(uint32_t size)
Definition PxArray.h:507
PX_FORCE_INLINE const T & front() const
Definition PxArray.h:207
PX_INLINE void reset()
Definition PxArray.h:460
PX_INLINE void clear()
Definition PxArray.h:250
PX_INLINE void removeRange(uint32_t begin, uint32_t count)
Definition PxArray.h:413
PX_NOINLINE void recreate(uint32_t capacity)
Definition PxArray.h:698
PX_INLINE void swap(PxArray< T, Alloc > &other)
Definition PxArray.h:518
PX_FORCE_INLINE const T & operator[](uint32_t i) const
Definition PxArray.h:152
PX_FORCE_INLINE ConstIterator begin() const
Definition PxArray.h:176
PX_FORCE_INLINE bool empty() const
Definition PxArray.h:261
PX_FORCE_INLINE T & operator[](uint32_t i)
Definition PxArray.h:165
PX_FORCE_INLINE uint32_t capacity() const
Definition PxArray.h:497
PX_FORCE_INLINE T & pushBack(const T &a)
Definition PxArray.h:296
PX_INLINE PxArray & operator=(const PxArray< T, A > &rhs)
Definition PxArray.h:127
PX_INLINE void reserve(const uint32_t capacity)
Definition PxArray.h:486
PX_INLINE void replaceWithLast(uint32_t i)
Definition PxArray.h:345
PX_INLINE PxArray(const T *first, const T *last, const Alloc &alloc=Alloc())
Definition PxArray.h:105
PX_INLINE ~PxArray()
Definition PxArray.h:115
PX_INLINE PxArray(const Alloc &alloc=Alloc())
Definition PxArray.h:67
PX_INLINE T popBack()
Definition PxArray.h:311
PX_INLINE T & insert()
Definition PxArray.h:326
PX_INLINE void resetOrClear()
Definition PxArray.h:471
PX_INLINE void grow(uint32_t capacity)
Definition PxArray.h:608
PX_INLINE void remove(uint32_t i)
Definition PxArray.h:388
PX_INLINE bool findAndReplaceWithLast(const T &a)
Definition PxArray.h:368
PX_FORCE_INLINE const T & back() const
Definition PxArray.h:224
#define PX_NOINLINE
Definition PxPreprocessor.h:346
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#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 void PxMarkSerializedMemory(void *ptr, PxU32 byteSize)
Definition PxMemory.h:111
PxEMPTY
Definition Px.h:87