17 #ifndef INC_KY_Kernel_ArrayUnsafe_H
18 #define INC_KY_Kernel_ArrayUnsafe_H
40 template<
class T,
class Allocator>
class ArrayUnsafeBase
43 typedef ArrayUnsafeBase<T, Allocator> SelfType;
45 typedef Allocator AllocatorType;
49 Allocator::DestructArray(Data, Size);
50 Allocator::Free(Data);
53 ArrayUnsafeBase() : Data(0), Size(0), Capacity(0) {}
55 ArrayUnsafeBase(UPInt capacity) :
56 Data((T*)Allocator::Alloc(this, Capacity * sizeof(T), __FILE__, __LINE__)),
61 ArrayUnsafeBase(
const SelfType& v) :
62 Data(Capacity ? (T*)Allocator::Alloc(this, Capacity * sizeof(T), __FILE__, __LINE__) : 0),
67 Allocator::CopyArrayForward(Data, v.Data, Size);
72 Allocator::DestructArray(Data, Size);
76 void ClearAndRelease()
78 Allocator::DestructArray(Data, Size);
79 Allocator::Free(Data);
84 void CutAt(UPInt newSize)
88 Allocator::DestructArray(Data + newSize, Size - newSize);
94 void Reserve(UPInt cap, UPInt extraTail=0)
96 Allocator::DestructArray(Data, Size);
99 Allocator::Free(Data);
100 Capacity = cap + extraTail;
101 Data = Capacity ? (T*)Allocator::Alloc(
this, Capacity *
sizeof(T), __FILE__, __LINE__) : 0;
106 UPInt GetCapacity()
const
111 UPInt GetNumBytes()
const
113 return GetCapacity() *
sizeof(ValueType);
118 void Resize(UPInt size, UPInt extraTail=0)
120 Reserve(size, extraTail);
122 Allocator::ConstructArray(Data, size);
127 memset(Data, 0,
sizeof(T) * Size);
130 void PushBack(
const T& v)
132 Allocator::Construct(&Data[Size++], v);
136 void PushBackAlt(
const S& val)
138 Allocator::ConstructAlt(&Data[Size++], val);
141 void InsertAt(UPInt pos,
const T& val)
149 Allocator::Construct(Data + Size);
150 Allocator::CopyArrayBackward(Data + pos + 1, Data + pos, Size - pos);
151 Allocator::Construct(Data + pos, val);
158 void RemoveAt(UPInt pos)
166 Allocator::Destruct(Data + pos);
167 Allocator::CopyArrayForward(
175 UPInt GetSize()
const
180 const SelfType& operator = (
const SelfType& v)
185 if(Size) Allocator::CopyArrayForward(Data, v.Data, Size);
190 const T& operator [] (UPInt i)
const {
return Data[i]; }
191 T& operator [] (UPInt i) {
return Data[i]; }
192 const T& At(UPInt i)
const {
return Data[i]; }
193 T& At(UPInt i) {
return Data[i]; }
194 T ValueAt(UPInt i)
const {
return Data[i]; }
196 const T* GetDataPtr()
const {
return Data; }
197 T* GetDataPtr() {
return Data; }
213 template<
class T,
int SID=Stat_Default_Mem>
214 class ArrayUnsafePOD :
215 public ArrayUnsafeBase<T, AllocatorGH_POD<T, SID> >
219 typedef AllocatorGH_POD<T, SID> AllocatorType;
220 typedef ArrayUnsafeBase<T, AllocatorType> BaseType;
221 typedef ArrayUnsafePOD<T, SID> SelfType;
222 ArrayUnsafePOD() : BaseType() {}
223 ArrayUnsafePOD(UPInt capacity) : BaseType(capacity) {}
224 ArrayUnsafePOD(
const SelfType& v) : BaseType(v) {}
225 const SelfType& operator=(
const SelfType& a) { BaseType::operator=(a);
return *
this; }
234 template<
class T,
int SID=Stat_Default_Mem>
236 public ArrayUnsafeBase<T, AllocatorGH<T, SID> >
240 typedef AllocatorGH<T, SID> AllocatorType;
241 typedef ArrayUnsafeBase<T, AllocatorType> BaseType;
242 typedef ArrayUnsafe<T, SID> SelfType;
243 ArrayUnsafe() : BaseType() {}
244 ArrayUnsafe(UPInt capacity) : BaseType(capacity) {}
245 ArrayUnsafe(
const SelfType& v) : BaseType(v) {}
246 const SelfType& operator=(
const SelfType& a) { BaseType::operator=(a);
return *
this; }
256 template<
class T,
int SID=Stat_Default_Mem>
257 class ArrayUnsafeLH_POD :
258 public ArrayUnsafeBase<T, AllocatorLH_POD<T, SID> >
262 typedef AllocatorLH_POD<T, SID> AllocatorType;
263 typedef ArrayUnsafeBase<T, AllocatorType> BaseType;
264 typedef ArrayUnsafeLH_POD<T, SID> SelfType;
265 ArrayUnsafeLH_POD() : BaseType() {}
266 ArrayUnsafeLH_POD(UPInt capacity) : BaseType(capacity) {}
267 ArrayUnsafeLH_POD(
const SelfType& v) : BaseType(v) {}
268 const SelfType& operator=(
const SelfType& a) { BaseType::operator=(a);
return *
this; }
277 template<
class T,
int SID=Stat_Default_Mem>
278 class ArrayUnsafeLH :
279 public ArrayUnsafeBase<T, AllocatorLH<T, SID> >
283 typedef AllocatorLH<T, SID> AllocatorType;
284 typedef ArrayUnsafeBase<T, AllocatorType> BaseType;
285 typedef ArrayUnsafeLH<T, SID> SelfType;
286 ArrayUnsafeLH() : BaseType() {}
287 ArrayUnsafeLH(UPInt capacity) : BaseType(capacity) {}
288 ArrayUnsafeLH(
const SelfType& v) : BaseType(v) {}
289 const SelfType& operator=(
const SelfType& a) { BaseType::operator=(a);
return *
this; }
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17