CommonLibSSE NG
Loading...
Searching...
No Matches
NiTArray.h
Go to the documentation of this file.
1#pragma once
2
5
6namespace RE
7{
8 template <class T, class Allocator>
9 class NiTArray
10 {
11 public:
12 using value_type = T;
13 using allocator_type = Allocator;
14 using size_type = std::uint16_t;
17 using iterator = T*;
18 using const_iterator = const T*;
19
20 NiTArray(std::uint32_t a_maxSize = 0, std::uint32_t a_growBy = 1) :
21 _data(0),
22 _capacity(static_cast<std::uint16_t>(a_maxSize)),
23 _freeIdx(0),
24 _size(0),
25 _growthSize(static_cast<std::uint16_t>(a_growBy))
26 {
27 if (_capacity > 0) {
28 _data = allocator_type::Allocate(_capacity);
29 }
30 }
31
32 virtual ~NiTArray() // 00
33 {
34 allocator_type::Deallocate(_data);
35 }
36
38 {
39 assert(a_pos < capacity());
40 return _data[a_pos];
41 }
42
44 {
45 assert(a_pos < capacity());
46 return _data[a_pos];
47 }
48
50 {
51 return operator[](0);
52 }
53
54 [[nodiscard]] const_reference front() const
55 {
56 return operator[](0);
57 }
58
60 {
61 return operator[](capacity() - 1);
62 }
63
64 [[nodiscard]] const_reference back() const
65 {
66 return operator[](capacity() - 1);
67 }
68
70 {
71 return _data;
72 }
73
74 [[nodiscard]] const_iterator begin() const
75 {
76 return _data;
77 }
78
79 [[nodiscard]] const_iterator cbegin() const
80 {
81 return _data;
82 }
83
85 {
86 return _data + _capacity;
87 }
88
89 [[nodiscard]] const_iterator end() const
90 {
91 return _data + _capacity;
92 }
93
94 [[nodiscard]] const_iterator cend() const
95 {
96 return _data + _capacity;
97 }
98
99 [[nodiscard]] bool empty() const
100 {
101 return _capacity == 0;
102 }
103
104 [[nodiscard]] size_type size() const
105 {
106 return _size;
107 }
108
109 [[nodiscard]] size_type capacity() const
110 {
111 return _capacity;
112 }
113
114 private:
115 // members
116 T* _data; // 08
117 std::uint16_t _capacity; // 10
118 std::uint16_t _freeIdx; // 12
119 std::uint16_t _size; // 14
120 std::uint16_t _growthSize; // 16
121 };
122 static_assert(sizeof(NiTArray<void*, NiTMallocInterface<void*>>) == 0x18);
123
124 template <class T>
125 class NiTObjectArray : public NiTArray<T, NiTNewInterface<T>>
126 {
127 public:
128 NiTObjectArray(std::uint32_t a_maxSize = 0, std::uint32_t a_growBy = 1) :
129 NiTArray<T, NiTNewInterface<T>>(a_maxSize, a_growBy)
130 {}
131 };
132 static_assert(sizeof(NiTObjectArray<void*>) == 0x18);
133
134 template <class T>
135 class NiTPrimitiveArray : public NiTArray<T, NiTMallocInterface<T>>
136 {
137 public:
138 NiTPrimitiveArray(std::uint32_t a_maxSize = 0, std::uint32_t a_growBy = 1) :
139 NiTArray<T, NiTMallocInterface<T>>(a_maxSize, a_growBy)
140 {}
141 };
142 static_assert(sizeof(NiTPrimitiveArray<void*>) == 0x18);
143
144 template <class T, class Allocator>
146 {
147 public:
148 using value_type = T;
149 using allocator_type = Allocator;
150 using size_type = std::uint32_t;
153 using iterator = T*;
154 using const_iterator = const T*;
155
156 NiTLargeArray(std::uint32_t a_maxSize = 0, std::uint32_t a_growBy = 1) :
157 _data(0),
158 _capacity(a_maxSize),
159 _freeIdx(0),
160 _size(0),
161 _growthSize(a_growBy)
162 {
163 if (_capacity > 0) {
164 _data = allocator_type::Allocate(_capacity);
165 }
166 }
167
168 virtual ~NiTLargeArray() // 00
169 {
170 allocator_type::Deallocate(_data);
171 }
172
174 {
175 assert(a_pos < size());
176 return _data[a_pos];
177 }
178
180 {
181 assert(a_pos < size());
182 return _data[a_pos];
183 }
184
186 {
187 return operator[](0);
188 }
189
190 [[nodiscard]] const_reference front() const
191 {
192 return operator[](0);
193 }
194
196 {
197 return operator[](size() - 1);
198 }
199
200 [[nodiscard]] const_reference back() const
201 {
202 return operator[](size() - 1);
203 }
204
206 {
207 return _data;
208 }
209
210 [[nodiscard]] const_iterator begin() const
211 {
212 return _data;
213 }
214
215 [[nodiscard]] const_iterator cbegin() const
216 {
217 return _data;
218 }
219
221 {
222 return _data + _size;
223 }
224
225 [[nodiscard]] const_iterator end() const
226 {
227 return _data + _size;
228 }
229
230 [[nodiscard]] const_iterator cend() const
231 {
232 return _data + _size;
233 }
234
235 [[nodiscard]] bool empty() const
236 {
237 return _capacity == 0;
238 }
239
240 [[nodiscard]] size_type size() const
241 {
242 return _size;
243 }
244
245 [[nodiscard]] size_type capacity() const
246 {
247 return _capacity;
248 }
249
250 private:
251 // members
252 T* _data; // 08
253 std::uint32_t _capacity; // 10
254 std::uint32_t _freeIdx; // 14
255 std::uint32_t _size; // 18
256 std::uint32_t _growthSize; // 1C
257 };
258 static_assert(sizeof(NiTLargeArray<void*, NiTMallocInterface<void*>>) == 0x20);
259
260 template <class T>
261 class NiTLargeObjectArray : public NiTLargeArray<T, NiTNewInterface<T>>
262 {
263 public:
264 NiTLargeObjectArray(std::uint32_t a_maxSize = 0, std::uint32_t a_growBy = 1) :
265 NiTLargeArray<T, NiTNewInterface<T>>(a_maxSize, a_growBy)
266 {}
267 };
268 static_assert(sizeof(NiTLargeObjectArray<void*>) == 0x20);
269
270 template <class T>
271 class NiTLargePrimitiveArray : public NiTLargeArray<T, NiTMallocInterface<T>>
272 {
273 public:
274 NiTLargePrimitiveArray(std::uint32_t a_maxSize = 0, std::uint32_t a_growBy = 1) :
275 NiTLargeArray<T, NiTMallocInterface<T>>(a_maxSize, a_growBy)
276 {}
277 };
278 static_assert(sizeof(NiTLargePrimitiveArray<void*>) == 0x20);
279
280 class TESForm;
281 class NiFormArray : public NiTLargePrimitiveArray<TESForm*>
282 {
283 public:
284 };
285 static_assert(sizeof(NiFormArray) == 0x20);
286}
Definition NiTArray.h:282
Definition NiTArray.h:10
virtual ~NiTArray()
Definition NiTArray.h:32
T * iterator
Definition NiTArray.h:17
const_iterator cend() const
Definition NiTArray.h:94
const_iterator end() const
Definition NiTArray.h:89
NiTArray(std::uint32_t a_maxSize=0, std::uint32_t a_growBy=1)
Definition NiTArray.h:20
const_reference operator[](size_type a_pos) const
Definition NiTArray.h:43
reference front()
Definition NiTArray.h:49
const value_type & const_reference
Definition NiTArray.h:16
iterator begin()
Definition NiTArray.h:69
Allocator allocator_type
Definition NiTArray.h:13
bool empty() const
Definition NiTArray.h:99
reference back()
Definition NiTArray.h:59
iterator end()
Definition NiTArray.h:84
const_reference front() const
Definition NiTArray.h:54
std::uint16_t size_type
Definition NiTArray.h:14
reference operator[](size_type a_pos)
Definition NiTArray.h:37
T value_type
Definition NiTArray.h:12
const T * const_iterator
Definition NiTArray.h:18
const_reference back() const
Definition NiTArray.h:64
const_iterator cbegin() const
Definition NiTArray.h:79
value_type & reference
Definition NiTArray.h:15
size_type capacity() const
Definition NiTArray.h:109
size_type size() const
Definition NiTArray.h:104
const_iterator begin() const
Definition NiTArray.h:74
Definition NiTArray.h:146
size_type capacity() const
Definition NiTArray.h:245
value_type & reference
Definition NiTArray.h:151
reference back()
Definition NiTArray.h:195
reference front()
Definition NiTArray.h:185
const_reference operator[](size_type a_pos) const
Definition NiTArray.h:179
const value_type & const_reference
Definition NiTArray.h:152
const_reference front() const
Definition NiTArray.h:190
T value_type
Definition NiTArray.h:148
std::uint32_t size_type
Definition NiTArray.h:150
const T * const_iterator
Definition NiTArray.h:154
const_iterator cend() const
Definition NiTArray.h:230
iterator end()
Definition NiTArray.h:220
const_reference back() const
Definition NiTArray.h:200
const_iterator cbegin() const
Definition NiTArray.h:215
Allocator allocator_type
Definition NiTArray.h:149
virtual ~NiTLargeArray()
Definition NiTArray.h:168
const_iterator begin() const
Definition NiTArray.h:210
reference operator[](size_type a_pos)
Definition NiTArray.h:173
iterator begin()
Definition NiTArray.h:205
const_iterator end() const
Definition NiTArray.h:225
NiTLargeArray(std::uint32_t a_maxSize=0, std::uint32_t a_growBy=1)
Definition NiTArray.h:156
size_type size() const
Definition NiTArray.h:240
bool empty() const
Definition NiTArray.h:235
T * iterator
Definition NiTArray.h:153
Definition NiTArray.h:262
NiTLargeObjectArray(std::uint32_t a_maxSize=0, std::uint32_t a_growBy=1)
Definition NiTArray.h:264
Definition NiTArray.h:272
NiTLargePrimitiveArray(std::uint32_t a_maxSize=0, std::uint32_t a_growBy=1)
Definition NiTArray.h:274
Definition NiTCollection.h:32
Definition NiTCollection.h:47
Definition NiTArray.h:126
NiTObjectArray(std::uint32_t a_maxSize=0, std::uint32_t a_growBy=1)
Definition NiTArray.h:128
Definition NiTArray.h:136
NiTPrimitiveArray(std::uint32_t a_maxSize=0, std::uint32_t a_growBy=1)
Definition NiTArray.h:138
Definition AbsorbEffect.h:6
Definition ActorValueList.h:28