44 typedef quint8 uint8; |
44 typedef quint8 uint8; |
45 typedef quint16 uint16; |
45 typedef quint16 uint16; |
46 typedef quint32 uint32; |
46 typedef quint32 uint32; |
47 typedef quint64 uint64; |
47 typedef quint64 uint64; |
48 |
48 |
|
49 template<class T> using List = QList<T>; |
49 template<class T> using initlist = std::initializer_list<T>; |
50 template<class T> using initlist = std::initializer_list<T>; |
50 template<class T, class R> using pair = std::pair<T, R>; |
51 template<class T, class R> using pair = std::pair<T, R>; |
51 using std::size_t; |
52 using std::size_t; |
52 |
53 |
53 enum Axis { X, Y, Z }; |
54 enum Axis { X, Y, Z }; |
163 private: |
164 private: |
164 double m_coords[3]; |
165 double m_coords[3]; |
165 }; |
166 }; |
166 |
167 |
167 // ============================================================================= |
168 // ============================================================================= |
168 // ----------------------------------------------------------------------------- |
|
169 class Line |
|
170 { public: |
|
171 Line() {} |
|
172 Line (const vertex& v0, const vertex v1) : |
|
173 m_v0 (v0), |
|
174 m_v1 (v1) {} |
|
175 |
|
176 inline const vertex& getVertex (int i) const |
|
177 { assert (i == 0 || i == 1); |
|
178 return (i == 0) ? m_v0 : m_v1; |
|
179 } |
|
180 |
|
181 inline void setVertex (int i, const vertex& a) |
|
182 { assert (i == 0 || i == 1); |
|
183 (i == 0) ? m_v0 : m_v1 = a; |
|
184 } |
|
185 |
|
186 inline const vertex& v0() const |
|
187 { return m_v0; |
|
188 } |
|
189 |
|
190 inline const vertex& v1() const |
|
191 { return m_v1; |
|
192 } |
|
193 |
|
194 inline void setV0 (const vertex& a) |
|
195 { m_v0 = a; |
|
196 } |
|
197 |
|
198 inline void setV1 (const vertex& a) |
|
199 { m_v1 = a; |
|
200 } |
|
201 |
|
202 private: |
|
203 vertex m_v0, |
|
204 m_v1; |
|
205 }; |
|
206 |
|
207 // ============================================================================= |
|
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
209 // ============================================================================= |
|
210 // List |
|
211 // |
|
212 // Array class that wraps around std::deque |
|
213 // ============================================================================= |
|
214 template<class T> class List |
|
215 { public: |
|
216 typedef typename std::deque<T>::iterator Iterator; |
|
217 typedef typename std::deque<T>::const_iterator ConstIterator; |
|
218 typedef typename std::deque<T>::reverse_iterator ReverseIterator; |
|
219 typedef typename std::deque<T>::const_reverse_iterator ConstReverseIterator; |
|
220 |
|
221 List() {} |
|
222 List (initlist<T> vals) |
|
223 { m_vect = vals; |
|
224 } |
|
225 |
|
226 inline Iterator begin() |
|
227 { return m_vect.begin(); |
|
228 } |
|
229 |
|
230 inline ConstIterator begin() const |
|
231 { return m_vect.cbegin(); |
|
232 } |
|
233 |
|
234 inline Iterator end() |
|
235 { return m_vect.end(); |
|
236 } |
|
237 |
|
238 inline ConstIterator end() const |
|
239 { return m_vect.cend(); |
|
240 } |
|
241 |
|
242 inline ReverseIterator rbegin() |
|
243 { return m_vect.rbegin(); |
|
244 } |
|
245 |
|
246 inline ConstReverseIterator crbegin() const |
|
247 { return m_vect.crbegin(); |
|
248 } |
|
249 |
|
250 inline ReverseIterator rend() |
|
251 { return m_vect.rend(); |
|
252 } |
|
253 |
|
254 inline ConstReverseIterator crend() const |
|
255 { return m_vect.crend(); |
|
256 } |
|
257 |
|
258 void erase (int pos) |
|
259 { assert (pos < size()); |
|
260 m_vect.erase (m_vect.begin() + pos); |
|
261 } |
|
262 |
|
263 T& push_back (const T& value) |
|
264 { m_vect.push_back (value); |
|
265 return m_vect[m_vect.size() - 1]; |
|
266 } |
|
267 |
|
268 void push_back (const List<T>& vals) |
|
269 { for (const T& val : vals) |
|
270 push_back (val); |
|
271 } |
|
272 |
|
273 bool pop (T& val) |
|
274 { if (size() == 0) |
|
275 return false; |
|
276 |
|
277 val = m_vect[size() - 1]; |
|
278 erase (size() - 1); |
|
279 return true; |
|
280 } |
|
281 |
|
282 T& operator<< (const T& value) |
|
283 { return push_back (value); |
|
284 } |
|
285 |
|
286 void operator<< (const List<T>& vals) |
|
287 { push_back (vals); |
|
288 } |
|
289 |
|
290 bool operator>> (T& value) |
|
291 { return pop (value); |
|
292 } |
|
293 |
|
294 List<T> reverse() const |
|
295 { List<T> rev; |
|
296 |
|
297 for (auto it = end() - 1; it != begin(); --it) |
|
298 rev << *it; |
|
299 |
|
300 return rev; |
|
301 } |
|
302 |
|
303 void clear() |
|
304 { m_vect.clear(); |
|
305 } |
|
306 |
|
307 void insert (int pos, const T& value) |
|
308 { m_vect.insert (m_vect.begin() + pos, value); |
|
309 } |
|
310 |
|
311 void makeUnique() |
|
312 { // Remove duplicate entries. For this to be effective, the List must be |
|
313 // sorted first. |
|
314 sort(); |
|
315 Iterator pos = std::unique (begin(), end()); |
|
316 resize (std::distance (begin(), pos)); |
|
317 } |
|
318 |
|
319 int size() const |
|
320 { return m_vect.size(); |
|
321 } |
|
322 |
|
323 T& operator[] (int n) |
|
324 { assert (n < size()); |
|
325 return m_vect[n]; |
|
326 } |
|
327 |
|
328 const T& operator[] (int n) const |
|
329 { assert (n < size()); |
|
330 return m_vect[n]; |
|
331 } |
|
332 |
|
333 void resize (std::ptrdiff_t size) |
|
334 { m_vect.resize (size); |
|
335 } |
|
336 |
|
337 void sort() |
|
338 { std::sort (begin(), end()); |
|
339 } |
|
340 |
|
341 int find (const T& needle) |
|
342 { int i = 0; |
|
343 |
|
344 for (const T & hay : *this) |
|
345 { if (hay == needle) |
|
346 return i; |
|
347 |
|
348 i++; |
|
349 } |
|
350 |
|
351 return -1; |
|
352 } |
|
353 |
|
354 private: |
|
355 std::deque<T> m_vect; |
|
356 }; |
|
357 |
|
358 // ============================================================================= |
|
359 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
169 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
360 // ============================================================================= |
170 // ============================================================================= |
361 // StringFormatArg |
171 // StringFormatArg |
362 // |
172 // |
363 // Converts a given value into a string that can be retrieved with ::value(). |
173 // Converts a given value into a string that can be retrieved with ::value(). |