| 15 | /// <typeparam name="AllocationType">The type of memory allocator.</typeparam> |
| 16 | template<typename T, typename AllocationType = HeapAllocation> |
| 17 | API_CLASS(InBuild) class Array |
| 18 | { |
| 19 | friend Array; |
| 20 | public: |
| 21 | using ItemType = T; |
| 22 | using AllocationData = typename AllocationType::template Data<T>; |
| 23 | using AllocationTag = typename AllocationType::Tag; |
| 24 | |
| 25 | private: |
| 26 | int32 _count; |
| 27 | int32 _capacity; |
| 28 | AllocationData _allocation; |
| 29 | |
| 30 | public: |
| 31 | /// <summary> |
| 32 | /// Initializes an empty <see cref="Array"/> without reserving any space. |
| 33 | /// </summary> |
| 34 | FORCE_INLINE Array() |
| 35 | : _count(0) |
| 36 | , _capacity(0) |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | /// <summary> |
| 41 | /// Initializes an empty <see cref="Array"/> without reserving any space. |
| 42 | /// </summary> |
| 43 | /// <param name="tag">The custom allocation tag.</param> |
| 44 | Array(AllocationTag tag) |
| 45 | : _count(0) |
| 46 | , _capacity(0) |
| 47 | , _allocation(tag) |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | /// <summary> |
| 52 | /// Initializes <see cref="Array"/> by reserving space. |
| 53 | /// </summary> |
| 54 | /// <param name="capacity">The number of elements that can be added without a need to allocate more memory.</param> |
| 55 | FORCE_INLINE explicit Array(const int32 capacity) |
| 56 | : _count(0) |
| 57 | , _capacity(capacity) |
| 58 | { |
| 59 | if (capacity > 0) |
| 60 | _allocation.Allocate(capacity); |
| 61 | } |
| 62 | |
| 63 | /// <summary> |
| 64 | /// Initializes <see cref="Array"/> by copying elements. |
| 65 | /// </summary> |
| 66 | /// <param name="data">The initial data.</param> |
| 67 | /// <param name="length">The amount of items.</param> |
| 68 | Array(const T* data, const int32 length) |
| 69 | { |
| 70 | ASSERT(length >= 0); |
| 71 | _count = _capacity = length; |
| 72 | if (length > 0) |
| 73 | { |
| 74 | _allocation.Allocate(length); |