34 typedef uint16_t uint16; |
37 typedef uint16_t uint16; |
35 typedef uint32_t uint32; |
38 typedef uint32_t uint32; |
36 typedef uint64_t uint64; |
39 typedef uint64_t uint64; |
37 |
40 |
38 template<class T> using initlist = std::initializer_list<T>; |
41 template<class T> using initlist = std::initializer_list<T>; |
39 using std::vector; |
|
40 |
42 |
41 enum Axis { X, Y, Z }; |
43 enum Axis { X, Y, Z }; |
42 static const Axis g_Axes[3] = {X, Y, Z}; |
44 static const Axis g_Axes[3] = {X, Y, Z}; |
43 |
45 |
44 // ============================================================================= |
46 // ============================================================================= |
111 |
113 |
112 private: |
114 private: |
113 double m_coords[3]; |
115 double m_coords[3]; |
114 }; |
116 }; |
115 |
117 |
|
118 |
|
119 // ============================================================================= |
|
120 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
121 // ============================================================================= |
|
122 // vector |
|
123 // |
|
124 // Array class that wraps around vector |
|
125 // ============================================================================= |
|
126 template<class T> class vector { |
|
127 public: |
|
128 typedef typename std::vector<T>::iterator it; |
|
129 typedef typename std::vector<T>::const_iterator c_it; |
|
130 |
|
131 vector () {} |
|
132 vector (initlist<T> vals) { |
|
133 m_vect = vals; |
|
134 } |
|
135 |
|
136 it begin () { |
|
137 return m_vect.begin (); |
|
138 } |
|
139 |
|
140 c_it begin () const { |
|
141 return m_vect.cbegin (); |
|
142 } |
|
143 |
|
144 it end () { |
|
145 return m_vect.end (); |
|
146 } |
|
147 |
|
148 c_it end () const { |
|
149 return m_vect.cend (); |
|
150 } |
|
151 |
|
152 void erase (ulong pos) { |
|
153 assert (pos < size ()); |
|
154 m_vect.erase (m_vect.begin () + pos); |
|
155 } |
|
156 |
|
157 void push_back (const T& value) { |
|
158 m_vect.push_back (value); |
|
159 } |
|
160 |
|
161 bool pop (T& val) { |
|
162 if (size () == 0) |
|
163 return false; |
|
164 |
|
165 val = m_vect[size () - 1]; |
|
166 erase (size () - 1); |
|
167 return true; |
|
168 } |
|
169 |
|
170 vector<T>& operator<< (const T& value) { |
|
171 push_back (value); |
|
172 return *this; |
|
173 } |
|
174 |
|
175 bool operator>> (T& value) { |
|
176 return pop (value); |
|
177 } |
|
178 |
|
179 vector<T> reverse () const { |
|
180 vector<T> rev; |
|
181 |
|
182 for (const T& val : m_vect) |
|
183 rev << val; |
|
184 |
|
185 return rev; |
|
186 } |
|
187 |
|
188 void clear () { |
|
189 m_vect.clear (); |
|
190 } |
|
191 |
|
192 void insert (ulong pos, const T& value) { |
|
193 m_vect.insert (m_vect.begin () + pos, value); |
|
194 } |
|
195 |
|
196 ulong size () const { |
|
197 return m_vect.size (); |
|
198 } |
|
199 |
|
200 T& operator[] (ulong n) { |
|
201 assert (n < size ()); |
|
202 return m_vect[n]; |
|
203 } |
|
204 |
|
205 const T& operator[] (ulong n) const { |
|
206 assert (n < size ()); |
|
207 return m_vect[n]; |
|
208 } |
|
209 |
|
210 void resize (std::ptrdiff_t size) { |
|
211 m_vect.resize (size); |
|
212 } |
|
213 |
|
214 private: |
|
215 std::vector<T> m_vect; |
|
216 }; |
|
217 |
116 #endif // TYPES_H |
218 #endif // TYPES_H |