18 #ifndef B2_GROWABLE_BUFFER_H
19 #define B2_GROWABLE_BUFFER_H
21 #include <Box2D/Common/b2BlockAllocator.h>
39 #if defined(LIQUIDFUN_SIMD_NEON)
44 b2Assert((intptr_t)&data - (intptr_t)(
this) == 0
45 && (intptr_t)&capacity - (intptr_t)(
this) == 8);
46 #endif // defined(LIQUIDFUN_SIMD_NEON)
52 capacity(rhs.capacity),
53 allocator(rhs.allocator)
57 data = (T*) allocator->
Allocate(
sizeof(T) * capacity);
58 memcpy(data, rhs.data,
sizeof(T) * count);
69 if (count >= capacity)
76 void Reserve(int32 newCapacity)
78 if (capacity >= newCapacity)
82 T* newData = (T*) allocator->
Allocate(
sizeof(T) * newCapacity);
85 memcpy(newData, data,
sizeof(T) * count);
86 allocator->
Free(data,
sizeof(T) * capacity);
90 capacity = newCapacity;
97 int32 newCapacity = capacity ? 2 * capacity
99 b2Assert(newCapacity > capacity);
100 Reserve(newCapacity);
108 allocator->
Free(data,
sizeof(data[0]) * capacity);
114 void Shorten(
const T* newEnd)
116 b2Assert(newEnd >= data);
117 count = (int32) (newEnd - data);
125 const T& operator[](
int i)
const
135 const T* Data()
const
145 const T* Begin()
const
160 int32 GetCount()
const
165 void SetCount(int32 newCount)
167 b2Assert(0 <= newCount && newCount <= capacity);
171 int32 GetCapacity()
const
176 template<
class UnaryPredicate>
177 T* RemoveIf(UnaryPredicate pred)
179 T* newEnd = std::remove_if(data, data + count, pred);
184 template<
class BinaryPredicate>
185 T* Unique(BinaryPredicate pred)
187 T* newEnd = std::unique(data, data + count, pred);
199 #endif // B2_GROWABLE_BUFFER_H
void Free(void *p, int32 size)
Free memory. This uses b2Free if the size is larger than b2_maxBlockSize.
Definition: b2BlockAllocator.cpp:163
Definition: b2GrowableBuffer.h:30
Definition: b2BlockAllocator.h:36
#define b2_minParticleSystemBufferCapacity
The initial size of particle data buffers.
Definition: b2Settings.h:194
void * Allocate(int32 size)
Allocate memory. This uses b2Alloc if the size is larger than b2_maxBlockSize.
Definition: b2BlockAllocator.cpp:105