gwnavruntime/querysystem/workingmemcontainers/workingmemcontainerbase.h Source File

workingmemcontainerbase.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_WorkingMemContainerBase_H
9 #define Navigation_WorkingMemContainerBase_H
10 
12 
13 namespace Kaim
14 {
15 
16 class WorkingMemContainerBase
17 {
18 public:
19  WorkingMemContainerBase() : m_workingMemory(KY_NULL), m_bufferIdx(BufferIndex_Invalid) {}
20  WorkingMemContainerBase(WorkingMemory* workingMemory);
21 
22  KyResult Init(WorkingMemory* workingMemory);
23 
24  ~WorkingMemContainerBase();
25 
26  bool IsInitialized() const;
27  void* GetBuffer() const;
28  // newSize == 0 means no specific is wanted, only try to increase the buffer with a normal way
29  void* Resize(KyUInt32 newMinByteSize = 0);
30  void ReleaseMemory(void* memory);
31  void ReleaseBuffer();
32  KyUInt32 GetBufferSize() const;
33 
34 public :
35  WorkingMemory* m_workingMemory;
36  BufferIndex m_bufferIdx;
37 };
38 
39 KY_INLINE WorkingMemContainerBase::WorkingMemContainerBase(WorkingMemory* workingMemory) : m_workingMemory(KY_NULL), m_bufferIdx(BufferIndex_Invalid) { Init(workingMemory); }
40 
41 KY_INLINE KyResult WorkingMemContainerBase::Init(WorkingMemory* workingMemory)
42 {
43  ReleaseBuffer();
44 
45  BufferIndex bufferIdx = workingMemory->TakeUsageOfFirstUnusedBufferIdx();
46 
47  if(bufferIdx == BufferIndex_Invalid)
48  return KY_ERROR;
49 
50  m_workingMemory = workingMemory;
51  m_bufferIdx = bufferIdx;
52 
53  if (workingMemory->GetBuffer(bufferIdx) == KY_NULL)
54  {
55  if (workingMemory->ResizeBuffer(bufferIdx) == KY_NULL)
56  {
57  return KY_ERROR;
58  }
59  }
60 
61  return KY_SUCCESS;
62 }
63 
64 KY_INLINE bool WorkingMemContainerBase::IsInitialized() const { return m_workingMemory != KY_NULL; }
65 KY_INLINE void* WorkingMemContainerBase::GetBuffer() const { return m_workingMemory->GetBuffer(m_bufferIdx); }
66 KY_INLINE KyUInt32 WorkingMemContainerBase::GetBufferSize() const { return m_workingMemory->GetBufferSize(m_bufferIdx); }
67 
68 KY_INLINE void* WorkingMemContainerBase::Resize(KyUInt32 newMinByteSize) { return m_workingMemory->ResizeBuffer(m_bufferIdx, newMinByteSize); }
69 
70 KY_INLINE void WorkingMemContainerBase::ReleaseMemory(void* memory) { m_workingMemory->ReleaseMemory(memory); }
71 
72 KY_INLINE void WorkingMemContainerBase::ReleaseBuffer()
73 {
74  if(m_workingMemory != KY_NULL)
75  {
76  m_workingMemory->ReleaseBuffer(m_bufferIdx);
77 
78  m_workingMemory = KY_NULL;
79  m_bufferIdx = BufferIndex_Invalid;
80  }
81 }
82 
83 KY_INLINE WorkingMemContainerBase::~WorkingMemContainerBase()
84 {
85  ReleaseBuffer();
86 }
87 }
88 
89 
90 #endif //Navigation_WorkingMemContainerBase_H
91 
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
#define KY_NULL
Null value.
Definition: types.h:247
Definition: gamekitcrowddispersion.h:20
#define KY_SUCCESS
Shorthand for Kaim::Result::Success.
Definition: types.h:273
#define KY_ERROR
Shorthand for Kaim::Result::Failure.
Definition: types.h:272
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36