10 #ifndef EASTL_CORE_ALLOCATOR_ADAPTER_H
11 #define EASTL_CORE_ALLOCATOR_ADAPTER_H
13 #if EASTL_CORE_ALLOCATOR_ENABLED
16 #include <EASTL/internal/config.h>
18 #if defined(EA_PRAGMA_ONCE_SUPPORTED)
29 #ifndef EASTL_CORE_ALLOCATOR_ADAPTER_GET_DEFAULT_CORE_ALLOCATOR
30 #define EASTL_CORE_ALLOCATOR_ADAPTER_GET_DEFAULT_CORE_ALLOCATOR AllocatorType::GetDefaultAllocator
81 template<
class AllocatorType>
82 class CoreAllocatorAdapter
85 typedef CoreAllocatorAdapter<AllocatorType> this_type;
89 CoreAllocatorAdapter(
const char* pName = EASTL_NAME_VAL(EASTL_ALLOCATOR_DEFAULT_NAME), AllocatorType* pAllocator = EASTL_CORE_ALLOCATOR_ADAPTER_GET_DEFAULT_CORE_ALLOCATOR());
90 CoreAllocatorAdapter(
const char* pName, AllocatorType* pAllocator,
int flags);
91 CoreAllocatorAdapter(
const CoreAllocatorAdapter& x);
92 CoreAllocatorAdapter(
const CoreAllocatorAdapter& x,
const char* pName);
94 CoreAllocatorAdapter& operator=(
const CoreAllocatorAdapter& x);
96 void* allocate(
size_t n,
int flags = 0);
97 void* allocate(
size_t n,
size_t alignment,
size_t offset,
int flags = 0);
98 void deallocate(
void* p,
size_t n);
100 AllocatorType* get_allocator()
const;
101 void set_allocator(AllocatorType* pAllocator);
103 int get_flags()
const;
104 void set_flags(
int flags);
106 const char* get_name()
const;
107 void set_name(
const char* pName);
110 AllocatorType* mpCoreAllocator;
113 #if EASTL_NAME_ENABLED
118 template<
class AllocatorType>
119 bool operator==(
const CoreAllocatorAdapter<AllocatorType>& a,
const CoreAllocatorAdapter<AllocatorType>& b);
121 template<
class AllocatorType>
122 bool operator!=(
const CoreAllocatorAdapter<AllocatorType>& a,
const CoreAllocatorAdapter<AllocatorType>& b);
134 class ICoreAllocator;
135 class EASTLCoreAllocatorImpl;
137 typedef CoreAllocatorAdapter<ICoreAllocator> EASTLICoreAllocatorAdapter;
138 typedef CoreAllocatorAdapter<EASTLCoreAllocatorImpl> EASTLCoreAllocatorAdapter;
139 typedef EASTLICoreAllocatorAdapter EASTLICoreAllocator;
150 template <
class AllocatorType>
151 class CoreDeleterAdapter
154 typedef CoreDeleterAdapter<AllocatorType> this_type;
155 AllocatorType* mpCoreAllocator;
158 CoreDeleterAdapter(AllocatorType* pAllocator = EASTL_CORE_ALLOCATOR_ADAPTER_GET_DEFAULT_CORE_ALLOCATOR()) EA_NOEXCEPT
159 : mpCoreAllocator(pAllocator) {}
161 ~CoreDeleterAdapter() EA_NOEXCEPT {}
163 template <
typename T>
164 void operator()(T* p)
167 mpCoreAllocator->Free(p);
170 CoreDeleterAdapter(
const CoreDeleterAdapter& in) { mpCoreAllocator = in.mpCoreAllocator; }
172 CoreDeleterAdapter(CoreDeleterAdapter&& in)
174 mpCoreAllocator = in.mpCoreAllocator;
175 in.mpCoreAllocator =
nullptr;
178 CoreDeleterAdapter& operator=(
const CoreDeleterAdapter& in)
180 mpCoreAllocator = in.mpCoreAllocator;
184 CoreDeleterAdapter& operator=(CoreDeleterAdapter&& in)
186 mpCoreAllocator = in.mpCoreAllocator;
187 in.mpCoreAllocator =
nullptr;
201 typedef CoreDeleterAdapter<ICoreAllocator> EASTLICoreDeleterAdapter;
202 typedef CoreDeleterAdapter<EASTLCoreAllocatorImpl> EASTLCoreDeleterAdapter;
220 template<
class AllocatorType>
221 inline CoreAllocatorAdapter<AllocatorType>::CoreAllocatorAdapter(
const char* EASTL_NAME(pName), AllocatorType* pCoreAllocator)
222 : mpCoreAllocator(pCoreAllocator), mnFlags(0)
224 #if EASTL_NAME_ENABLED
225 mpName = pName ? pName : EASTL_ALLOCATOR_DEFAULT_NAME;
229 template<
class AllocatorType>
230 inline CoreAllocatorAdapter<AllocatorType>::CoreAllocatorAdapter(
const char* EASTL_NAME(pName), AllocatorType* pCoreAllocator,
int flags)
231 : mpCoreAllocator(pCoreAllocator), mnFlags(flags)
233 #if EASTL_NAME_ENABLED
234 mpName = pName ? pName : EASTL_ALLOCATOR_DEFAULT_NAME;
238 template<
class AllocatorType>
239 inline CoreAllocatorAdapter<AllocatorType>::CoreAllocatorAdapter(
const CoreAllocatorAdapter& x)
240 : mpCoreAllocator(x.mpCoreAllocator), mnFlags(x.mnFlags)
242 #if EASTL_NAME_ENABLED
247 template<
class AllocatorType>
248 inline CoreAllocatorAdapter<AllocatorType>::CoreAllocatorAdapter(
const CoreAllocatorAdapter& x,
const char* EASTL_NAME(pName))
249 : mpCoreAllocator(x.mpCoreAllocator), mnFlags(x.mnFlags)
251 #if EASTL_NAME_ENABLED
252 mpName = pName ? pName : EASTL_ALLOCATOR_DEFAULT_NAME;
256 template<
class AllocatorType>
257 inline CoreAllocatorAdapter<AllocatorType>& CoreAllocatorAdapter<AllocatorType>::operator=(
const CoreAllocatorAdapter& x)
259 mpCoreAllocator = x.mpCoreAllocator;
262 #if EASTL_NAME_ENABLED
269 template<
class AllocatorType>
270 inline void* CoreAllocatorAdapter<AllocatorType>::allocate(
size_t n,
int )
275 return mpCoreAllocator->Alloc(n, EASTL_NAME_VAL(mpName), (
unsigned)mnFlags);
278 template<
class AllocatorType>
279 inline void* CoreAllocatorAdapter<AllocatorType>::allocate(
size_t n,
size_t alignment,
size_t offset,
int )
284 return mpCoreAllocator->Alloc(n, EASTL_NAME_VAL(mpName), (
unsigned)mnFlags, (
unsigned)alignment, (
unsigned)offset);
287 template<
class AllocatorType>
288 inline void CoreAllocatorAdapter<AllocatorType>::deallocate(
void* p,
size_t n)
290 return mpCoreAllocator->Free(p, n);
293 template<
class AllocatorType>
294 inline AllocatorType* CoreAllocatorAdapter<AllocatorType>::get_allocator()
const
296 return mpCoreAllocator;
299 template<
class AllocatorType>
300 inline void CoreAllocatorAdapter<AllocatorType>::set_allocator(AllocatorType* pAllocator)
302 mpCoreAllocator = pAllocator;
305 template<
class AllocatorType>
306 inline int CoreAllocatorAdapter<AllocatorType>::get_flags()
const
311 template<
class AllocatorType>
312 inline void CoreAllocatorAdapter<AllocatorType>::set_flags(
int flags)
317 template<
class AllocatorType>
318 inline const char* CoreAllocatorAdapter<AllocatorType>::get_name()
const
320 #if EASTL_NAME_ENABLED
323 return EASTL_ALLOCATOR_DEFAULT_NAME;
327 template<
class AllocatorType>
328 inline void CoreAllocatorAdapter<AllocatorType>::set_name(
const char* pName)
330 #if EASTL_NAME_ENABLED
339 template<
class AllocatorType>
340 inline bool operator==(
const CoreAllocatorAdapter<AllocatorType>& a,
const CoreAllocatorAdapter<AllocatorType>& b)
342 return (a.mpCoreAllocator == b.mpCoreAllocator) &&
343 (a.mnFlags == b.mnFlags);
346 template<
class AllocatorType>
347 inline bool operator!=(
const CoreAllocatorAdapter<AllocatorType>& a,
const CoreAllocatorAdapter<AllocatorType>& b)
349 return (a.mpCoreAllocator != b.mpCoreAllocator) ||
350 (a.mnFlags != b.mnFlags);