NeuralEngine
A Game Engine with embeded Machine Learning algorithms based on Gaussian Processes.
NeArray4.inl
1
11template <typename T>
12Array4<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
26template <typename T>
27Array4<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
40template <typename T>
42 :
43 mBound0(0),
44 mBound1(0),
45 mBound2(0),
46 mBound3(0)
47{
48}
49
50template <typename T>
51Array4<T>::Array4(Array4 const& other)
52{
53 *this = other;
54}
55
56template <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
65template <typename T>
66Array4<T>::Array4(Array4&& other)
67{
68 *this = std::move(other);
69}
70
71template <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
80template <typename T> inline
81size_t Array4<T>::GetBound0() const
82{
83 return mBound0;
84}
85
86template <typename T> inline
87size_t Array4<T>::GetBound1() const
88{
89 return mBound1;
90}
91
92template <typename T> inline
93size_t Array4<T>::GetBound2() const
94{
95 return mBound2;
96}
97
98template <typename T> inline
99size_t Array4<T>::GetBound3() const
100{
101 return mBound3;
102}
103
104template <typename T> inline
105T** const* Array4<T>::operator[] (int cuboid) const
106{
107 return mIndirect3[cuboid];
108}
109
110template <typename T> inline
111T*** Array4<T>::operator[] (int cuboid)
112{
113 return mIndirect3[cuboid];
114}
115
116template <typename T>
117void 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
136template <typename T>
137void 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}
The Array4 class represents a 4-dimensional array that minimizes the number of new and delete calls....
Definition: NeArray4.h:31
Array4()
Default constructor.
Definition: NeArray4.inl:41