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

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