ezEngine  Milestone 7
DynamicArray_inl.h
1 
2 template <typename T>
4 {
5  this->m_uiCapacity = 0;
6  m_pAllocator = pAllocator;
7 }
8 
9 template <typename T>
11 {
12  this->m_uiCapacity = 0;
13  m_pAllocator = pAllocator;
14 
15  ezArrayBase<T, ezDynamicArrayBase<T>>::operator=((ezArrayPtr<const T>)other); // redirect this to the ezArrayPtr version
16 }
17 
18 template <typename T>
20 {
21  this->m_uiCapacity = 0;
22  m_pAllocator = pAllocator;
23 
24  *this = std::move(other);
25 }
26 
27 template <typename T>
29 {
30  this->m_uiCapacity = 0;
31  m_pAllocator = pAllocator;
32 
34 }
35 
36 template <typename T>
38 {
39  this->Clear();
40  EZ_DELETE_RAW_BUFFER(this->m_pAllocator, this->m_pElements);
41  this->m_uiCapacity = 0;
42 }
43 
44 template <typename T>
46 {
47  ezArrayBase<T, ezDynamicArrayBase<T>>::operator=((ezArrayPtr<const T>)rhs); // redirect this to the ezArrayPtr version
48 }
49 
50 template <typename T>
52 {
53  if (this->m_pAllocator == rhs.m_pAllocator)
54  {
55  // clear any existing data
56  this->Clear();
57  EZ_DELETE_RAW_BUFFER(this->m_pAllocator, this->m_pElements);
58 
59  // move the data over from the other array
60  this->m_uiCount = rhs.m_uiCount;
61  this->m_uiCapacity = rhs.m_uiCapacity;
62  this->m_pElements = rhs.m_pElements;
63 
64  // reset the other array to not reference the data anymore
65  rhs.m_pElements = nullptr;
66  rhs.m_uiCount = 0;
67  rhs.m_uiCapacity = 0;
68  }
69  else
70  {
71  ezArrayBase<T, ezDynamicArrayBase<T>>::operator=((ezArrayPtr<const T>)rhs); // redirect this to the ezArrayPtr version
72  rhs.Clear();
73  }
74 }
75 
76 template <typename T>
77 void ezDynamicArrayBase<T>::SetCapacity(ezUInt32 uiCapacity)
78 {
79  this->m_uiCapacity = uiCapacity;
80  this->m_pElements = EZ_EXTEND_RAW_BUFFER(this->m_pAllocator, this->m_pElements, this->m_uiCount, this->m_uiCapacity);
81 }
82 
83 template <typename T>
84 void ezDynamicArrayBase<T>::Reserve(ezUInt32 uiCapacity)
85 {
86  if (this->m_uiCapacity >= uiCapacity)
87  return;
88 
89  ezUInt32 uiNewCapacity = ezMath::Max(this->m_uiCapacity + (this->m_uiCapacity / 2), uiCapacity);
90  uiNewCapacity = (uiNewCapacity + (CAPACITY_ALIGNMENT - 1)) & ~(CAPACITY_ALIGNMENT - 1);
91  SetCapacity(uiNewCapacity);
92 }
93 
94 template <typename T>
96 {
97  if (this->IsEmpty())
98  {
99  // completely deallocate all data, if the array is empty.
100  EZ_DELETE_RAW_BUFFER(this->m_pAllocator, this->m_pElements);
101  this->m_uiCapacity = 0;
102  }
103  else
104  {
105  const ezUInt32 uiNewCapacity = (this->m_uiCount + (CAPACITY_ALIGNMENT - 1)) & ~(CAPACITY_ALIGNMENT - 1);
106  if (this->m_uiCapacity != uiNewCapacity)
107  SetCapacity(uiNewCapacity);
108  }
109 }
110 
111 template <typename T>
113 {
114  return (ezUInt64) this->m_uiCapacity * (ezUInt64) sizeof(T);
115 }
116 
117 template <typename T, typename A>
119 {
120 }
121 
122 template <typename T, typename A>
124 {
125 }
126 
127 template <typename T, typename A>
128 ezDynamicArray<T, A>::ezDynamicArray(const ezDynamicArray<T, A>& other) : ezDynamicArrayBase<T>(other, A::GetAllocator())
129 {
130 }
131 
132 template <typename T, typename A>
133 ezDynamicArray<T, A>::ezDynamicArray(const ezDynamicArrayBase<T>& other) : ezDynamicArrayBase<T>(other, A::GetAllocator())
134 {
135 }
136 
137 template <typename T, typename A>
138 ezDynamicArray<T, A>::ezDynamicArray(const ezArrayPtr<const T>& other) : ezDynamicArrayBase<T>(other, A::GetAllocator())
139 {
140 }
141 
142 template <typename T, typename A>
143 ezDynamicArray<T, A>::ezDynamicArray(ezDynamicArray<T, A>&& other) : ezDynamicArrayBase<T>(std::move(other), A::GetAllocator())
144 {
145 }
146 
147 template <typename T, typename A>
148 ezDynamicArray<T, A>::ezDynamicArray(ezDynamicArrayBase<T>&& other) : ezDynamicArrayBase<T>(std::move(other), A::GetAllocator())
149 {
150 }
151 
152 template <typename T, typename A>
154 {
156 }
157 
158 template <typename T, typename A>
160 {
162 }
163 
164 template <typename T, typename A>
166 {
167  ezArrayBase<T, ezDynamicArrayBase<T>>::operator=(rhs);
168 }
169 
170 template <typename T, typename A>
172 {
173  ezDynamicArrayBase<T>::operator=(std::move(rhs));
174 }
175 
176 template <typename T, typename A>
178 {
179  ezDynamicArrayBase<T>::operator=(std::move(rhs));
180 }
181