34#define AGX_DECLARE_VECTOR_TYPES(type) \
35typedef agx::Vector<type ## Ref> type ## RefVector; \
36typedef agx::Vector<type ## Observer> type ## ObserverVector; \
37typedef agx::VectorPOD<type *> type ## PtrVector
41# pragma warning( disable: 4345)
51 template<
typename T,
typename Allocator = ByteAllocator >
124 T&
at(
size_t index)
const;
128 template <
typename T2>
176 template <
typename T2>
185 template <
typename T2>
186 size_t find(
const T2& element)
const;
194 template <
typename T2>
198 void insert(
size_t index,
const T& value);
200 template <
typename InputIterator>
212 size_t getNumActiveElements() const;
216 void reallocate(
size_t size);
217 void constructElements(
size_t startIndex,
size_t endIndex);
218 void constructElements(
size_t startIndex,
size_t endIndex, const T& value);
219 void destroyElements(
size_t startIndex,
size_t endIndex);
222 Real32 m_smoothingAverage;
225 template<typename T, typename A>
228 template<typename T, typename A>
231 template<typename T, typename A>
234 template<typename T, typename A>
314 T&
at(
size_t index)
const;
362 template <
typename T2>
370 template <
typename T2>
371 size_t find(
const T2& element)
const;
382 void insert(
size_t index,
const T& value);
384 template <
typename InputIterator>
395 size_t getNumActiveElements() const;
399 void reallocate(
size_t size);
400 void constructElements(
size_t startIndex,
size_t endIndex);
401 void constructElements(
size_t startIndex,
size_t endIndex, const T& value);
403 static T s_initializer;
406 Real32 m_smoothingAverage;
409 template<typename T, typename A>
412 template<typename T, typename A>
415 template<typename T, typename A>
418 template<typename T, typename A>
423 #define AGX_VECTOR_RESIZE_FACTOR 2.0f
424 #define AGX_VECTOR_SMOOTHING_FACTOR 0.8f
425 #define AGX_VECTOR_SHRINK_THRESHOLD 0.25f
426 #define AGX_VECTOR_MIN_SIZE 4
428 #define m_elements static_cast<T *>(this->m_buffer)
429 #define m_size this->m_size
430 #define m_capacity this->m_capacity
440 template <
typename T,
typename A>
446 template <
typename T,
typename A>
447 Vector<T, A>::Vector(
size_t size,
const T& value,
const A& allocator) : m_allocator(allocator), m_smoothingAverage(0.0)
450 this->resize(size, value);
453 template <
typename T,
typename A>
454 Vector<T, A>::Vector(
const Vector<T, A>& other) : m_smoothingAverage(0.0)
459 template <
typename T,
typename Allocator>
464 m_allocator = other.m_allocator;
466 m_smoothingAverage = other.m_smoothingAverage;
470 other.m_smoothingAverage =
Real32(0.0);
473 template <
typename T,
typename A>
474 Vector<T, A>::Vector(const_iterator first, const_iterator
end,
const A& allocator) : m_allocator(allocator), m_smoothingAverage(0.0)
480 template <
typename T,
typename A>
482 : m_allocator(allocator), m_smoothingAverage(0.0)
490 template <
typename T,
typename A>
496 this->destroyElements(0,
m_size);
498 if (policy == MAINTAIN_BUFFER)
502 else if (policy == SHRINK_BUFFER)
508 m_smoothingAverage = 0.0;
524 this->reallocate((
size_t)m_smoothingAverage);
530 template <
typename T,
typename A>
539 template <
typename T,
typename A>
545 this->reallocate(size);
547 this->constructElements(
m_size, size);
552 this->reallocate(size);
554 this->destroyElements(size,
m_size);
561 template <
typename T,
typename A>
567 this->reallocate(size);
569 this->constructElements(
m_size, size, value);
574 this->reallocate(size);
576 this->destroyElements(size,
m_size);
582 template <
typename T,
typename A>
586 this->reallocate(size);
591 template <
typename T,
typename A>
596 while (size > newCapacity)
598 this->reallocate(newCapacity);
604 template <
typename T,
typename A>
607 size_t newSize =
m_size + numElements;
611 this->constructElements(
m_size, newSize);
618 template <
typename T,
typename A>
624 for (
size_t i = 0; i <
m_size; i++)
631 template <
typename T,
typename A>
637 for (
size_t i = 0; i <
m_size; i++)
645 template <
typename T,
typename A>
651 this->clear(MAINTAIN_BUFFER);
652 m_allocator = other.m_allocator;
660 for (
size_t i = 0; i < other.
size(); i++)
668 template <
typename T,
typename A>
671 this->destroyElements(0,
m_size);
676 template <
typename T,
typename A>
679 template <
typename T,
typename A>
683 template <
typename T,
typename A>
686 agxAssertN(i <
m_size,
"Array index %llu is out of bounds, current size is %llu", (
long long unsigned)i, (
long long unsigned)
m_size);
690 template <
typename T,
typename A>
693 agxVerifyN(index <
m_size,
"Array index %llu is out of bounds, current size is %llu", (
long long unsigned)index, (
long long unsigned)
m_size);
698 template <
typename T,
typename A>
706 template <
typename T,
typename A>
714 template <
typename T,
typename A>
template <
typename T2>
726 template <
typename T,
typename A>
740 template <
typename T,
typename A>
753 template <
typename T,
typename A>
764 template <
typename T,
typename A>
767 size_t index = position - this->
begin();
769 return this->
begin() + index;
772 template <
typename T,
typename A>
775 size_t startIndex = start - this->
begin();
776 size_t endIndex =
end - this->
begin();
777 this->erase(startIndex, endIndex);
779 return this->
begin() + endIndex;
783 template <
typename T,
typename A>
791 for (
size_t i = index + 1; i <
m_size; i++)
805 template <
typename T,
typename A>
809 size_t numElements =
end - start;
824 template <
typename T,
typename A>
827 size_t index = position - this->
begin();
828 this->eraseFast(index);
829 return this->
begin() + index;
832 template <
typename T,
typename A>
835 agxAssertN(index <
m_size,
"Array index %llu is out of bounds, current size is %llu", (
long long unsigned)index, (
long long unsigned)
m_size);
842 template <
typename T,
typename A>
template <
typename T2>
845 return this->find(element) !=
m_size;
848 template <
typename T,
typename A>
851 return this->find(element) !=
m_size;
855 template <
typename T,
typename A>
template <
typename T2>
858 for (
size_t i = 0; i <
m_size; i++)
867 template <
typename T,
typename A>
template <
typename T2>
872 for (
size_t i = 0; i <
m_size; i++)
890 template <
typename T,
typename A>
893 size_t index = position - this->
begin();
894 this->insert(index, value);
895 return this->
begin() + index;
898 template <
typename T,
typename A>
template <
typename InputIterator>
902 size_t numElements = std::distance( first, last );
904 if (numElements == 0)
907 size_t index = it - this->
begin();
912 for (
size_t i =
m_size; i > index; i--) {
917 for (; first != last; first++)
918 ::new((
void *)&
m_elements[index++]) T(*first);
923 template <
typename T,
typename A>
926 this->insert(it, ilist.begin(), ilist.end());
929 template <
typename T,
typename A>
932 agxAssertN(index <=
m_size,
"Insert with invalid index %llu, size is %llu", (
long long unsigned)index, (
long long unsigned)
m_size);
937 for (
size_t i =
m_size; i > index; i--) {
946 template <
typename T,
typename A>
952 this->destroyElements(size,
m_size);
959 T *newBuf =
reinterpret_cast<T*
>(m_allocator.
allocateBytes(size *
sizeof(T)));
964 for (
size_t i = 0; i <
m_size; i++)
969 this->destroyElements(0,
m_size);
972 m_buffer = (
void *)newBuf;
977 template <
typename T,
typename A>
978 AGX_FORCE_INLINE void Vector<T, A>::constructElements(
size_t startIndex,
size_t endIndex)
980 for (
size_t i = startIndex; i < endIndex; i++)
984 template <
typename T,
typename A>
985 AGX_FORCE_INLINE void Vector<T, A>::constructElements(
size_t startIndex,
size_t endIndex,
const T& value)
987 for (
size_t i = startIndex; i < endIndex; i++)
991 template <
typename T,
typename A>
992 AGX_FORCE_INLINE void Vector<T, A>::destroyElements(
size_t startIndex,
size_t endIndex)
994 for (
size_t i = startIndex; i < endIndex; i++)
1000 template <
typename T,
typename A>
1003 template <
typename T,
typename A>
1007 template <typename T, typename A>
1011 template <typename VectorT>
1014 for (
size_t i = 0; i < vec.size(); i++)
1018 if (i < vec.size()-1)
1025 template <
typename T,
typename A>
1032 template <
typename T,
typename A>
1040 template <
typename T,
typename A>
1043 template <
typename T,
typename A>
1046 template <
typename T,
typename A>
1049 template <
typename T,
typename A>
1052 template <
typename T,
typename A>
1055 template <
typename T,
typename A>
1058 template <
typename T,
typename A>
1061 template <
typename T,
typename A>
1067 template<
typename T,
typename A>
1070 template<
typename T,
typename A>
1074 template <
typename T,
typename A>
1077 template <
typename T,
typename A>
1092 template <
typename T,
typename A>
1095 static_assert( std::is_trivially_destructible<T>::value,
"Non-POD type used in VectorPOD");
1099 template <
typename T,
typename A>
1100 VectorPOD<T, A>::VectorPOD(
size_t size,
const T& value,
const A& allocator) : m_allocator(allocator), m_smoothingAverage(0.0)
1103 this->resize(size, value);
1106 template <
typename T,
typename A>
1107 VectorPOD<T, A>::VectorPOD(
const VectorPOD<T, A>& other) : m_smoothingAverage(0.0)
1114 template <
typename T,
typename A>
1115 VectorPOD<T, A>::VectorPOD(VectorPOD<T, A>&& other)
1116 : Container(
std::move(other)), m_smoothingAverage(0.0)
1119 m_allocator = std::move(other.m_allocator);
1121 m_smoothingAverage = other.m_smoothingAverage;
1124 other.m_allocator = A();
1125 other.m_smoothingAverage =
Real32(0);
1130 template <
typename T,
typename A>
1131 VectorPOD<T, A>::VectorPOD(const_iterator first, const_iterator end,
const A& allocator) : m_allocator(allocator), m_smoothingAverage(0.0)
1134 this->insert(this->
begin(), first,
end);
1137 template <
typename T,
typename A>
1138 VectorPOD<T, A>::VectorPOD(std::initializer_list<T> values,
const A& allocator)
1139 : m_allocator(allocator), m_smoothingAverage(0.0)
1148 template <
typename T,
typename A>
1154 if (policy == MAINTAIN_BUFFER)
1158 else if (policy == SHRINK_BUFFER)
1164 m_smoothingAverage = 0.0;
1180 this->reallocate((
size_t)m_smoothingAverage);
1185 template <
typename T,
typename A>
1190 this->reallocate(
m_size);
1195 template <
typename T,
typename A>
1201 this->reallocate(size);
1203 this->constructElements(
m_size, size);
1208 this->reallocate(size);
1215 template <
typename T,
typename A>
1221 this->reallocate(size);
1223 this->constructElements(
m_size, size, value);
1228 this->reallocate(size);
1234 template <
typename T,
typename A>
1238 this->reallocate(size);
1242 template <
typename T,
typename A>
1247 while (size > newCapacity)
1249 this->reallocate(newCapacity);
1254 template <
typename T,
typename A>
1257 size_t newSize =
m_size + numElements;
1261 this->constructElements(
m_size, newSize);
1268 template <
typename T,
typename A>
1274 for (
size_t i = 0; i <
m_size; i++)
1281 template <
typename T,
typename A>
1287 for (
size_t i = 0; i <
m_size; i++)
1295 template <
typename T,
typename A>
1301 m_allocator = other.m_allocator;
1305 this->reallocate(other.
size());
1307 if (other.
size() > 0) {
1316 template <
typename T,
typename A>
1323 template <
typename T,
typename A>
1326 template <
typename T,
typename A>
1329 template <
typename T,
typename A>
1332 agxAssertN(i <
m_size,
"Array index %llu is out of bounds, current size is %llu", (
long long unsigned)i, (
long long unsigned)
m_size);
1337 template <
typename T,
typename A>
1340 agxVerifyN(index <
m_size,
"Array index %llu is out of bounds, current size is %llu", (
long long unsigned)index, (
long long unsigned)
m_size);
1345 template <
typename T,
typename A>
1353 template <
typename T,
typename A>
1361 template <
typename T,
typename A>
1373 template <
typename T,
typename A>
1385 template <
typename T,
typename A>
1394 template <
typename T,
typename A>
1397 size_t index = position - this->
begin();
1399 return this->begin() + index;
1402 template <
typename T,
typename A>
1405 size_t startIndex = start - this->
begin();
1406 size_t endIndex =
end - this->begin();
1407 this->erase(startIndex, endIndex);
1409 return this->begin() + endIndex;
1413 template <
typename T,
typename A>
1416 this->erase(index, index+1);
1419 template <
typename T,
typename A>
1423 size_t numElements =
end - start;
1435 template <
typename T,
typename A>
1438 size_t index = position - this->
begin();
1439 this->eraseFast(index);
1440 return this->begin() + index;
1443 template <
typename T,
typename A>
1446 agxAssertN(index <
m_size,
"Array index %llu is out of bounds, current size is %llu", (
long long unsigned)index, (
long long unsigned)
m_size);
1451 template <
typename T,
typename A>
template <
typename T2>
1454 return this->find(element) !=
m_size;
1457 template <
typename T,
typename A>
1460 return this->find(element) !=
m_size;
1464 template <
typename T,
typename A>
template <
typename T2>
1467 for (
size_t i = 0; i <
m_size; i++)
1477 template <
typename T,
typename A>
1482 for (
size_t i = 0; i <
m_size; i++)
1489 if (!searchMultiple)
1500 template <
typename T,
typename A>
1504 size_t index = position - this->
begin();
1505 this->insert(index, value);
1506 return this->begin() + index;
1510 template <
typename T,
typename A>
1513 this->insert(it, ilist.begin(), ilist.end());
1516 template <
typename T,
typename A>
template <
typename InputIterator>
1520 size_t numElements = std::distance( first, last );
1521 if (numElements == 0)
1524 size_t index = it - this->
begin();
1529 for (
size_t i =
m_size; i > index; i--)
1532 for (; first != last; first++)
1533 memcpy(&
m_elements[index++], &(*first),
sizeof(T));
1538 template <
typename T,
typename A>
1544 for (
size_t i =
m_size; i > index; i--)
1547 memcpy(&
m_elements[index], &value,
sizeof(T));
1553 template <
typename T,
typename A>
1566 memcpy(newBuf, oldBuf,
m_size *
sizeof(T));
1577 template <
typename T,
typename A>
1578 AGX_FORCE_INLINE void VectorPOD<T, A>::constructElements(
size_t startIndex,
size_t endIndex)
1580 for (
size_t i = startIndex; i < endIndex; i++)
1581 memcpy(&
m_elements[i], &s_initializer,
sizeof(T));
1584 template <
typename T,
typename A>
1585 AGX_FORCE_INLINE void VectorPOD<T, A>::constructElements(
size_t startIndex,
size_t endIndex,
const T& value)
1587 for (
size_t i = startIndex; i < endIndex; i++)
1588 memcpy((
void*)&
m_elements[i], (
void*)&value,
sizeof(T));
1592 template <
typename T,
typename A>
1595 template <
typename T,
typename A>
1599 template <typename T, typename A>
1604 template <typename T, typename A>
1605 T VectorPOD<T, A>::s_initializer;
1608 template <typename T, typename A>
1611 template <
typename T,
typename A>
1614 template <
typename T,
typename A>
1617 template <
typename T,
typename A>
1620 template <
typename T,
typename A>
1623 template <
typename T,
typename A>
1626 template <
typename T,
typename A>
1629 template <
typename T,
typename A>
1633 template<
typename T,
typename A>
1636 template<
typename T,
typename A>
1639 template <
typename T,
typename A>
1642 template <
typename T,
typename A>
1650 template <
typename T,
typename A>
1656 std::swap(this->m_smoothingAverage, other.m_smoothingAverage);
1659 template <
typename T,
typename A>
1665 std::swap(this->m_smoothingAverage, other.m_smoothingAverage);
1671#pragma warning (pop)
#define AGX_VECTOR_SMOOTHING_FACTOR
#define AGX_VECTOR_SHRINK_THRESHOLD
#define AGX_VECTOR_RESIZE_FACTOR
#define AGX_VECTOR_MIN_SIZE
void setContainer(class Container *)
void deallocateBytes(void *buffer, size_t numBytes)
Deallocate a section previously allocated using allocateBytes method.
void * allocateBytes(size_t numBytes, size_t alignment=16)
Allocate a memory section of specified alignment.
The Container is the base class for several of the container classes proided by AGX,...
ClearPolicy
agxData::Values from this enumeration is passed to the subclasses' 'clear' method in order to control...
@ SHRINK_BUFFER_AVERAGED
Buffer is shrunk if a smoothing average (which is updated each clear call) goes below a threshold.
size_t capacity() const
Returns the size of the memory are used by the container to store its elements.
Vector containing 'raw' data.
VectorPOD(size_t size, const T &value=T(), const Allocator &allocator=Allocator())
void resize(size_t size)
Resize the vector, which then enables direct addressing using the bracket '[]' operator.
const_iterator begin() const
iterator insert(iterator position, const T &value)
void push_back(const T &value)
reverse_iterator rbegin()
const_iterator end() const
std::reverse_iterator< iterator > reverse_iterator
const_reverse_iterator rend() const
bool contains(const T2 &element) const
Test if the vector contains a certain element.
VectorPOD(const_iterator first, const_iterator end, const Allocator &allocator=Allocator())
VectorPOD(std::initializer_list< T > values, const Allocator &allocator=Allocator())
iterator eraseFast(const_iterator position)
Fast erase, replacing the erased element with the last element.
T & at(size_t index) const
ptrdiff_t difference_type
void shrink_to_fit()
Reduce the capacity of the vector to the actual size (number of elements)
VectorPOD(VectorPOD< T, Allocator > &&other)
T * ptr()
Get access to the internal data buffer.
VectorPOD(const VectorPOD< T, Allocator > &other)
const_reverse_iterator rbegin() const
bool findAndErase(const T &element, bool searchMultiple=false)
Find and erase an element.
void erase(size_t start, size_t end)
size_t find(const T2 &element) const
Find the index to a matching element, return size() if not found.
const T & const_reference
void insert(size_t index, const T &value)
void erase(size_t index)
Erase elements using indices instead of iterators.
void reserveAtLeast(size_t size)
Reserve capacity in the vector.
void eraseFast(size_t index)
void insert(const_iterator it, InputIterator first, InputIterator last)
void reserve(size_t size)
Reserve capacity in the vector.
void swap(VectorPOD &other)
void clear(ClearPolicy policy=SHRINK_BUFFER_AVERAGED)
Remove all elements, optionally with maintained buffer allocation.
bool contains(const T &element) const
const Allocator & allocator() const
void insert(const_iterator it, std::initializer_list< T > ilist)
iterator erase(iterator start, iterator end)
VectorPOD(const Allocator &allocator=Allocator())
void resize(size_t size, const T &value)
void push_back(T &&value)
T * increment(size_t numElements=1)
Resize using a increment.
iterator erase(iterator position)
STL erase functionality.
std::reverse_iterator< const_iterator > const_reverse_iterator
void clear(ClearPolicy policy=SHRINK_BUFFER_AVERAGED)
Remove all elements, optionally with maintained buffer allocation.
reverse_iterator rbegin()
size_t find(const T2 &element) const
Find the index to a matching element, return size() if not found.
const T & const_reference
std::random_access_iterator_tag iterator_category
Vector(const Vector< T, Allocator > &other)
void insert(const_iterator it, InputIterator first, InputIterator last)
void reserveAtLeast(size_t size)
Reserve capacity in the vector.
void push_back(T &&value)
void insert(size_t index, const T &value)
const Allocator & allocator() const
Vector(Vector< T, Allocator > &&other)
void insert(const_iterator it, std::initializer_list< T > ilist)
Vector(std::initializer_list< T > values, const Allocator &allocator=Allocator())
void push_back(const T &value)
iterator erase(iterator start, iterator end)
const_reverse_iterator rbegin() const
bool operator==(const Vector< T, Allocator > &other) const
Compare with other vector, return true if same size and all pairs are equal.
T * ptr()
Get access to the internal data buffer.
bool findAndErase(const T2 &element, bool searchMultiple=false)
Find and erase an element.
bool contains(const T &element) const
ptrdiff_t difference_type
void resize(size_t size)
Resize the vector, which then enables direct addressing using the bracket '[]' operator.
T & at(size_t index) const
void eraseFast(size_t index)
const_reverse_iterator rend() const
bool operator!=(const Vector< T, Allocator > &other) const
Vector(size_t size, const T &value=T(), const Allocator &allocator=Allocator())
void shrink_to_fit()
Reduce the capacity of the vector to the actual size (number of elements)
Vector(const_iterator first, const_iterator end, const Allocator &allocator=Allocator())
void reserve(size_t size)
Reserve capacity in the vector.
void erase(size_t index)
Erase elements using indices instead of iterators.
void push_back(const T2 &value)
iterator eraseFast(const_iterator position)
Fast erase, replacing the erased element with the last element.
T & operator[](size_t i) const
void erase(size_t start, size_t end)
iterator erase(iterator position)
STL erase functionality.
Vector(const Allocator &allocator=Allocator())
iterator insert(iterator position, const T &value)
Vector< T, Allocator > & operator=(const Vector< T, Allocator > &other)
std::reverse_iterator< iterator > reverse_iterator
const_iterator begin() const
const_iterator end() const
bool contains(const T2 &element) const
Test if the vector contains a certain element.
T * increment(size_t numElements=1)
Resize using a increment.
std::reverse_iterator< const_iterator > const_reverse_iterator
void resize(size_t size, const T &value)
#define agxAssert1(expr, msg)
#define agxAssertN(expr, format,...)
#define agxVerifyN(expr, format,...)
#define DOXYGEN_END_INTERNAL_BLOCK()
#define DOXYGEN_START_INTERNAL_BLOCK()
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
std::ostream & printVector(std::ostream &output, const VectorT &vec)
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)
std::ostream & operator<<(std::ostream &os, const agx::AddedMassInteraction::Matrix6x6 &m)
LinearProbingHashSetImplementation< KeyT, HashT >::iterator begin(LinearProbingHashSetImplementation< KeyT, HashT > &set)
void swap(agx::Name &lhs, agx::Name &rhs)
Data type to bind an index and ranges associated with it.