gwnavruntime/containers/circulararray.h Source File

circulararray.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_CircularArray_H
9 #define Navigation_CircularArray_H
10 
14 
15 namespace Kaim
16 {
17 
18 template <class T, int SID=Stat_Default_Mem>
19 class CircularArray
20 {
22  KY_CLASS_WITHOUT_COPY(CircularArray)
23 public:
24  CircularArray(MemoryHeap* heap = KY_NULL);
25 
26  ~CircularArray();
27 
28  KyUInt32 GetCount() const;
29  KyUInt32 GetCapacity() const;
30 
31  bool IsEmpty() const;
32  bool IsFull() const;
33 
34  void PushBack(const T& item);
35  void PushFront(const T& item);
36 
37  void PopFront();
38  void PopNFirstElements(KyUInt32 popCount);
39  void PopBack();
40 
41 
42  const T& GetBack() const;
43  T& GetBack();
44 
45  const T& GetFront() const;
46  T& GetFront();
47 
48  T& operator [] (KyUInt32 index);
49  const T& operator [] (KyUInt32 index) const;
50 
51  void Clear();
52  void Reserve(KyUInt32 size);
53 
54 protected:
55  void ReserveInHeap(KyUInt32 size);
56 
57 private:
58  void AutoReserve() { if (IsFull()) Reserve(Max<KyUInt32>(4, 2 * GetCapacity())); }
59  void ReleaseMemory();
60  void IncreaseBeginIdx();
61  void IncreaseEndIdx();
62  void DecreaseBeginIdx();
63  void DecreaseEndIdx();
64 private:
65  T* m_buffer;
66  MemoryHeap* const m_heap;
67  KyUInt32 m_lastValidIdx; // capacity == m_lastValidIdx + 1;
68  KyUInt32 m_beginIdx;
69  KyUInt32 m_endIdx;
70  KyUInt32 m_count;
71 };
72 
73 } // namespace Kaim
74 
76 
77 #endif // Navigation_CircularArray_H
#define KY_NULL
Null value.
Definition: types.h:247
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:387
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36