NeuralEngine A Game Engine with embeded Machine Learning algorithms based on Gaussian Processes. |

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