gwnavruntime/querysystem/workingmemcontainers/workingmembitfield.h Source File

workingmembitfield.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_WorkingMemBitField_H
9 #define Navigation_WorkingMemBitField_H
10 
13 
14 namespace Kaim
15 {
16 
17 class WorkingMemBitField
18 {
19 public:
20  WorkingMemBitField();
21 
22  WorkingMemBitField(WorkingMemory* workingMemory);
23 
24  void Init(WorkingMemory* workingMemory);
25 
26  // Check whether the container has been successfully initialized from a buffer of the WorkingMemory
27  bool IsInitialized() const;
28 
29  KyUInt32 GetWordCount() const;
30  KyUInt32 GetCapacity() const;
31  bool IsEmpty() const;
32 
33  void SetBit(KyUInt32 bitIndex);
34  void UnsetBit(KyUInt32 bitIndex);
35  bool IsBitSet(KyUInt32 bitIndex) const;
36 
37  void UnsetAllBits();
38  void SetAllBits();
39 
40 
41  KyResult SetMinimumBitCountAndUnsetAllBits(KyUInt32 bitCount) /* \pre IsInitialized() == true */
42  {
43  const KyUInt32 wordCount = BitFieldUtils::GetWordsCount(bitCount);
44  KY_FORWARD_ERROR_NO_LOG(m_words.SetMinimumCapacity(wordCount));
45 
46  for(KyUInt32 i = m_words.GetCount(); i < wordCount; ++i)
47  m_words.PushBack_UnSafe(0);
48 
49  return KY_SUCCESS;
50  }
51 
52  bool IsFull() { return m_words.IsFull(); } /* \pre IsInitialized() == true */
53  void ReleaseWorkingMemoryBuffer() { m_words.ReleaseWorkingMemoryBuffer(); }
54 private:
55  KyUInt32* GetWordsBuffer() { return m_words.GetBuffer(); }
56  const KyUInt32* GetWordsBuffer() const { return m_words.GetBuffer(); }
57 public:
58  WorkingMemArray<KyUInt32> m_words;
59 };
60 
61 KY_INLINE WorkingMemBitField::WorkingMemBitField() {}
62 KY_INLINE WorkingMemBitField::WorkingMemBitField(WorkingMemory* workingMemory) : m_words(workingMemory) {}
63 
64 KY_INLINE void WorkingMemBitField::Init(WorkingMemory* workingMemory) { m_words.Init(workingMemory); }
65 
66 KY_INLINE bool WorkingMemBitField::IsInitialized() const { return m_words.IsInitialized(); }
67 
68 KY_INLINE KyUInt32 WorkingMemBitField::GetWordCount() const { return m_words.GetCount(); }
69 KY_INLINE KyUInt32 WorkingMemBitField::GetCapacity() const { return m_words.GetCapacity(); }
70 KY_INLINE bool WorkingMemBitField::IsEmpty() const { return m_words.IsEmpty(); }
71 
72 KY_INLINE void WorkingMemBitField::SetBit(KyUInt32 bitIndex) { BitFieldUtils::SetBit(GetWordsBuffer(), bitIndex); }
73 KY_INLINE void WorkingMemBitField::UnsetBit(KyUInt32 bitIndex) { BitFieldUtils::UnsetBit(GetWordsBuffer(), bitIndex); }
74 KY_INLINE bool WorkingMemBitField::IsBitSet(KyUInt32 bitIndex) const { return BitFieldUtils::IsBitSet(GetWordsBuffer(), bitIndex); }
75 
76 KY_INLINE void WorkingMemBitField::UnsetAllBits() { memset(GetWordsBuffer(), '\0', GetWordCount() * sizeof(KyUInt32)); }
77 KY_INLINE void WorkingMemBitField::SetAllBits() { memset(GetWordsBuffer(), '\xFF', GetWordCount() * sizeof(KyUInt32)); }
78 
79 }
80 
81 
82 
83 #endif
84 
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
Definition: gamekitcrowddispersion.h:20
#define KY_SUCCESS
Shorthand for Kaim::Result::Success.
Definition: types.h:273
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36