gwnavgeneration/common/densegrid.h Source File

densegrid.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 
10 
14 
15 
16 namespace Kaim
17 {
18 
19 
22 template<class T>
23 class DenseGrid
24 {
25 public:
26  class Column
27  {
28  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavDataGen)
29  public:
30  Column() : m_x(KyInt32MAXVAL), m_root_y(KyInt32MAXVAL) {}
31  Column(KyInt32 x) : m_x(x), m_root_y(KyInt32MAXVAL) {}
32  void Set(KyInt32 y, const T& value, const T& noneValue);
33  T Get(KyInt32 y, const T& noneValue) const;
34 
35  public:
36  KyInt32 m_x;
37  KyInt32 m_root_y;
38  KyArray<T> m_plus_y; // [root_y..[
39  KyArray<T> m_minus_y; // ]..root_y[
40  };
41 
42 public:
43  DenseGrid() : m_root_x(KyInt32MAXVAL), m_noneValue() {}
44  DenseGrid(const T& noneValue) : m_root_x(KyInt32MAXVAL), m_noneValue(noneValue) {}
45  ~DenseGrid() { ClearAndRelease(); }
46  void ClearAndRelease();
47  void Set(KyInt32 x, KyInt32 y, const T& value);
48  T Get(KyInt32 x, KyInt32 y) const;
49 
50 private:
51  KyInt32 m_root_x;
52  KyArrayPOD<Column*> m_plus_x; // [root_x..]
53  KyArrayPOD<Column*> m_minus_x; // ]..root_x[
54  T m_noneValue;
55  friend class DynamicGridColumn;
56 };
57 
58 
59 template<class T>
60 class DenseGridAndArrayOfRawPtr
61 {
62 public:
63  DenseGridAndArrayOfRawPtr() : m_grid(nullptr) {}
64  ~DenseGridAndArrayOfRawPtr() { ClearAndRelease(); }
65  void ClearAndRelease();
66  T* GetOrCreate(KyInt32 x, KyInt32 y);
67  T* Get(KyInt32 x, KyInt32 y) const { return m_grid.Get(x, y); }
68  const KyArrayPOD<T*>& GetArray() const { return m_array; }
69  T** GetElements() { return m_array.GetDataPtr(); }
70  KyUInt32 GetElementsCount() const { return m_array.GetCount(); }
71 
72 private:
73  DenseGrid<T*> m_grid;
74  KyArrayPOD<T*> m_array;
75 };
76 
77 
78 template<class T>
79 class DenseGridAndArrayOfRefPtr
80 {
81 public:
82  DenseGridAndArrayOfRefPtr() : m_grid(nullptr) {}
83  ~DenseGridAndArrayOfRefPtr() { ClearAndRelease(); }
84  void ClearAndRelease();
85  Ptr<T> GetOrCreate(KyInt32 x, KyInt32 y);
86  Ptr<T> Get(KyInt32 x, KyInt32 y) const { return m_grid.Get(x, y); }
87  const KyArray<Ptr<T> >& GetArray() const { return m_array; }
88  Ptr<T>* GetElements() { return m_array.GetDataPtr(); }
89  KyUInt32 GetElementsCount() const { return m_array.GetCount(); }
90 
91 private:
92  DenseGrid<Ptr<T> > m_grid;
93  KyArray<Ptr<T> > m_array;
94 };
95 
96 
97 }
98 
99 
101 
102 
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
Container that spatialize elements in a 2d grid.
Definition: densegrid.h:23
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
#define KyInt32MAXVAL
KyInt32 max value
Definition: types.h:60
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
std::int32_t KyInt32
int32_t
Definition: types.h:24