gwnavruntime/containers/kyarray.h Source File

kyarray.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 
8 #ifndef Navigation_KyArray_H
9 #define Navigation_KyArray_H
10 
13 
14 
15 namespace Kaim
16 {
17 
18 // Gameware Navigation array generic interface
19 //
20 // **************************
21 // - UPInt GetSize() const;
22 // - bool IsEmpty() const;
23 // - UPInt GetCapacity() const;
24 // - UPInt GetNumBytes() const;
25 //
26 // void ClearAndRelease();
27 // void Clear();
28 // void Resize(UPInt newSize);
29 //
30 // void Reserve(UPInt newCapacity);
31 //
32 // // Basic access.
33 // ValueType& At(UPInt index);
34 // const ValueType& At(UPInt index); const
35 // ValueType ValueAt(UPInt index) const;
36 // ValueType& operator [] (UPInt index);
37 // const ValueType& operator [] (UPInt index) const;
38 //
39 // // Raw pointer to the data. Use with caution!
40 // const ValueType* GetDataPtr() const;
41 // ValueType* GetDataPtr();
42 //
43 // // Insert the given element at the end of the array.
44 // void PushBack(const ValueType& val);
45 // template<class S>
46 // void PushBackAlt(const S& val);
47 //
48 // // Remove the last element.
49 // void PopBack(UPInt count = 1);
50 // ValueType& PushDefault();
51 //
52 // ValueType Pop();
53 //
54 // // Access the first element.
55 // ValueType& Front();
56 // const ValueType& Front() const;
57 //
58 // // Access the last element.
59 // ValueType& Back();
60 // const ValueType& Back() const;
61 //
62 // // Array copy. Copies the contents of a into this array.
63 // const SelfType& operator = (const SelfType& a);
64 //
65 // // Removing multiple elements from the array.
66 // void RemoveMultipleAt(UPInt index, UPInt num);
67 //
68 // // Removing an element from the array is an expensive operation!
69 // // It compacts only after removing the last element.
70 // void RemoveAt(UPInt index);
71 // // Insert the given object at the given index shifting all the elements up.
72 // void InsertAt(UPInt index, const ValueType& val = ValueType());
73 // // Insert the given object at the given index shifting all the elements up.
74 // void InsertMultipleAt(UPInt index, UPInt num, const ValueType& val = ValueType());
75 // // Append the given data to the array.
76 // void Append(const SelfType& other);
77 // // Append the given data to the array.
78 // void Append(const ValueType other[], UPInt count);
79 //
80 // bool DoesContain(const ValueType& value) const;
81 // void RemoveConsecutiveDuplicates();
82 // **************************
83 // // Gameware Navigation array different type
84 // - KyArray :
85 // General purpose array for movable objects that require explicit
86 // construction/destruction. Global heap is in use.
87 // - KyArrayPOD
88 // General purpose array for movable objects that DOES NOT require
89 // construction/destruction. Constructors and destructors are not called!
90 // Global heap is in use.
91 // - KyArrayLH
92 // General purpose array for movable objects that require explicit
93 // construction/destruction. Local heap is in use.
94 // - KyArrayLH_POD
95 // General purpose array for movable objects that DOES NOT require
96 // construction/destruction. Constructors and destructors are not called!
97 // Local heap is in use.
98 // - KyArrayDH
99 // General purpose array for movable objects that require explicit
100 // construction/destruction. Dynamic heap is in use.
101 // - KyArrayDH_POD
102 // General purpose array for movable objects that DOES NOT require
103 // construction/destruction. Constructors and destructors are not called!
104 // Dynamic heap is in use.
105 
106 
107 
108 // ---- KyArrayDefaultPolicy ----
111 typedef ArrayConstPolicy<0, 4, true> KyArrayDefaultPolicy;
112 
113 
114 // ---- KyArray ----
117 template<class T, int SID=Stat_Default_Mem, class SizePolicy=KyArrayDefaultPolicy>
118 class KyArray : public Array<T, SID, SizePolicy>
119 {
120 public:
121  // ---------------------------------- Public typedef ----------------------------------
122 
123  typedef T ValueType;
125  typedef Array<T, SID, SizePolicy> BaseType;
126 
127 
128  // ---------------------------------- Public Member Functions ----------------------------------
129 
130  KyArray() : BaseType() {}
131  explicit KyArray(int size) : BaseType(size) {}
132  KyArray(const SelfType& a) : BaseType(a) {}
133  const SelfType& operator=(const SelfType& a) { BaseType::operator=(a); return *this; }
134 
135  KyUInt32 GetCount() const { return (KyUInt32)BaseType::GetSize(); }
136 
137  bool DoesContain(const ValueType& value) const;
138  void RemoveConsecutiveDuplicates();
139 };
140 
141 
142 // ---- KyArrayPOD ----
146 template<class T, int SID=Stat_Default_Mem, class SizePolicy=KyArrayDefaultPolicy>
147 class KyArrayPOD : public ArrayPOD<T, SID, SizePolicy>
148 {
149 public:
150  // ---------------------------------- Public typedef ----------------------------------
151 
152  typedef T ValueType;
153  typedef KyArrayPOD<T, SID, SizePolicy> SelfType;
154  typedef ArrayPOD<T, SID, SizePolicy> BaseType;
155 
157  // ---------------------------------- Public Member Functions ----------------------------------
158 
159  KyArrayPOD() : BaseType() {}
160  explicit KyArrayPOD(int size) : BaseType(size) {}
161  KyArrayPOD(const SelfType& a) : BaseType(a) {}
162  const SelfType& operator=(const SelfType& a) { BaseType::operator=(a); return *this; }
163 
164  KyUInt32 GetCount() const { return (KyUInt32)BaseType::GetSize(); }
165  bool DoesContain(const ValueType& value) const;
166  void RemoveConsecutiveDuplicates();
167 };
168 
169 // ---- KyArrayLH ----
172 template<class T, int SID=Stat_Default_Mem, class SizePolicy=KyArrayDefaultPolicy>
173 class KyArrayLH : public ArrayLH<T, SID, SizePolicy>
174 {
175 public:
176  // ---------------------------------- Public typedef ----------------------------------
177 
178  typedef T ValueType;
179  typedef KyArrayLH<T, SID, SizePolicy> SelfType;
180  typedef ArrayLH<T, SID, SizePolicy> BaseType;
181 
182 
183  // ---------------------------------- Public Member Functions ----------------------------------
184 
185  KyArrayLH() : BaseType() {}
186  explicit KyArrayLH(int size) : BaseType(size) {}
187  KyArrayLH(const SelfType& a) : BaseType(a) {}
188  const SelfType& operator=(const SelfType& a) { BaseType::operator=(a); return *this; }
189 
190  KyUInt32 GetCount() const { return (KyUInt32)BaseType::GetSize(); }
191  bool DoesContain(const ValueType& value) const;
192  void RemoveConsecutiveDuplicates();
193 };
194 
195 // ---- KyArrayCPP ----
196 // General purpose fully C++ compliant array. Can be used with non-movable data.
197 // Global heap is in use.
198 template<class T, int SID=Stat_Default_Mem, class SizePolicy=KyArrayDefaultPolicy>
199 class KyArrayCPP : public ArrayCPP<T, SID, SizePolicy>
200 {
201 public:
202  // ---------------------------------- Public typedef ----------------------------------
203 
204  typedef T ValueType;
205  typedef KyArrayCPP<T, SID, SizePolicy> SelfType;
206  typedef ArrayCPP<T, SID, SizePolicy> BaseType;
207 
208 
209  // ---------------------------------- Public Member Functions ----------------------------------
210 
211  KyArrayCPP() : BaseType() {}
212  explicit KyArrayCPP(int size) : BaseType(size) {}
213  KyArrayCPP(const SelfType& a) : BaseType(a) {}
214  const SelfType& operator=(const SelfType& a) { BaseType::operator=(a); return *this; }
215 
216  KyUInt32 GetCount() const { return (KyUInt32)BaseType::GetSize(); }
217  bool DoesContain(const ValueType& value) const;
218  void RemoveConsecutiveDuplicates();
219 };
220 
221 // ---- KyArrayLH_POD ----
225 template<class T, int SID=Stat_Default_Mem, class SizePolicy=KyArrayDefaultPolicy>
226 class KyArrayLH_POD : public ArrayLH_POD<T, SID, SizePolicy>
227 {
228 public:
229  // ---------------------------------- Public typedef ----------------------------------
230 
231  typedef T ValueType;
232  typedef KyArrayLH_POD<T, SID, SizePolicy> SelfType;
233  typedef ArrayLH_POD<T, SID, SizePolicy> BaseType;
234 
235 
236  // ---------------------------------- Public Member Functions ----------------------------------
237 
238  KyArrayLH_POD() : BaseType() {}
239  explicit KyArrayLH_POD(int size) : BaseType(size) {}
240  KyArrayLH_POD(const SelfType& a) : BaseType(a) {}
241  const SelfType& operator=(const SelfType& a) { BaseType::operator=(a); return *this; }
242 
243  KyUInt32 GetCount() const { return (KyUInt32)BaseType::GetSize(); }
244  bool DoesContain(const ValueType& value) const;
245  void RemoveConsecutiveDuplicates();
246 };
247 
248 // ---- KyArrayLH_CPP ----
249 // General purpose fully C++ compliant array. Can be used with non-movable data.
250 // Local heap is in use.
251 template<class T, int SID=Stat_Default_Mem, class SizePolicy=KyArrayDefaultPolicy>
252 class KyArrayLH_CPP : public ArrayLH_CPP<T, SID, SizePolicy>
253 {
254 public:
255  // ---------------------------------- Public typedef ----------------------------------
256 
257  typedef T ValueType;
258  typedef KyArrayLH_CPP<T, SID, SizePolicy> SelfType;
259  typedef ArrayLH_CPP<T, SID, SizePolicy> BaseType;
260 
261 
262  // ---------------------------------- Public Member Functions ----------------------------------
263 
264  KyArrayLH_CPP() : BaseType() {}
265  explicit KyArrayLH_CPP(int size) : BaseType(size) {}
266  KyArrayLH_CPP(const SelfType& a) : BaseType(a) {}
267  const SelfType& operator=(const SelfType& a) { BaseType::operator=(a); return *this; }
268 
269  KyUInt32 GetCount() const { return (KyUInt32)BaseType::GetSize(); }
270  bool DoesContain(const ValueType& value) const;
271  void RemoveConsecutiveDuplicates();
272 };
273 
274 // ---- KyArrayDH ----
277 template<class T, int SID=Stat_Default_Mem, class SizePolicy=KyArrayDefaultPolicy>
278 class KyArrayDH : public ArrayDH<T, SID, SizePolicy>
279 {
280 public:
281  // ---------------------------------- Public typedef ----------------------------------
282 
283  typedef T ValueType;
284  typedef KyArrayDH<T, SID, SizePolicy> SelfType;
285  typedef ArrayDH<T, SID, SizePolicy> BaseType;
286 
287 
288  // ---------------------------------- Public Member Functions ----------------------------------
289 
290  explicit KyArrayDH(MemoryHeap* heap) : BaseType(heap) {}
291  KyArrayDH(MemoryHeap* heap, int size) : BaseType(heap, size) {}
292  KyArrayDH(MemoryHeap* heap, const SelfType& a) : BaseType(heap, a) {}
293  const SelfType& operator=(const SelfType& a) { BaseType::operator=(a); return *this; }
294 
295  KyUInt32 GetCount() const { return (KyUInt32)BaseType::GetSize(); }
296  bool DoesContain(const ValueType& value) const;
297  void RemoveConsecutiveDuplicates();
298 };
299 
300 
301 // ---- KyArrayDH_POD ----
305 template<class T, int SID=Stat_Default_Mem, class SizePolicy=KyArrayDefaultPolicy>
306 class KyArrayDH_POD : public ArrayDH_POD<T, SID, SizePolicy>
307 {
308 public:
309  // ---------------------------------- Public typedef ----------------------------------
310 
311  typedef T ValueType;
312  typedef KyArrayDH_POD<T, SID, SizePolicy> SelfType;
313  typedef ArrayDH_POD<T, SID, SizePolicy> BaseType;
314 
315 
316  // ---------------------------------- Public Member Functions ----------------------------------
317 
318  explicit KyArrayDH_POD(MemoryHeap* heap) : BaseType(heap) {}
319  KyArrayDH_POD(MemoryHeap* heap, int size) : BaseType(heap, size) {}
320  KyArrayDH_POD(MemoryHeap* heap, const SelfType& a) : BaseType(heap, a) {}
321  const SelfType& operator=(const SelfType& a) { BaseType::operator=(a); return *this; }
322 
323  KyUInt32 GetCount() const { return (KyUInt32)BaseType::GetSize(); }
324  bool DoesContain(const ValueType& value) const;
325  void RemoveConsecutiveDuplicates();
326 };
327 
328 
329 // ---- KyArrayDH_CPP ----
330 // General purpose fully C++ compliant array. Can be used with non-movable data.
331 // Dynamic heap is in use
332 template<class T, int SID=Stat_Default_Mem, class SizePolicy=KyArrayDefaultPolicy>
333 class KyArrayDH_CPP : public ArrayDH_CPP<T, SID, SizePolicy>
334 {
335 public:
336  // ---------------------------------- Public typedef ----------------------------------
337 
338  typedef T ValueType;
339  typedef KyArrayDH_CPP<T, SID, SizePolicy> SelfType;
340  typedef ArrayDH_CPP<T, SID, SizePolicy> BaseType;
341 
342 
343  // ---------------------------------- Public Member Functions ----------------------------------
344 
345  explicit KyArrayDH_CPP(MemoryHeap* heap) : BaseType(heap) {}
346  KyArrayDH_CPP(MemoryHeap* heap, int size) : BaseType(heap, size) {}
347  KyArrayDH_CPP(MemoryHeap* heap, const SelfType& a) : BaseType(heap, a) {}
348  const SelfType& operator=(const SelfType& a) { BaseType::operator=(a); return *this; }
349 
350  KyUInt32 GetCount() const { return (KyUInt32)BaseType::GetSize(); }
351  bool DoesContain(const ValueType& value) const;
352  void RemoveConsecutiveDuplicates();
353 };
354 } // namespace Kaim
355 
357 
358 #endif // Navigation_KyArray_H
General purpose array for movable objects that DOES NOT require construction/destruction.
Definition: kyarray.h:156
General purpose array for movable objects that require explicit construction/destruction.
Definition: kyarray.h:118
ArrayConstPolicy< 0, 4, true > KyArrayDefaultPolicy
Default resize behavior for Gameware Navigation array.
Definition: kyarray.h:111
Definition: gamekitcrowddispersion.h:20
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36