77 inline void*
operator new(size_t,
const rcNewTag&,
void* p) {
return p; }
78 inline void operator delete(
void*,
const rcNewTag&,
void*) {}
83 #define RC_SIZE_MAX INTPTR_MAX
87 #if defined(__GNUC__) || defined(__clang__)
88 #define rcLikely(x) __builtin_expect((x), true)
89 #define rcUnlikely(x) __builtin_expect((x), false)
91 #define rcLikely(x) (x)
92 #define rcUnlikely(x) (x)
103 template <
typename T, rcAllocH
int H>
109 static void construct(T* p,
const T& v) { ::new(
rcNewTag(), (
void*)p) T(v); }
110 static void construct(T* p) { ::new(
rcNewTag(), (
void*)p) T; }
111 static void construct_range(T*
begin, T*
end);
112 static void construct_range(T*
begin, T*
end,
const T& value);
113 static void copy_range(T* dst,
const T*
begin,
const T*
end);
140 void clear() { destroy_range(0, m_size); m_size = 0; }
156 const T*
data()
const {
return m_data; }
160 T*
end() {
return m_data + m_size; }
161 const T*
begin()
const {
return m_data; }
162 const T*
end()
const {
return m_data + m_size; }
170 template<
typename T, rcAllocH
int H>
172 if (count <= m_cap) {
175 T* new_data = allocate_and_copy(count);
179 destroy_range(0, m_size);
185 template <
typename T, rcAllocH
int H>
188 T* new_data =
static_cast<T*
>(
rcAlloc(
sizeof(T) * size, H));
190 copy_range(new_data, m_data, m_data + m_size);
194 template <
typename T, rcAllocH
int H>
197 reserve(end - begin);
198 m_size = end - begin;
199 copy_range(m_data, begin, end);
201 template <
typename T, rcAllocH
int H>
206 construct(m_data + m_size++, value);
210 const rcSizeType new_cap = get_new_capacity(m_cap + 1);
211 T* data = allocate_and_copy(new_cap);
214 construct(data + m_size, value);
215 destroy_range(0, m_size);
222 template <
typename T, rcAllocH
int H>
227 return 2 * m_cap > min_capacity ? 2 * m_cap : min_capacity;
230 template <
typename T, rcAllocH
int H>
233 destroy_range(size, m_size);
235 }
else if (size > m_size) {
238 construct_range(m_data + m_size, m_data + size, *value);
240 construct_range(m_data + m_size, m_data + size);
244 const rcSizeType new_cap = get_new_capacity(size);
245 T* new_data = allocate_and_copy(new_cap);
249 construct_range(new_data + m_size, new_data + size, *value);
251 construct_range(new_data + m_size, new_data + size);
253 destroy_range(0, m_size);
261 template <
typename T, rcAllocH
int H>
266 T* tmp_data = other.m_data;
269 other.m_size = m_size;
270 other.m_data = m_data;
277 template <
typename T, rcAllocH
int H>
279 for (T* p = begin; p < end; p++) {
284 template <
typename T, rcAllocH
int H>
286 for (T* p = begin; p < end; p++) {
291 template <
typename T, rcAllocH
int H>
293 for (
rcSizeType i = 0 ; i < end - begin; i++) {
294 construct(dst + i, begin[i]);
297 template <
typename T, rcAllocH
int H>
304 template <
typename T>
314 template <
typename T>
338 int v = m_impl.
back();
342 int size()
const {
return static_cast<int>(m_impl.
size()); }
364 inline operator T*() {
return ptr; }
rcAllocHint
Provides hint values to the memory allocator on how long the memory is expected to be used.
Definition: RecastAlloc.h:30
@ RC_ALLOC_TEMP
Memory used temporarily within a function.
Definition: RecastAlloc.h:32
@ RC_ALLOC_PERM
Memory will persist after a function call.
Definition: RecastAlloc.h:31
intptr_t rcSizeType
Signed to avoid warnings when comparing to int loop indexes, and common error with comparing to zero.
Definition: RecastAlloc.h:82
void() rcFreeFunc(void *ptr)
A memory deallocation function.
Definition: RecastAlloc.h:45
void *() rcAllocFunc(size_t size, rcAllocHint hint)
A memory allocation function.
Definition: RecastAlloc.h:40
void rcFree(void *ptr)
Deallocates a memory block.
Definition: RecastAlloc.cpp:45
#define RC_SIZE_MAX
Definition: RecastAlloc.h:83
#define rcUnlikely(x)
Definition: RecastAlloc.h:92
void * rcAlloc(size_t size, rcAllocHint hint)
Allocates a memory block.
Definition: RecastAlloc.cpp:40
#define rcLikely(x)
Macros to hint to the compiler about the likeliest branch.
Definition: RecastAlloc.h:91
void rcAllocSetCustom(rcAllocFunc *allocFunc, rcFreeFunc *freeFunc)
Sets the base custom allocation functions to be used by Recast.
Definition: RecastAlloc.cpp:34
#define rcAssert(expression)
Definition: RecastAssert.h:44
Legacy class. Prefer rcVector<int>.
Definition: RecastAlloc.h:328
void clear()
Definition: RecastAlloc.h:335
int pop()
Definition: RecastAlloc.h:336
int & operator[](int index)
Definition: RecastAlloc.h:343
void resize(int size)
Definition: RecastAlloc.h:334
rcIntArray()
Definition: RecastAlloc.h:331
int operator[](int index) const
Definition: RecastAlloc.h:344
rcIntArray(int n)
Definition: RecastAlloc.h:332
void push(int item)
Definition: RecastAlloc.h:333
int size() const
Definition: RecastAlloc.h:342
Definition: RecastAlloc.h:315
rcPermVector()
Definition: RecastAlloc.h:318
rcPermVector(const rcPermVector< T > &other)
Definition: RecastAlloc.h:321
rcPermVector(rcSizeType size, const T &value)
Definition: RecastAlloc.h:320
rcPermVector(const T *begin, const T *end)
Definition: RecastAlloc.h:322
rcPermVector(rcSizeType size)
Definition: RecastAlloc.h:319
A simple helper class used to delete an array when it goes out of scope.
Definition: RecastAlloc.h:350
rcScopedDelete()
Constructs an instance with a null pointer.
Definition: RecastAlloc.h:355
rcScopedDelete(T *p)
Constructs an instance with the specified pointer.
Definition: RecastAlloc.h:359
~rcScopedDelete()
Definition: RecastAlloc.h:360
Definition: RecastAlloc.h:305
rcTempVector(rcSizeType size)
Definition: RecastAlloc.h:309
rcTempVector(const rcTempVector< T > &other)
Definition: RecastAlloc.h:311
rcTempVector(const T *begin, const T *end)
Definition: RecastAlloc.h:312
rcTempVector(rcSizeType size, const T &value)
Definition: RecastAlloc.h:310
rcTempVector()
Definition: RecastAlloc.h:308
Variable-sized storage type.
Definition: RecastAlloc.h:104
bool reserve(rcSizeType size)
Definition: RecastAlloc.h:171
void resize(rcSizeType size, const T &value)
Definition: RecastAlloc.h:138
T * end()
Definition: RecastAlloc.h:160
const T * data() const
Definition: RecastAlloc.h:156
rcSizeType capacity() const
Definition: RecastAlloc.h:146
void assign(const T *begin, const T *end)
Definition: RecastAlloc.h:195
rcSizeType size_type
Definition: RecastAlloc.h:121
rcVectorBase(rcSizeType count)
Definition: RecastAlloc.h:126
T & operator[](rcSizeType i)
Definition: RecastAlloc.h:150
void pop_back()
Definition: RecastAlloc.h:143
void resize(rcSizeType size)
Definition: RecastAlloc.h:137
rcVectorBase()
Definition: RecastAlloc.h:124
const T & back() const
Definition: RecastAlloc.h:154
rcVectorBase(const rcVectorBase< T, H > &other)
Definition: RecastAlloc.h:125
~rcVectorBase()
Definition: RecastAlloc.h:129
T value_type
Definition: RecastAlloc.h:122
T * data()
Definition: RecastAlloc.h:157
void push_back(const T &value)
Definition: RecastAlloc.h:202
const T & operator[](rcSizeType i) const
Definition: RecastAlloc.h:149
rcVectorBase(const T *begin, const T *end)
Definition: RecastAlloc.h:128
T * begin()
Definition: RecastAlloc.h:159
const T & front() const
Definition: RecastAlloc.h:152
const T * begin() const
Definition: RecastAlloc.h:161
rcVectorBase(rcSizeType count, const T &value)
Definition: RecastAlloc.h:127
bool empty() const
Definition: RecastAlloc.h:147
void clear()
Definition: RecastAlloc.h:140
rcSizeType size() const
Definition: RecastAlloc.h:145
const T * end() const
Definition: RecastAlloc.h:162
T & front()
Definition: RecastAlloc.h:153
void swap(rcVectorBase< T, H > &other)
Definition: RecastAlloc.h:262
T & back()
Definition: RecastAlloc.h:155
void assign(rcSizeType count, const T &value)
Definition: RecastAlloc.h:134
rcVectorBase & operator=(const rcVectorBase< T, H > &other)
An implementation of operator new usable for placement new.
Definition: RecastAlloc.h:76