gwnavruntime/querysystem/workingmemcontainers/workingmembitfield.h Source File

workingmembitfield.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 
11 
12 namespace Kaim
13 {
14 
15 class WorkingMemBitField
16 {
17 public:
18  WorkingMemBitField();
19  WorkingMemBitField(WorkingMemory* workingMemory);
20 
21  void Init(WorkingMemory* workingMemory);
22 
23  // Check whether the container has been successfully initialized from a buffer of the WorkingMemory
24  bool IsInitialized() const;
25 
26  KyUInt32 GetWordCount() const;
27  KyUInt32 GetCapacity() const;
28  bool IsEmpty() const;
29 
30  void SetBit(KyUInt32 bitIndex);
31  void UnsetBit(KyUInt32 bitIndex);
32  bool IsBitSet(KyUInt32 bitIndex) const;
33 
34  void UnsetAllBits();
35  void SetAllBits();
36 
37  KyResult SetMinimumBitCountAndUnsetAllBits(KyUInt32 bitCount)
38  {
39  const KyUInt32 wordCount = BitFieldUtils::GetWordsCount(bitCount);
40  KY_TRY(m_words.SetMinimumCapacity(wordCount));
41 
42  for(KyUInt32 i = m_words.GetCount(); i < wordCount; ++i)
43  m_words.PushBack_UnSafe(0);
44 
45  return KY_SUCCESS;
46  }
47 
48  KyResult GrowIfNeeded() { return m_words.GrowIfNeeded(); }
49 
50  void ReleaseWorkingMemoryBuffer() { m_words.ReleaseWorkingMemoryBuffer(); }
51 
52 private:
53  KyUInt32* GetWordsBuffer() { return m_words.GetBuffer(); }
54  const KyUInt32* GetWordsBuffer() const { return m_words.GetBuffer(); }
55 
56 public:
57  WorkingMemArray<KyUInt32> m_words;
58 };
59 
60 KY_INLINE WorkingMemBitField::WorkingMemBitField() {}
61 KY_INLINE WorkingMemBitField::WorkingMemBitField(WorkingMemory* workingMemory) : m_words(workingMemory) {}
62 
63 KY_INLINE void WorkingMemBitField::Init(WorkingMemory* workingMemory) { m_words.Init(workingMemory); }
64 
65 KY_INLINE bool WorkingMemBitField::IsInitialized() const { return m_words.IsInitialized(); }
66 
67 KY_INLINE KyUInt32 WorkingMemBitField::GetWordCount() const { return m_words.GetCount(); }
68 KY_INLINE KyUInt32 WorkingMemBitField::GetCapacity() const { return m_words.GetCapacity(); }
69 KY_INLINE bool WorkingMemBitField::IsEmpty() const { return m_words.IsEmpty(); }
70 
71 KY_INLINE void WorkingMemBitField::SetBit(KyUInt32 bitIndex) { BitFieldUtils::SetBit(GetWordsBuffer(), bitIndex); }
72 KY_INLINE void WorkingMemBitField::UnsetBit(KyUInt32 bitIndex) { BitFieldUtils::UnsetBit(GetWordsBuffer(), bitIndex); }
73 KY_INLINE bool WorkingMemBitField::IsBitSet(KyUInt32 bitIndex) const { return BitFieldUtils::IsBitSet(GetWordsBuffer(), bitIndex); }
74 
75 KY_INLINE void WorkingMemBitField::UnsetAllBits() { memset(GetWordsBuffer(), '\0', GetWordCount() * sizeof(KyUInt32)); }
76 KY_INLINE void WorkingMemBitField::SetAllBits() { memset(GetWordsBuffer(), '\xFF', GetWordCount() * sizeof(KyUInt32)); }
77 
78 }
79 
80 
81 
82 
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
#define KY_TRY(expr)
Returns KY_ERROR if expression == KY_ERROR.
Definition: types.h:144
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17