gwnavruntime/querysystem/workingmemcontainers/workingmemdeque.h Source File

workingmemdeque.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 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 #pragma once
9 
11 
12 namespace Kaim
13 {
14 
15 template <class T>
16 class WorkingMemDeque
17 {
18 public:
19  WorkingMemDeque() : m_headIdx(0), m_tailIdx(0), m_lastIdx(0) {}
20  WorkingMemDeque(WorkingMemory*workingMemory) { Init(workingMemory); }
21 
22  void Init(WorkingMemory* workingMemory);
23 
24  T* GetBuffer() const { return (T*)m_buffer.GetBuffer(); }
25  bool IsInitialized() const { return m_buffer.IsInitialized(); }
26  bool IsEmpty() const { return m_tailIdx == m_headIdx; }
27 
28  void MakeEmpty() { m_headIdx = 0; m_tailIdx = 0; }
29 
30  KyResult PushFront(const T& x);
31  KyResult PushBack(const T& x);
32 
33  void PopFront();
34  void PopBack();
35 
36  void Front(T& item) const;
37  void Back(T& item) const;
38 
39  // The following functions are not used, but could be interesting so we keep the code commented
40  // If we need them at some point, we must unit-test them though
41  // The usage would be for(idx = GetHeadIdx(); idx != GetTailEndIdx(); idx = GetNextItemIdx()) {...}
42  //KyUInt32 GetHeadIdx() const { return m_headIdx; }
43  //KyUInt32 GetTailEndIdx() const { return m_tailIdx; }
44  //KyUInt32 GetNextItemIdx(KyUInt32 idx) const;
45  //KyUInt32 GetPrevItemIdx(KyUInt32 idx) const;
46 
47  T& GetItem(KyUInt32 idx);
48 
49  KyResult TryToResize(); // return KY_ERROR
50 
51  void ReleaseWorkingMemoryBuffer() { m_buffer.ReleaseBuffer(); }
52 
53  KyResult GrowIfNeeded();
54 
55 public:
56  WorkingMemContainerBase m_buffer;
57  KyUInt32 m_headIdx;
58  KyUInt32 m_tailIdx;
59  KyUInt32 m_lastIdx; // capacity - 1
60 };
61 
62 }
63 
65 
66 
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17