| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Core/TempAllocator.h> |
| 8 |
|
| 9 |
JPH_NAMESPACE_BEGIN |
| 10 |
|
| 11 |
|
| 12 |
template <typename T> |
| 13 |
class STLTempAllocator |
| 14 |
{ |
| 15 |
public: |
| 16 |
using value_type = T; |
| 17 |
|
| 18 |
|
| 19 |
using pointer = T *; |
| 20 |
using const_pointer = const T *; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
using reference = T &; |
| 25 |
using const_reference = const T &; |
| 26 |
|
| 27 |
using size_type = size_t; |
| 28 |
using difference_type = ptrdiff_t; |
| 29 |
|
| 30 |
|
| 31 |
using is_always_equal = std::false_type; |
| 32 |
|
| 33 |
|
| 34 |
inline STLTempAllocator(TempAllocator &inAllocator) : mAllocator(inAllocator) { } |
| 35 |
|
| 36 |
|
| 37 |
template <typename T2> |
| 38 |
inline explicit STLTempAllocator(const STLTempAllocator<T2> &inRHS) : mAllocator(inRHS.GetAllocator()) { } |
| 39 |
|
| 40 |
|
| 41 |
inline pointer allocate(size_type inN) |
| 42 |
{ |
| 43 |
return pointer(mAllocator.Allocate(uint(inN * sizeof(value_type)))); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
inline void deallocate(pointer inPointer, size_type inN) |
| 48 |
{ |
| 49 |
mAllocator.Free(inPointer, uint(inN * sizeof(value_type))); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
inline bool operator == (const STLTempAllocator<T> &inRHS) const |
| 54 |
{ |
| 55 |
return &mAllocator == &inRHS.mAllocator; |
| 56 |
} |
| 57 |
|
| 58 |
inline bool operator != (const STLTempAllocator<T> &inRHS) const |
| 59 |
{ |
| 60 |
return &mAllocator != &inRHS.mAllocator; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
template <typename T2> |
| 65 |
struct rebind |
| 66 |
{ |
| 67 |
using other = STLTempAllocator<T2>; |
| 68 |
}; |
| 69 |
|
| 70 |
|
| 71 |
TempAllocator & GetAllocator() const |
| 72 |
{ |
| 73 |
return mAllocator; |
| 74 |
} |
| 75 |
|
| 76 |
private: |
| 77 |
TempAllocator & mAllocator; |
| 78 |
}; |
| 79 |
|
| 80 |
JPH_NAMESPACE_END |