NeuralEngine
A Game Engine with embeded Machine Learning algorithms based on Gaussian Processes.
NeArray2.inl
1
11template <typename T>
12Array2<T>::Array2(size_t bound0, size_t bound1)
13 :
14 mBound0(bound0),
15 mBound1(bound1),
16 mObjects(bound0 * bound1),
17 mIndirect1(bound1)
18{
19 SetPointers(mObjects.data());
20}
21
22template <typename T>
23Array2<T>::Array2(size_t bound0, size_t bound1, T* objects)
24 :
25 mBound0(bound0),
26 mBound1(bound1),
27 mIndirect1(bound1)
28{
29 SetPointers(objects);
30}
31
32template <typename T>
34 :
35 mBound0(0),
36 mBound1(0)
37{
38}
39
40template <typename T>
41Array2<T>::Array2(Array2 const& other)
42{
43 *this = other;
44}
45
46template <typename T>
47Array2<T>& Array2<T>::operator=(Array2 const& other)
48{
49 // The copy is valid whether or not other.mObjects has elements.
50 mObjects = other.mObjects;
51 SetPointers(other);
52 return *this;
53}
54
55template <typename T>
56Array2<T>::Array2(Array2&& other)
57{
58 *this = std::move(other);
59}
60
61template <typename T>
62Array2<T>& Array2<T>::operator=(Array2&& other)
63{
64 // The move is valid whether or not other.mObjects has elements.
65 mObjects = std::move(other.mObjects);
66 SetPointers(other);
67 return *this;
68}
69
70template <typename T> inline
71size_t Array2<T>::GetBound0() const
72{
73 return mBound0;
74}
75
76template <typename T> inline
77size_t Array2<T>::GetBound1() const
78{
79 return mBound1;
80}
81
82template <typename T> inline
83T const* Array2<T>::operator[] (int row) const
84{
85 return mIndirect1[row];
86}
87
88template <typename T> inline
89T* Array2<T>::operator[] (int row)
90{
91 return mIndirect1[row];
92}
93
94template <typename T>
95void Array2<T>::SetPointers(T* objects)
96{
97 for (size_t i1 = 0; i1 < mBound1; ++i1)
98 {
99 size_t j0 = mBound0 * i1; // = bound0 * (i1 + j1) where j1 = 0
100 mIndirect1[i1] = &objects[j0];
101 }
102}
103
104template <typename T>
105void Array2<T>::SetPointers(Array2 const& other)
106{
107 mBound0 = other.mBound0;
108 mBound1 = other.mBound1;
109 mIndirect1.resize(mBound1);
110
111 if (mBound0 > 0)
112 {
113 // The objects are owned.
114 SetPointers(mObjects.data());
115 }
116 else if (mIndirect1.size() > 0)
117 {
118 // The objects are not owned.
119 SetPointers(other.mIndirect1[0]);
120 }
121 // else 'other' is an empty Array2.
122}
The Array2 class represents a 2-dimensional array that minimizes the number of new and delete calls....
Definition: NeArray2.h:31
Array2()
Default constructor.
Definition: NeArray2.inl:33