gwnavgeneration/common/densegrid.h Source File

densegrid.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 // primary contact: GUAL - secondary contact: NOBODY
9 #ifndef GwNavGen_DenseGrid_H
10 #define GwNavGen_DenseGrid_H
11 
12 
16 
17 
18 namespace Kaim
19 {
20 
21 
24 template<class T>
25 class DenseGrid
26 {
27 public:
28  class Column
29  {
30  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavDataGen)
31  public:
32  Column() : m_x(KyInt32MAXVAL), m_root_y(KyInt32MAXVAL) {}
33  Column(KyInt32 x) : m_x(x), m_root_y(KyInt32MAXVAL) {}
34  void Set(KyInt32 y, const T& value, const T& noneValue);
35  T Get(KyInt32 y, const T& noneValue) const;
36 
37  public:
38  KyInt32 m_x;
39  KyInt32 m_root_y;
40  KyArray<T> m_plus_y; // [root_y..[
41  KyArray<T> m_minus_y; // ]..root_y[
42  };
43 
44 public:
45  DenseGrid() : m_root_x(KyInt32MAXVAL), m_noneValue() {}
46  DenseGrid(const T& noneValue) : m_root_x(KyInt32MAXVAL), m_noneValue(noneValue) {}
47  ~DenseGrid() { ClearAndRelease(); }
48  void ClearAndRelease();
49  void Set(KyInt32 x, KyInt32 y, const T& value);
50  T Get(KyInt32 x, KyInt32 y) const;
51 
52 private:
53  KyInt32 m_root_x;
54  KyArrayPOD<Column*> m_plus_x; // [root_x..]
55  KyArrayPOD<Column*> m_minus_x; // ]..root_x[
56  T m_noneValue;
57  friend class DynamicGridColumn;
58 };
59 
60 
61 template<class T>
62 class DenseGridAndArrayOfRawPtr
63 {
64 public:
65  DenseGridAndArrayOfRawPtr() : m_grid(KY_NULL) {}
66  ~DenseGridAndArrayOfRawPtr() { ClearAndRelease(); }
67  void ClearAndRelease();
68  T* GetOrCreate(KyInt32 x, KyInt32 y);
69  T* Get(KyInt32 x, KyInt32 y) const { return m_grid.Get(x, y); }
70  const KyArrayPOD<T*>& GetArray() const { return m_array; }
71  T** GetElements() { return m_array.GetDataPtr(); }
72  KyUInt32 GetElementsCount() const { return m_array.GetCount(); }
73 
74 private:
75  DenseGrid<T*> m_grid;
76  KyArrayPOD<T*> m_array;
77 };
78 
79 
80 template<class T>
81 class DenseGridAndArrayOfRefPtr
82 {
83 public:
84  DenseGridAndArrayOfRefPtr() : m_grid(KY_NULL) {}
85  ~DenseGridAndArrayOfRefPtr() { ClearAndRelease(); }
86  void ClearAndRelease();
87  Ptr<T> GetOrCreate(KyInt32 x, KyInt32 y);
88  Ptr<T> Get(KyInt32 x, KyInt32 y) const { return m_grid.Get(x, y); }
89  const KyArray<Ptr<T> >& GetArray() const { return m_array; }
90  Ptr<T>* GetElements() { return m_array.GetDataPtr(); }
91  KyUInt32 GetElementsCount() const { return m_array.GetCount(); }
92 
93 private:
94  DenseGrid<Ptr<T> > m_grid;
95  KyArray<Ptr<T> > m_array;
96 };
97 
98 
99 }
100 
101 
103 
104 
105 #endif
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
#define KY_NULL
Null value.
Definition: types.h:247
Container that spatialize elements in a 2d grid.
Definition: densegrid.h:26
#define KyInt32MAXVAL
The maximum value that can be stored in the KyInt32 variable type.
Definition: types.h:224
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36