NTrace
GPU ray tracing framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Array.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2011, NVIDIA Corporation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of NVIDIA Corporation nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #pragma once
29 #include "base/Math.hpp"
30 
31 namespace FW
32 {
33 //------------------------------------------------------------------------
34 // Growing Array, similar to stl::vector.
35 // Array<T> uses S32 as size, Array64 uses S64.
36 
37 template <class T, typename S> class ArrayBase
38 {
39 private:
40  enum
41  {
42  MinBytes = 256, // Minimum number of bytes to allocate when the first element is being added.
43  };
44 
45 public:
46 
47  // Constructors.
48 
49  inline ArrayBase (void); // Create an empty ArrayBase. Memory is allocated lazily.
50  inline explicit ArrayBase (const T& item); // Create an ArrayBase containing one element.
51  inline ArrayBase (const T* ptr, S size); // Copy contents from the given memory location. If NULL, the elements are left uninitialized.
52  inline ArrayBase (const ArrayBase<T,S>& other); // Copy constructor.
53  inline ~ArrayBase (void);
54 
55  // ArrayBase-wide getters.
56 
57  inline S getSize (void) const; // Returns the number of elements contained in the ArrayBase.
58  inline S getCapacity (void) const; // Returns the number of elements currently allocated. Can be larger than getSize().
59  inline const T* getPtr (S idx = 0) const; // Returns a pointer to the specified element.
60  inline T* getPtr (S idx = 0);
61  inline S getStride (void) const; // Returns the size of one element in bytes.
62  inline S getNumBytes (void) const; // Returns the size of the entire ArrayBase in bytes.
63 
64  // Element access.
65 
66  inline const T& get (S idx) const; // Returns a reference to the specified element.
67  inline T& get (S idx);
68  inline T set (S idx, const T& item); // Overwrites the specified element and returns the old value.
69  inline const T& getFirst (void) const; // Returns a reference to the first element.
70  inline T& getFirst (void);
71  inline const T& getLast (void) const; // Returns a reference to the last element.
72  inline T& getLast (void);
73  inline void getRange (S start, S end, T* ptr) const; // Copies a range of elements (start..end-1) into the given memory location.
74  inline ArrayBase<T,S> getRange (S start, S end) const; // Copies a range of elements (start..end-1) into a newly allocated ArrayBase.
75  inline void setRange (S start, S end, const T* ptr); // Overwrites a range of elements (start..end-1) from the given memory location.
76  inline void setRange (S start, const ArrayBase<T,S>& other); // Overwrites a range of elements from the given ArrayBase.
77 
78  // ArrayBase-wide operations that may shrink the allocation.
79 
80  inline void reset (S size = 0); // Discards old contents, and resets size & capacity exactly to the given value.
81  inline void setCapacity (S numElements); // Resizes the allocation for exactly the given number of elements. Does not modify contents.
82  inline void compact (void); // Shrinks the allocation to the match the current size. Does not modify contents.
83  inline void set (const T* ptr, S size); // Discards old contents, and re-initializes the ArrayBase from the given memory location.
84  inline void set (const ArrayBase<T,S>& other); // Discards old contents, and re-initializes the ArrayBase by cloning the given ArrayBase.
85 
86  // ArrayBase-wide operations that can only grow the allocation.
87 
88  inline void clear (void); // Sets the size to zero. Does not shrink the allocation.
89  inline void resize (S size); // Sets the size to the given value. Allocates more space if necessary.
90  inline void reserve (S numElements); // Grows the allocation to contain at least the given number of elements. Does not modify contents.
91 
92  // Element addition. Allocates more space if necessary.
93 
94  inline T& add (void); // Adds one element and returns a reference to it.
95  inline T& add (const T& item); // Adds one element and initializes it to the given value.
96  inline T* add (const T* ptr, S size); // Appends a number of elements from the given memory location. If NULL, the elements are left uninitialized.
97  inline T* add (const ArrayBase<T,S>& other); // Appends elements from the given ArrayBase.
98  inline T& insert (S idx); // Inserts a new element at the given index and returns a reference to it. Shifts the following elements up.
99  inline T& insert (S idx, const T& item); // Inserts a new element at the given index and initializes it to the given value. Shifts the following elements up.
100  inline T* insert (S idx, const T* ptr, S size); // Inserts a number of elements from the given memory location. If NULL, the elements are left uninitialized.
101  inline T* insert (S idx, const ArrayBase<T,S>& other); // Inserts elements from the given ArrayBase.
102 
103  // Element removal. Does not shrink the allocation.
104 
105  inline T remove (S idx); // Removes the given element and returns its value. Shifts the following elements down.
106  inline void remove (S start, S end); // Removes a range of elements (start..end-1). Shifts the following elements down.
107  inline T& removeLast (void); // Removes the last element and returns a reference to its value.
108  inline T removeSwap (S idx); // Removes the given element and returns its value. Swaps in the last element to fill the vacant slot.
109  inline void removeSwap (S start, S end); // Removes a range of elements (start..end-1). Swaps in the N last element to fill the vacant slots.
110  inline T* replace (S start, S end, S size); // remove(start, end), insert(start, NULL, size)
111  inline T* replace (S start, S end, const T* ptr, S size); // remove(start, end), insert(start, ptr, size)
112  inline T* replace (S start, S end, const ArrayBase<T,S>& other); // remove(start, end), insert(start, other)
113 
114  // Element search.
115 
116  inline S indexOf (const T& item, S fromIdx = 0) const; // Finds the first element that equals the given value, or -1 if not found.
117  inline S lastIndexOf (const T& item) const; // Finds the last element that equals the given value, or -1 if not found.
118  inline S lastIndexOf (const T& item, S fromIdx) const;
119  inline bool contains (const T& item) const; // Checks whether the ArrayBase contains an element that equals the given value.
120  inline bool removeItem (const T& item); // Finds the first element that equals the given value and removes it.
121 
122  // Operators.
123 
124  inline const T& operator[] (S idx) const;
125  inline T& operator[] (S idx);
126  inline ArrayBase<T,S>& operator= (const ArrayBase<T,S>& other);
127  inline bool operator== (const ArrayBase<T,S>& other) const;
128  inline bool operator!= (const ArrayBase<T,S>& other) const;
129 
130  // Type-specific utilities.
131 
132  static inline void copy (T* dst, const T* src, S size); // Analogous to memcpy().
133  static inline void copyOverlap (T* dst, const T* src, S size); // Analogous to memmove().
134 
135  // Internals.
136 
137 private:
138  inline void init (void);
139  void realloc (S size);
140  void reallocRound(S size);
141 
142 private:
143  T* m_ptr;
144  S m_size;
145  S m_alloc;
146 };
147 
148 //------------------------------------------------------------------------
149 
150 template <class T, typename S> ArrayBase<T,S>::ArrayBase(void)
151 {
152  init();
153 }
154 
155 //------------------------------------------------------------------------
156 
157 template <class T, typename S> ArrayBase<T,S>::ArrayBase(const T& item)
158 {
159  init();
160  add(item);
161 }
162 
163 //------------------------------------------------------------------------
164 
165 template <class T, typename S> ArrayBase<T,S>::ArrayBase(const T* ptr, S size)
166 {
167  init();
168  set(ptr, size);
169 }
170 
171 //------------------------------------------------------------------------
172 
173 template <class T, typename S> ArrayBase<T,S>::ArrayBase(const ArrayBase<T,S>& other)
174 {
175  init();
176  set(other);
177 }
178 
179 //------------------------------------------------------------------------
180 
181 template <class T, typename S> ArrayBase<T,S>::~ArrayBase(void)
182 {
183  delete[] m_ptr;
184 }
185 
186 //------------------------------------------------------------------------
187 
188 template <class T, typename S> S ArrayBase<T,S>::getSize(void) const
189 {
190  return m_size;
191 }
192 
193 //------------------------------------------------------------------------
194 
195 template <class T, typename S> S ArrayBase<T,S>::getCapacity(void) const
196 {
197  return m_alloc;
198 }
199 
200 //------------------------------------------------------------------------
201 
202 template <class T, typename S> const T* ArrayBase<T,S>::getPtr(S idx) const
203 {
204  FW_ASSERT(idx >= 0 && idx <= m_size);
205  return m_ptr + idx;
206 }
207 
208 //------------------------------------------------------------------------
209 
210 template <class T, typename S> T* ArrayBase<T,S>::getPtr(S idx)
211 {
212  FW_ASSERT(idx >= 0 && idx <= m_size);
213  return m_ptr + idx;
214 }
215 
216 //------------------------------------------------------------------------
217 
218 template <class T, typename S> S ArrayBase<T,S>::getStride(void) const
219 {
220  return sizeof(T);
221 }
222 
223 //------------------------------------------------------------------------
224 
225 template <class T, typename S> S ArrayBase<T,S>::getNumBytes(void) const
226 {
227  return getSize() * getStride();
228 }
229 
230 //------------------------------------------------------------------------
231 
232 template <class T, typename S> const T& ArrayBase<T,S>::get(S idx) const
233 {
234  FW_ASSERT(idx >= 0 && idx < m_size);
235  return m_ptr[idx];
236 }
237 
238 //------------------------------------------------------------------------
239 
240 template <class T, typename S> T& ArrayBase<T,S>::get(S idx)
241 {
242  FW_ASSERT(idx >= 0 && idx < m_size);
243  return m_ptr[idx];
244 }
245 
246 //------------------------------------------------------------------------
247 
248 template <class T, typename S> T ArrayBase<T,S>::set(S idx, const T& item)
249 {
250  T& slot = get(idx);
251  T old = slot;
252  slot = item;
253  return old;
254 }
255 
256 //------------------------------------------------------------------------
257 
258 template <class T, typename S> const T& ArrayBase<T,S>::getFirst(void) const
259 {
260  return get(0);
261 }
262 
263 //------------------------------------------------------------------------
264 
265 template <class T, typename S> T& ArrayBase<T,S>::getFirst(void)
266 {
267  return get(0);
268 }
269 
270 //------------------------------------------------------------------------
271 
272 template <class T, typename S> const T& ArrayBase<T,S>::getLast(void) const
273 {
274  return get(getSize() - 1);
275 }
276 
277 //------------------------------------------------------------------------
278 
279 template <class T, typename S> T& ArrayBase<T,S>::getLast(void)
280 {
281  return get(getSize() - 1);
282 }
283 
284 //------------------------------------------------------------------------
285 
286 template <class T, typename S> void ArrayBase<T,S>::getRange(S start, S end, T* ptr) const
287 {
288  FW_ASSERT(end <= m_size);
289  copy(ptr, getPtr(start), end - start);
290 }
291 
292 //------------------------------------------------------------------------
293 
294 template <class T, typename S> ArrayBase<T,S> ArrayBase<T,S>::getRange(S start, S end) const
295 {
296  FW_ASSERT(end <= m_size);
297  return ArrayBase<T,S>(getPtr(start), end - start);
298 }
299 
300 //------------------------------------------------------------------------
301 
302 template <class T, typename S> void ArrayBase<T,S>::setRange(S start, S end, const T* ptr)
303 {
304  FW_ASSERT(end <= m_size);
305  copy(getPtr(start), ptr, end - start);
306 }
307 
308 //------------------------------------------------------------------------
309 
310 template <class T, typename S> void ArrayBase<T,S>::setRange(S start, const ArrayBase<T,S>& other)
311 {
312  setRange(start, start + other.getSize(), other.getPtr());
313 }
314 
315 //------------------------------------------------------------------------
316 
317 template <class T, typename S> void ArrayBase<T,S>::reset(S size)
318 {
319  clear();
320  setCapacity(size);
321  m_size = size;
322 }
323 
324 //------------------------------------------------------------------------
325 
326 template <class T, typename S> void ArrayBase<T,S>::setCapacity(S numElements)
327 {
328  S c = max(numElements, m_size);
329  if (m_alloc != c)
330  realloc(c);
331 }
332 
333 //------------------------------------------------------------------------
334 
335 template <class T, typename S> void ArrayBase<T,S>::compact(void)
336 {
337  setCapacity(0);
338 }
339 
340 //------------------------------------------------------------------------
341 
342 template <class T, typename S> void ArrayBase<T,S>::set(const T* ptr, S size)
343 {
344  reset(size);
345  if (ptr)
346  copy(getPtr(), ptr, size);
347 }
348 
349 //------------------------------------------------------------------------
350 
351 template <class T, typename S> void ArrayBase<T,S>::set(const ArrayBase<T,S>& other)
352 {
353  if (&other != this)
354  set(other.getPtr(), other.getSize());
355 }
356 
357 //------------------------------------------------------------------------
358 
359 template <class T, typename S> void ArrayBase<T,S>::clear(void)
360 {
361  m_size = 0;
362 }
363 
364 //------------------------------------------------------------------------
365 
366 template <class T, typename S> void ArrayBase<T,S>::resize(S size)
367 {
368  FW_ASSERT(size >= 0);
369  if (size > m_alloc)
370  reallocRound(size);
371  m_size = size;
372 }
373 
374 //------------------------------------------------------------------------
375 
376 template <class T, typename S> void ArrayBase<T,S>::reserve(S numElements)
377 {
378  if (numElements > m_alloc)
379  realloc(numElements);
380 }
381 
382 //------------------------------------------------------------------------
383 
384 template <class T, typename S> T& ArrayBase<T,S>::add(void)
385 {
386  return *add(NULL, 1);
387 }
388 
389 //------------------------------------------------------------------------
390 
391 template <class T, typename S> T& ArrayBase<T,S>::add(const T& item)
392 {
393  T* slot = add(NULL, 1);
394  *slot = item;
395  return *slot;
396 }
397 
398 //------------------------------------------------------------------------
399 
400 template <class T, typename S> T* ArrayBase<T,S>::add(const T* ptr, S size)
401 {
402  S oldSize = getSize();
403  resize(oldSize + size);
404  T* slot = getPtr(oldSize);
405  if (ptr)
406  copy(slot, ptr, size);
407  return slot;
408 }
409 
410 //------------------------------------------------------------------------
411 
412 template <class T, typename S> T* ArrayBase<T,S>::add(const ArrayBase<T,S>& other)
413 {
414  return replace(getSize(), getSize(), other);
415 }
416 
417 //------------------------------------------------------------------------
418 
419 template <class T, typename S> T& ArrayBase<T,S>::insert(S idx)
420 {
421  return *replace(idx, idx, 1);
422 }
423 
424 //------------------------------------------------------------------------
425 
426 template <class T, typename S> T& ArrayBase<T,S>::insert(S idx, const T& item)
427 {
428  T* slot = replace(idx, idx, 1);
429  *slot = item;
430  return *slot;
431 }
432 
433 //------------------------------------------------------------------------
434 
435 template <class T, typename S> T* ArrayBase<T,S>::insert(S idx, const T* ptr, S size)
436 {
437  return replace(idx, idx, ptr, size);
438 }
439 
440 //------------------------------------------------------------------------
441 
442 template <class T, typename S> T* ArrayBase<T,S>::insert(S idx, const ArrayBase<T,S>& other)
443 {
444  return replace(idx, idx, other);
445 }
446 
447 //------------------------------------------------------------------------
448 
449 template <class T, typename S> T ArrayBase<T,S>::remove(S idx)
450 {
451  T old = get(idx);
452  replace(idx, idx + 1, 0);
453  return old;
454 }
455 
456 //------------------------------------------------------------------------
457 
458 template <class T, typename S> void ArrayBase<T,S>::remove(S start, S end)
459 {
460  replace(start, end, 0);
461 }
462 
463 //------------------------------------------------------------------------
464 
465 template <class T, typename S> T& ArrayBase<T,S>::removeLast(void)
466 {
467  FW_ASSERT(m_size > 0);
468  m_size--;
469  return m_ptr[m_size];
470 }
471 
472 //------------------------------------------------------------------------
473 
474 template <class T, typename S> T ArrayBase<T,S>::removeSwap(S idx)
475 {
476  FW_ASSERT(idx >= 0 && idx < m_size);
477 
478  T old = get(idx);
479  m_size--;
480  if (idx < m_size)
481  m_ptr[idx] = m_ptr[m_size];
482  return old;
483 }
484 
485 //------------------------------------------------------------------------
486 
487 template <class T, typename S> void ArrayBase<T,S>::removeSwap(S start, S end)
488 {
489  FW_ASSERT(start >= 0);
490  FW_ASSERT(start <= end);
491  FW_ASSERT(end <= m_size);
492 
493  S oldSize = m_size;
494  m_size += start - end;
495 
496  S copyStart = max(m_size, end);
497  copy(m_ptr + start, m_ptr + copyStart, oldSize - copyStart);
498 }
499 
500 //------------------------------------------------------------------------
501 
502 template <class T, typename S> T* ArrayBase<T,S>::replace(S start, S end, S size)
503 {
504  FW_ASSERT(start >= 0);
505  FW_ASSERT(start <= end);
506  FW_ASSERT(end <= m_size);
507  FW_ASSERT(size >= 0);
508 
509  S tailSize = m_size - end;
510  S newEnd = start + size;
511  resize(m_size + newEnd - end);
512 
513  copyOverlap(m_ptr + newEnd, m_ptr + end, tailSize);
514  return m_ptr + start;
515 }
516 
517 //------------------------------------------------------------------------
518 
519 template <class T, typename S> T* ArrayBase<T,S>::replace(S start, S end, const T* ptr, S size)
520 {
521  T* slot = replace(start, end, size);
522  if (ptr)
523  copy(slot, ptr, size);
524  return slot;
525 }
526 
527 //------------------------------------------------------------------------
528 
529 template <class T, typename S> T* ArrayBase<T,S>::replace(S start, S end, const ArrayBase<T,S>& other)
530 {
531  ArrayBase<T,S> tmp;
532  const T* ptr = other.getPtr();
533  if (&other == this)
534  {
535  tmp = other;
536  ptr = tmp.getPtr();
537  }
538  return replace(start, end, ptr, other.getSize());
539 }
540 
541 //------------------------------------------------------------------------
542 
543 template <class T, typename S> S ArrayBase<T,S>::indexOf(const T& item, S fromIdx) const
544 {
545  for (S i = max(fromIdx, 0); i < getSize(); i++)
546  if (get(i) == item)
547  return i;
548  return -1;
549 }
550 
551 //------------------------------------------------------------------------
552 
553 template <class T, typename S> S ArrayBase<T,S>::lastIndexOf(const T& item) const
554 {
555  return lastIndexOf(item, getSize() - 1);
556 }
557 
558 //------------------------------------------------------------------------
559 
560 template <class T, typename S> S ArrayBase<T,S>::lastIndexOf(const T& item, S fromIdx) const
561 {
562  for (S i = min(fromIdx, getSize() - 1); i >= 0; i--)
563  if (get(i) == item)
564  return i;
565  return -1;
566 }
567 
568 //------------------------------------------------------------------------
569 
570 template <class T, typename S> bool ArrayBase<T,S>::contains(const T& item) const
571 {
572  return (indexOf(item) != -1);
573 }
574 
575 //------------------------------------------------------------------------
576 
577 template <class T, typename S> bool ArrayBase<T,S>::removeItem(const T& item)
578 {
579  S idx = indexOf(item);
580  if (idx == -1)
581  return false;
582  remove(idx);
583  return true;
584 }
585 
586 //------------------------------------------------------------------------
587 
588 template <class T, typename S> const T& ArrayBase<T,S>::operator[](S idx) const
589 {
590  return get(idx);
591 }
592 
593 //------------------------------------------------------------------------
594 
595 template <class T, typename S> T& ArrayBase<T,S>::operator[](S idx)
596 {
597  return get(idx);
598 }
599 
600 //------------------------------------------------------------------------
601 
602 template <class T, typename S> ArrayBase<T,S>& ArrayBase<T,S>::operator=(const ArrayBase<T,S>& other)
603 {
604  set(other);
605  return *this;
606 }
607 
608 //------------------------------------------------------------------------
609 
610 template <class T, typename S> bool ArrayBase<T,S>::operator==(const ArrayBase<T,S>& other) const
611 {
612  if (getSize() != other.getSize())
613  return false;
614 
615  for (S i = 0; i < getSize(); i++)
616  if (get(i) != other[i])
617  return false;
618  return true;
619 }
620 
621 //------------------------------------------------------------------------
622 
623 template <class T, typename S> bool ArrayBase<T,S>::operator!=(const ArrayBase<T,S>& other) const
624 {
625  return (!operator==(other));
626 }
627 
628 //------------------------------------------------------------------------
629 
630 template <class T, typename S> void ArrayBase<T,S>::copy(T* dst, const T* src, S size)
631 {
632  FW_ASSERT(size >= 0);
633  if (!size)
634  return;
635 
636  FW_ASSERT(dst && src);
637  for (S i = 0; i < size; i++)
638  dst[i] = src[i];
639 }
640 
641 //------------------------------------------------------------------------
642 
643 template <class T, typename S> void ArrayBase<T,S>::copyOverlap(T* dst, const T* src, S size)
644 {
645  FW_ASSERT(size >= 0);
646  if (!size)
647  return;
648 
649  FW_ASSERT(dst && src);
650  if (dst < src || dst >= src + size)
651  for (S i = 0; i < size; i++)
652  dst[i] = src[i];
653  else
654  for (S i = size - 1; i >= 0; i--)
655  dst[i] = src[i];
656 }
657 
658 //------------------------------------------------------------------------
659 
660 template <class T, typename S> void ArrayBase<T,S>::init(void)
661 {
662  m_ptr = NULL;
663  m_size = 0;
664  m_alloc = 0;
665 }
666 
667 //------------------------------------------------------------------------
668 
669 template <class T, typename S> void ArrayBase<T,S>::realloc(S size)
670 {
671  FW_ASSERT(size >= 0);
672 
673  T* newPtr = NULL;
674  if (size)
675  {
676  newPtr = new T[size];
677  copy(newPtr, m_ptr, min(size, m_size));
678  }
679 
680  delete[] m_ptr;
681  m_ptr = newPtr;
682  m_alloc = size;
683 }
684 
685 //------------------------------------------------------------------------
686 
687 template <class T, typename S> void ArrayBase<T,S>::reallocRound(S size)
688 {
689  FW_ASSERT(size >= 0);
690  S rounded = max((S)(MinBytes / sizeof(T)), S(1));
691  while (size > rounded)
692  rounded <<= 1;
693  realloc(rounded);
694 }
695 
696 //------------------------------------------------------------------------
697 
698 inline void ArrayBase<S8,S32>::copy(S8* dst, const S8* src, int size) { memcpy(dst, src, size * sizeof(S8)); }
699 inline void ArrayBase<U8,S32>::copy(U8* dst, const U8* src, int size) { memcpy(dst, src, size * sizeof(U8)); }
700 inline void ArrayBase<S16,S32>::copy(S16* dst, const S16* src, int size) { memcpy(dst, src, size * sizeof(S16)); }
701 inline void ArrayBase<U16,S32>::copy(U16* dst, const U16* src, int size) { memcpy(dst, src, size * sizeof(U16)); }
702 inline void ArrayBase<S32,S32>::copy(S32* dst, const S32* src, int size) { memcpy(dst, src, size * sizeof(S32)); }
703 inline void ArrayBase<U32,S32>::copy(U32* dst, const U32* src, int size) { memcpy(dst, src, size * sizeof(U32)); }
704 inline void ArrayBase<F32,S32>::copy(F32* dst, const F32* src, int size) { memcpy(dst, src, size * sizeof(F32)); }
705 inline void ArrayBase<S64,S32>::copy(S64* dst, const S64* src, int size) { memcpy(dst, src, size * sizeof(S64)); }
706 inline void ArrayBase<U64,S32>::copy(U64* dst, const U64* src, int size) { memcpy(dst, src, size * sizeof(U64)); }
707 inline void ArrayBase<F64,S32>::copy(F64* dst, const F64* src, int size) { memcpy(dst, src, size * sizeof(F64)); }
708 
709 inline void ArrayBase<Vec2i,S32>::copy(Vec2i* dst, const Vec2i* src, int size) { memcpy(dst, src, size * sizeof(Vec2i)); }
710 inline void ArrayBase<Vec2f,S32>::copy(Vec2f* dst, const Vec2f* src, int size) { memcpy(dst, src, size * sizeof(Vec2f)); }
711 inline void ArrayBase<Vec3i,S32>::copy(Vec3i* dst, const Vec3i* src, int size) { memcpy(dst, src, size * sizeof(Vec3i)); }
712 inline void ArrayBase<Vec3f,S32>::copy(Vec3f* dst, const Vec3f* src, int size) { memcpy(dst, src, size * sizeof(Vec3f)); }
713 inline void ArrayBase<Vec4i,S32>::copy(Vec4i* dst, const Vec4i* src, int size) { memcpy(dst, src, size * sizeof(Vec4i)); }
714 inline void ArrayBase<Vec4f,S32>::copy(Vec4f* dst, const Vec4f* src, int size) { memcpy(dst, src, size * sizeof(Vec4f)); }
715 
716 inline void ArrayBase<Mat2f,S32>::copy(Mat2f* dst, const Mat2f* src, int size) { memcpy(dst, src, size * sizeof(Mat2f)); }
717 inline void ArrayBase<Mat3f,S32>::copy(Mat3f* dst, const Mat3f* src, int size) { memcpy(dst, src, size * sizeof(Mat3f)); }
718 inline void ArrayBase<Mat4f,S32>::copy(Mat4f* dst, const Mat4f* src, int size) { memcpy(dst, src, size * sizeof(Mat4f)); }
719 
720 //------------------------------------------------------------------------
721 
722 inline void ArrayBase<S8,S64>::copy(S8* dst, const S8* src, S64 size) { memcpy(dst, src, (size_t)size * sizeof(S8)); }
723 inline void ArrayBase<U8,S64>::copy(U8* dst, const U8* src, S64 size) { memcpy(dst, src, (size_t)size * sizeof(U8)); }
724 inline void ArrayBase<S16,S64>::copy(S16* dst, const S16* src, S64 size) { memcpy(dst, src, (size_t)size * sizeof(S16)); }
725 inline void ArrayBase<U16,S64>::copy(U16* dst, const U16* src, S64 size) { memcpy(dst, src, (size_t)size * sizeof(U16)); }
726 inline void ArrayBase<S32,S64>::copy(S32* dst, const S32* src, S64 size) { memcpy(dst, src, (size_t)size * sizeof(S32)); }
727 inline void ArrayBase<U32,S64>::copy(U32* dst, const U32* src, S64 size) { memcpy(dst, src, (size_t)size * sizeof(U32)); }
728 inline void ArrayBase<F32,S64>::copy(F32* dst, const F32* src, S64 size) { memcpy(dst, src, (size_t)size * sizeof(F32)); }
729 inline void ArrayBase<S64,S64>::copy(S64* dst, const S64* src, S64 size) { memcpy(dst, src, (size_t)size * sizeof(S64)); }
730 inline void ArrayBase<U64,S64>::copy(U64* dst, const U64* src, S64 size) { memcpy(dst, src, (size_t)size * sizeof(U64)); }
731 inline void ArrayBase<F64,S64>::copy(F64* dst, const F64* src, S64 size) { memcpy(dst, src, (size_t)size * sizeof(F64)); }
732 
733 inline void ArrayBase<Vec2i,S64>::copy(Vec2i* dst, const Vec2i* src, S64 size) { memcpy(dst, src, (size_t)size * sizeof(Vec2i)); }
734 inline void ArrayBase<Vec2f,S64>::copy(Vec2f* dst, const Vec2f* src, S64 size) { memcpy(dst, src, (size_t)size * sizeof(Vec2f)); }
735 inline void ArrayBase<Vec3i,S64>::copy(Vec3i* dst, const Vec3i* src, S64 size) { memcpy(dst, src, (size_t)size * sizeof(Vec3i)); }
736 inline void ArrayBase<Vec3f,S64>::copy(Vec3f* dst, const Vec3f* src, S64 size) { memcpy(dst, src, (size_t)size * sizeof(Vec3f)); }
737 inline void ArrayBase<Vec4i,S64>::copy(Vec4i* dst, const Vec4i* src, S64 size) { memcpy(dst, src, (size_t)size * sizeof(Vec4i)); }
738 inline void ArrayBase<Vec4f,S64>::copy(Vec4f* dst, const Vec4f* src, S64 size) { memcpy(dst, src, (size_t)size * sizeof(Vec4f)); }
739 
740 inline void ArrayBase<Mat2f,S64>::copy(Mat2f* dst, const Mat2f* src, S64 size) { memcpy(dst, src, (size_t)size * sizeof(Mat2f)); }
741 inline void ArrayBase<Mat3f,S64>::copy(Mat3f* dst, const Mat3f* src, S64 size) { memcpy(dst, src, (size_t)size * sizeof(Mat3f)); }
742 inline void ArrayBase<Mat4f,S64>::copy(Mat4f* dst, const Mat4f* src, S64 size) { memcpy(dst, src, (size_t)size * sizeof(Mat4f)); }
743 
744 //------------------------------------------------------------------------
745 
746 template<class T> class Array : public ArrayBase<T,S32>
747 {
748 public:
749  inline Array (void) : ArrayBase<T,S32>() { };
750  inline explicit Array (const T& item) : ArrayBase<T,S32>( item ) { };
751  inline Array (const T* ptr, S32 size) : ArrayBase<T,S32>( ptr, size ) { };
752  inline Array (const Array<T>& other) : ArrayBase<T,S32>( other ) { };
753 };
754 
755 template<class T> class Array64 : public ArrayBase<T,S64>
756 {
757 public:
758  inline Array64 (void) : ArrayBase<T,S64>() { };
759  inline explicit Array64 (const T& item) : ArrayBase<T,S64>( item ) { };
760  inline Array64 (const T* ptr, S64 size) : ArrayBase<T,S64>( ptr, size ) { };
761  inline Array64 (const Array64<T>& other) : ArrayBase<T,S64>( other ) { };
762 };
763 
764 
765 }
const T & getFirst(void) const
Definition: Array.hpp:258
#define NULL
Definition: Defs.hpp:39
static void copy(T *dst, const T *src, S size)
Definition: Array.hpp:630
S getStride(void) const
Definition: Array.hpp:218
T removeSwap(S idx)
Definition: Array.hpp:474
void ** ptr
Definition: DLLImports.cpp:74
Array64(const T *ptr, S64 size)
Definition: Array.hpp:760
unsigned __int64 U64
Definition: Defs.hpp:97
signed char S8
Definition: Defs.hpp:86
double F64
Definition: Defs.hpp:90
Array64(const T &item)
Definition: Array.hpp:759
void clear(void)
Definition: Array.hpp:359
S getNumBytes(void) const
Definition: Array.hpp:225
const T & operator[](S idx) const
Definition: Array.hpp:588
void reset(S size=0)
Definition: Array.hpp:317
const T & get(S idx) const
Definition: Array.hpp:232
float F32
Definition: Defs.hpp:89
const T & getLast(void) const
Definition: Array.hpp:272
Array(void)
Definition: Array.hpp:749
Array(const T &item)
Definition: Array.hpp:750
T * replace(S start, S end, S size)
Definition: Array.hpp:502
bool removeItem(const T &item)
Definition: Array.hpp:577
void init(void)
Definition: App.cpp:770
signed short S16
Definition: Defs.hpp:87
static void copyOverlap(T *dst, const T *src, S size)
Definition: Array.hpp:643
FW_CUDA_FUNC T min(const VectorBase< T, L, S > &v)
Definition: Math.hpp:461
FW_CUDA_FUNC T max(const VectorBase< T, L, S > &v)
Definition: Math.hpp:462
Array64(const Array64< T > &other)
Definition: Array.hpp:761
void * realloc(void *ptr, size_t size)
Definition: Defs.cpp:191
S getCapacity(void) const
Definition: Array.hpp:195
#define FW_ASSERT(X)
Definition: Defs.hpp:67
signed int S32
Definition: Defs.hpp:88
ArrayBase< T, S > & operator=(const ArrayBase< T, S > &other)
Definition: Array.hpp:602
T & add(void)
Definition: Array.hpp:384
void setCapacity(S numElements)
Definition: Array.hpp:326
void reserve(S numElements)
Definition: Array.hpp:376
~ArrayBase(void)
Definition: Array.hpp:181
signed __int64 S64
Definition: Defs.hpp:98
unsigned int U32
Definition: Defs.hpp:85
T & insert(S idx)
Definition: Array.hpp:419
Array(const T *ptr, S32 size)
Definition: Array.hpp:751
bool operator==(const ArrayBase< T, S > &other) const
Definition: Array.hpp:610
S lastIndexOf(const T &item) const
Definition: Array.hpp:553
unsigned char U8
Definition: Defs.hpp:83
unsigned short U16
Definition: Defs.hpp:84
void compact(void)
Definition: Array.hpp:335
void getRange(S start, S end, T *ptr) const
Definition: Array.hpp:286
T set(S idx, const T &item)
Definition: Array.hpp:248
T & removeLast(void)
Definition: Array.hpp:465
ArrayBase(void)
Definition: Array.hpp:150
const T * getPtr(S idx=0) const
Definition: Array.hpp:202
Array(const Array< T > &other)
Definition: Array.hpp:752
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr size
Definition: DLLImports.inl:319
bool operator!=(const ArrayBase< T, S > &other) const
Definition: Array.hpp:623
void resize(S size)
Definition: Array.hpp:366
S getSize(void) const
Definition: Array.hpp:188
T remove(S idx)
Definition: Array.hpp:449
S indexOf(const T &item, S fromIdx=0) const
Definition: Array.hpp:543
void setRange(S start, S end, const T *ptr)
Definition: Array.hpp:302
Array64(void)
Definition: Array.hpp:758
bool contains(const T &item) const
Definition: Array.hpp:570