gwnavruntime/querysystem/workingmemcontainers/workingmemarray.h Source File

workingmemarray.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 #pragma once
8 
10 #include <string.h>
11 
12 namespace Kaim
13 {
14 
15 template <class T>
16 class WorkingMemArray
17 {
18 public:
19  WorkingMemArray() : m_count(0), m_capacity(0) {} // leaves WorkingMemArray uninitialized
20 
21  WorkingMemArray(WorkingMemory* workingMemory) { Init(workingMemory); }
22 
23  void Init(WorkingMemory* workingMemory);
24 
25  bool IsInitialized() const { return m_buffer.IsInitialized(); }
26 
27  T* GetBuffer() const { return (T*)m_buffer.GetBuffer(); }
28  KyUInt32 GetCount() const { return m_count; }
29  KyUInt32 GetCapacity() const { return m_capacity; }
30  bool IsEmpty() const { return m_count == 0; }
31 
32  void MakeEmpty() { m_count = 0; }
33  KyResult SetMinimumCapacity(KyUInt32 capacity); // return KY_ERROR if the working memory reaches its memory limit
34  KyResult GrowIfNeeded(); // return KY_ERROR if the working memory reaches its memory limit
35 
36  KyResult PushBack(const T& x); // return KY_ERROR if the working memory reaches its memory limit
37  void PushBack_UnSafe(const T& x);
38 
39  KyResult PopBack();
40 
41  const T& operator[](UPInt idx) const;
42  T& operator[](UPInt idx);
43 
44  void ReleaseWorkingMemoryBuffer() { m_buffer.ReleaseBuffer(); }
45 
46 private:
47  // capacity == 0 means increase capacity by the underlying working mem granularity
48  bool TryToResize(KyUInt32 capacity = 0);
49 
50 public:
51  WorkingMemContainerBase m_buffer;
52  KyUInt32 m_count;
53  KyUInt32 m_capacity;
54 };
55 
56 }
57 
59 
60 
61 
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