1#ifndef SimTK_SimTKCOMMON_ARRAY_H_
2#define SimTK_SimTKCOMMON_ARRAY_H_
44#include <initializer_list>
50template <
class X>
struct ArrayIndexTraits;
51template <
class T,
class X=
unsigned>
class ArrayViewConst_;
52template <
class T,
class X=
unsigned>
class ArrayView_;
53template <
class T,
class X=
unsigned>
class Array_;
237 {
return (
unsigned long long)LLONG_MAX;}
258template <
class Integral,
class is64Bit>
struct ArrayIndexPackTypeHelper
259{
typedef Integral packed_size_type;};
262template<>
struct ArrayIndexPackTypeHelper<bool,FalseType>
263{
typedef unsigned short packed_size_type;};
264template<>
struct ArrayIndexPackTypeHelper<char,FalseType>
265{
typedef unsigned short packed_size_type;};
266template<>
struct ArrayIndexPackTypeHelper<unsigned char,FalseType>
267{
typedef unsigned short packed_size_type;};
268template<>
struct ArrayIndexPackTypeHelper<signed char,FalseType>
269{
typedef short packed_size_type;};
272template<>
struct ArrayIndexPackTypeHelper<bool,TrueType>
273{
typedef unsigned int packed_size_type;};
274template<>
struct ArrayIndexPackTypeHelper<char,TrueType>
275{
typedef unsigned int packed_size_type;};
276template<>
struct ArrayIndexPackTypeHelper<unsigned char,TrueType>
277{
typedef unsigned int packed_size_type;};
278template<>
struct ArrayIndexPackTypeHelper<signed char,TrueType>
279{
typedef int packed_size_type;};
280template<>
struct ArrayIndexPackTypeHelper<unsigned short,TrueType>
281{
typedef unsigned int packed_size_type;};
282template<>
struct ArrayIndexPackTypeHelper<short,TrueType>
283{
typedef int packed_size_type;};
285template <
class Integral>
struct ArrayIndexPackType
286{
typedef typename ArrayIndexPackTypeHelper<Integral,Is64BitPlatformType>
287 ::packed_size_type packed_size_type;};
360typedef typename ArrayIndexPackType<size_type>::packed_size_type
385: pData(0), nUsed(src.nUsed), nAllocated(0) {
386 if (nUsed) pData =
const_cast<T*
>(src.pData);
414: pData(0),nUsed(0),nAllocated(0) {
415 if (last1==first)
return;
418 "ArrayViewConst_<T>(first,last1)",
419 "One of the source pointers was null (0); either both must be"
420 " non-null or both must be null.");
423 "ArrayViewConst_<T>(first,last1)",
424 "The source data's size %llu is too big for this array which"
425 " is limited to %llu elements by its index type %s.",
426 this->ull(last1-first), ullMaxSize(), indexName());
428 pData =
const_cast<T*
>(first);
462: pData(0),nUsed(0),nAllocated(0) {
463 if (src.empty())
return;
466 "ArrayViewConst_<T>::ctor(std::vector<T>)",
467 "The source std::vector's size %llu is too big for this array which"
468 " is limited to %llu elements by its index type %s.",
469 this->ull(src.size()), ullMaxSize(), indexName());
471 pData =
const_cast<T*
>(&src.front());
482{
return *
reinterpret_cast<const Array_<T,X>*
>(
this); }
491 "ArrayViewConst_::deallocate(): called on an owner Array_");
519bool empty()
const {
return nUsed==0;}
525{
return size_type(nAllocated?nAllocated:nUsed); }
535bool isOwner()
const {
return nAllocated || pData==0;}
587 return pData[nUsed-1]; }
610 "For this operator, we must have 0 <= index <= size(), but"
611 " index==%llu and size==%llu.", this->ull(ix), ullSize());
613 "ArrayViewConst_<T>(index,length)",
614 "This operator requires 0 <= length <= size()-index, but"
615 " length==%llu and size()-index==%llu.",this->ull(length),this->ull(
size()-ix));
622{
return (*
this)(index,length); }
646const T*
cend()
const {
return pData + nUsed;}
648const T*
begin()
const {
return pData;}
650const T*
end()
const {
return pData + nUsed;}
672const T*
cdata()
const {
return pData;}
674const T*
data()
const {
return pData;}
691void setData(
const T* p) {pData =
const_cast<T*
>(p);}
693void incrSize() {++nUsed;}
694void decrSize() {--nUsed;}
700bool isSameSize(S sz)
const
701{
return ull(sz) == ullSize(); }
706bool isSizeOK(S srcSz)
const
707{
return ull(srcSz) <= ullMaxSize(); }
714template<
class Iter>
static
715typename std::iterator_traits<Iter>::difference_type
716iterDistance(
const Iter& first,
const Iter& last1) {
717 return iterDistanceImpl(first,last1,
718 typename std::iterator_traits<Iter>::iterator_category());
724template<
class Iter>
static
725typename std::iterator_traits<Iter>::difference_type
726iterDistanceImpl(
const Iter& first,
const Iter& last1, std::input_iterator_tag) {
727 typename std::iterator_traits<Iter>::difference_type d = 0;
728 for (Iter src=first; src != last1; ++src, ++d)
735template<
class Iter>
static
736typename std::iterator_traits<Iter>::difference_type
737iterDistanceImpl(
const Iter& first,
const Iter& last1,
738 std::random_access_iterator_tag) {
739 return last1 - first;
751template<
class Iter>
bool
752overlapsWithData(
const Iter& first,
const Iter& last1) {
753 return overlapsWithDataImpl(first,last1,
754 typename std::iterator_traits<Iter>::iterator_category());
759template <
class T2>
bool
760overlapsWithData(
const T2* first,
const T2* last1) {
766 const T* obegin = std::max(
cbegin(), (
const T*)first);
767 const T* oend1 = std::min(
cend(), (
const T*)last1);
769 return obegin < oend1;
774template<
class Iter>
bool
775overlapsWithDataImpl(
const Iter&,
const Iter&, std::input_iterator_tag)
780template<
class Iter>
bool
781overlapsWithDataImpl(
const Iter& first,
const Iter& last1,
782 std::random_access_iterator_tag) {
793 return overlapsWithData(&*first, &*(last1-1));
800static unsigned long long ull(S sz)
801{
return (
unsigned long long)sz; }
804unsigned long long ullSize()
const {
return ull(
size());}
805unsigned long long ullCapacity()
const {
return ull(
capacity());}
806unsigned long long ullMaxSize()
const {
return ull(
max_size());}
866typedef typename ArrayIndexPackType<size_type>::packed_size_type
893{
return *
reinterpret_cast<const Array_<T,X>*
>(
this); }
925 avAssignIteratorDispatch(src.
cbegin(), src.
cend(),
926 std::random_access_iterator_tag(),
927 "ArrayView_<T>::operator=(ArrayView_<T>)");
934template <
class T2,
class X2>
936 if ((
const void*)&src != (
void*)
this)
937 avAssignIteratorDispatch(src.
cbegin(), src.
cend(),
938 std::random_access_iterator_tag(),
939 "ArrayView_<T>::operator=(Array_<T2>)");
948template <
class T2,
class X2>
953template <
class T2,
class X2>
959template <
class T2,
class A2>
961 avAssignIteratorDispatch(src.begin(), src.end(),
962 std::random_access_iterator_tag(),
963 "ArrayView_<T>::operator=(std::vector<T2>)");
969{
fill(fillValue);
return *
this; }
977 for (T* d =
begin(); d !=
end(); ++d)
987 "Assignment to an ArrayView is permitted only if the source"
988 " is the same size. Here n==%llu element(s) but the"
989 " ArrayView has a fixed size of %llu.",
990 this->ull(n), this->ull(
size()));
1013void assign(
const T2* first,
const T2* last1) {
1014 const char* methodName =
"ArrayView_<T>::assign(T2* first, T2* last1)";
1015 SimTK_ERRCHK((first&&last1)||(first==last1), methodName,
1016 "One of the source pointers was null (0); either both must be"
1017 " non-null or both must be null.");
1019 avAssignIteratorDispatch(first, last1, std::random_access_iterator_tag(),
1054template <
class Iter>
1055void assign(
const Iter& first,
const Iter& last1)
1057 "ArrayView_<T>::assign(Iter first, Iter last1)"); }
1158 "For this operator, we must have 0 <= index <= size(), but"
1159 " index==%llu and size==%llu.", this->ull(ix), ullSize());
1161 "ArrayView_<T>(index,length)",
1162 "This operator requires 0 <= length <= size()-index, but"
1163 " length==%llu and size()-index==%llu.",this->ull(length),this->ull(
size()-ix));
1170{
return (*
this)(index,length); }
1283template <
class IntegralType>
1284void avAssignDispatch(IntegralType n, IntegralType v,
TrueType isIntegralType,
1291template <
class InputIterator>
1292void avAssignDispatch(
const InputIterator& first,
const InputIterator& last1,
1293 FalseType isIntegralType,
const char* methodName)
1294{ avAssignIteratorDispatch(first, last1,
1295 typename std::iterator_traits<InputIterator>::iterator_category(),
1304template <
class InputIterator>
1305void avAssignIteratorDispatch(
const InputIterator& first,
1306 const InputIterator& last1,
1307 std::input_iterator_tag,
1308 const char* methodName)
1311 InputIterator src = first;
1312 while (src != last1 && p !=
end())
1318 "The supplied input_iterator provided only %llu elements but this"
1319 " ArrayView has a fixed size of %llu elements.",
1320 this->ull(nCopied), ullSize());
1329template <
class ForwardIterator>
1330void avAssignIteratorDispatch(
const ForwardIterator& first,
1331 const ForwardIterator& last1,
1332 std::forward_iterator_tag,
1333 const char* methodName)
1336 ForwardIterator src = first;
1337 while (src != last1 && p !=
end())
1343 "The supplied forward_ or bidirectional_iterator source range provided"
1344 " only %llu elements but this ArrayView has a fixed size of"
1345 " %llu elements.", this->ull(nCopied), ullSize());
1349 "The supplied forward_ or bidirectional_iterator source range"
1350 " contained too many elements; this ArrayView has a fixed size of"
1351 " %llu elements.", ullSize());
1358template <
class RandomAccessIterator>
1359void avAssignIteratorDispatch(
const RandomAccessIterator& first,
1360 const RandomAccessIterator& last1,
1361 std::random_access_iterator_tag,
1362 const char* methodName)
1365 "Assignment to an ArrayView is permitted only if the source"
1366 " is the same size. Here the source had %llu element(s) but the"
1367 " ArrayView has a fixed size of %llu.",
1368 this->ull(last1-first), this->ull(
size()));
1371 "Source range can't overlap with the destination data.");
1374 RandomAccessIterator src = first;
1388{
return this->CBase::psize(); }
1390{
return this->CBase::pallocated(); }
1394unsigned long long ullSize()
const
1395{
return this->CBase::ullSize(); }
1396unsigned long long ullCapacity()
const
1397{
return this->CBase::ullCapacity(); }
1398unsigned long long ullMaxSize()
const
1399{
return this->CBase::ullMaxSize(); }
1402const char* indexName()
const {
return this->CBase::indexName();}
1546typedef typename ArrayIndexPackType<size_type>::packed_size_type
1568 allocateNoConstruct(n);
1569 defaultConstruct(
data(),
data()+n);
1579 allocateNoConstruct(
size());
1580 fillConstruct(
begin(),
cend(), initVal);
1597template <
class InputIter>
1609 static_assert(std::is_assignable<T&,T2>::value,
1610 "Array_<T> construction from T2 requires that "
1611 "T2 implicitly converts to T");
1612 SimTK_ERRCHK((first&&last1)||(first==last1),
"Array_<T>(first,last1)",
1613 "Pointers must be non-null unless they are both null.");
1614 SimTK_ERRCHK3(this->isSizeOK(last1-first),
"Array_<T>(first,last1)",
1615 "Source has %llu elements but this array is limited to %llu"
1616 " elements by its index type %s.",
1617 this->ull(last1-first), ullMaxSize(), indexName());
1620 allocateNoConstruct(
size());
1637 if (v.empty())
return;
1639 SimTK_ERRCHK3(this->isSizeOK(v.size()),
"Array_<T>::ctor(std::vector<T2>)",
1640 "The source std::vector's size %llu is too big for this array which"
1641 " is limited to %llu elements by its index type %s.",
1642 this->ull(v.size()), ullMaxSize(), indexName());
1647 new (
this)
Array_(&v.front(), (&v.back())+1);
1655 setSize(src.
size());
1656 allocateNoConstruct(
size());
1672template <
class T2,
class X2>
1756 deallocateNoDestruct();
1818void assign(size_type n,
const T& fillValue) {
1819 SimTK_ERRCHK3(this->isSizeOK(n),
"Array_<T>::assign(n,value)",
1820 "Requested size %llu is too big for this array which is limited"
1821 " to %llu elements by its index type %s.",
1822 this->ull(n), ullMaxSize(), indexName());
1825 "Requested size %llu is not allowed because this is a non-owner"
1826 " array of fixed size %llu.", this->ull(n), this->ull(
size()));
1832 reallocateIfAdvisable(n);
1833 fillConstruct(
data(),
cdata()+n, fillValue);
1877void assign(
const T2* first,
const T2* last1) {
1878 const char* methodName =
"Array_<T>::assign(T2* first, T2* last1)";
1879 SimTK_ERRCHK((first&&last1)||(first==last1), methodName,
1880 "Pointers must be non-null unless they are both null.");
1881 SimTK_ERRCHK(!this->overlapsWithData(first,last1), methodName,
1882 "Source range can't overlap the current array contents.");
1884 assignIteratorDispatch(first,last1,std::random_access_iterator_tag(),
1924template <
class Iter>
1925void assign(
const Iter& first,
const Iter& last1) {
1927 "Array_<T>::assign(Iter first, Iter last1)");
1937 assignIteratorDispatch(src.
begin(), src.
end(),
1938 std::random_access_iterator_tag(),
1939 "Array_<T>::operator=(Array_<T>)");
1955template <
class T2,
class X2>
1957 assignIteratorDispatch(src.
begin(), src.
end(),
1958 std::random_access_iterator_tag(),
1959 "Array_<T>::operator=(Array_<T2,X2>)");
1968template <
class T2,
class A>
1970 assignIteratorDispatch(src.begin(), src.end(),
1971 std::random_access_iterator_tag(),
1972 "Array_<T>::operator=(std::vector)");
1984 T*
const pTmp=
data(); setData(other.
data()); other.setData(pTmp);
1998 SimTK_ERRCHK2(dataSize <= dataCapacity,
"Array_<T>::adoptData()",
1999 "Specified data size %llu was greater than the specified data"
2000 " capacity of %llu.", this->ull(dataSize), this->ull(dataCapacity));
2001 SimTK_ERRCHK(newData || dataCapacity==0,
"Array_<T>::adoptData()",
2002 "A null data pointer is allowed only if the size and capacity are"
2003 " specified as zero.");
2004 SimTK_ERRCHK(!this->overlapsWithData(newData, newData+dataSize),
2005 "Array_<T>::adoptData()",
2006 "The new data can't overlap with the old data.");
2011 setAllocated(dataCapacity);
2017{
return adoptData(newData, dataSize, dataSize); }
2035 SimTK_ERRCHK(newData || dataSize==0,
"Array_<T>::shareData()",
2036 "A null data pointer is allowed only if the size is zero.");
2037 SimTK_ERRCHK(!this->overlapsWithData(newData, newData+dataSize),
2038 "Array_<T>::shareData()",
2039 "The new data can't overlap with the old data.");
2052 "Array_<T>::shareData(first,last1)",
2053 "Requested size %llu is too big for this array which is limited"
2054 " to %llu elements by its index type %s.",
2055 this->ull(last1-first), ullMaxSize(), indexName());
2092 if (n ==
size())
return;
2095 "Requested size change to %llu is not allowed because this is a "
2096 "non-owner array of fixed size %llu.",
2097 this->ull(n), this->ull(
size()));
2114 if (n ==
size())
return;
2117 "Requested size change to %llu is not allowed because this is a"
2118 " non-owner array of fixed size %llu.", this->ull(n), this->ull(
size()));
2141 "Requested capacity change to %llu is not allowed because this is a "
2142 "non-owner array of fixed size %llu.",
2143 this->ull(n), this->ull(
size()));
2145 T* newData = allocN(n);
2146 moveConstructThenDestructSource(newData, newData+
size(),
data());
2177 T* newData = allocN(
size());
2178 moveConstructThenDestructSource(newData, newData+
size(),
data());
2179 deallocateNoDestruct();
2181 setAllocated(
size());
2400 if (pallocated() == psize())
2401 growAtEnd(1,
"Array_<T>::push_back(const T& value)");
2402 copyConstruct(
end(), value);
2411 if (pallocated() == psize())
2412 growAtEnd(1,
"Array_<T>::push_back(T&& value)");
2413 moveConstruct(
end(), std::move(value));
2425template<
class... Args>
2427 if (pallocated() == psize())
2428 growAtEnd(1,
"Array_<T>::emplace_back(Args...)");
2429 new(
end()) T(std::forward<Args>(args)...);
2451 if (pallocated() == psize())
2452 growAtEnd(1,
"Array_<T>::push_back()");
2453 defaultConstruct(
end());
2478 if (pallocated() == psize())
2479 growAtEnd(1,
"Array_<T>::raw_push_back()");
2512 "Array_<T>::erase(first,last1)",
"Pointers out of range or out of order.");
2516 "No elements can be erased from a non-owner array.");
2519 destruct(first, last1);
2520 moveElementsDown(first+nErased, nErased);
2521 setSize(
size()-nErased);
2547 "Array_<T>::erase(p)",
"Pointer must point to a valid element.");
2549 "No elements can be erased from a non-owner array.");
2552 moveElementsDown(p+1, 1);
2580 "Array_<T>::eraseFast(p)",
"Pointer must point to a valid element.");
2582 "No elements can be erased from a non-owner array.");
2586 moveOneElement(p, &
back());
2600 "clear() is not allowed for a non-owner array.");
2633 T*
const gap = insertGapAt(p, n,
"Array_<T>::insert(p,n,value)");
2635 fillConstruct(gap, gap+n, value);
2645 T*
const gap = insertGapAt(p, 1,
"Array_<T>::insert(p,value)");
2647 copyConstruct(gap, value);
2657template <
class... Args>
2659 T*
const gap = insertGapAt(p, 1,
"Array_<T>::emplace(p,Args...)");
2661 new(gap) T(std::forward<Args>(args)...);
2696T*
insert(T* p,
const T2* first,
const T2* last1) {
2697 const char* methodName =
"Array_<T>::insert(T* p, T2* first, T2* last1)";
2698 SimTK_ERRCHK((first&&last1) || (first==last1), methodName,
2699 "One of first or last1 was null; either both or neither must be null.");
2700 SimTK_ERRCHK(!this->overlapsWithData(first,last1), methodName,
2701 "Source range can't overlap with the current array contents.");
2703 return insertIteratorDispatch(p, first, last1,
2704 std::random_access_iterator_tag(),
2710template <
class Iter>
2711T*
insert(T* p,
const Iter& first,
const Iter& last1) {
2712 return insertDispatch(p, first, last1,
2714 "Array_<T>::insert(T* p, Iter first, Iter last1)");
2739T* growWithGap(T* gapPos,
size_type gapSz,
const char* methodName) {
2744 "Given insertion point is not valid for this array.");
2747 setAllocated(calcNewCapacityForGrowthBy(gapSz, methodName));
2754 T* newGap = newData + nBefore;
2755 T* newGapEnd = newGap + gapSz;
2758 moveConstructThenDestructSource(newData, newGap,
data());
2760 moveConstructThenDestructSource(newGapEnd, newData+
size(), gapPos);
2763 freeN(
data()); setData(newData);
2768void growAtEnd(
size_type n,
const char* methodName) {
2771 setAllocated(calcNewCapacityForGrowthBy(n, methodName));
2774 moveConstructThenDestructSource(newData, newData+
size(),
data());
2776 freeN(
data()); setData(newData);
2789 "Can't grow this Array by %llu element(s) because it would"
2790 " then exceed the max_size of %llu set by its index type %s.",
2791 (
unsigned long long)n, ullMaxSize(), indexName());
2802 const size_type newCapacity = std::max(std::max(mustHave,wantToHave),
2811T* insertGapAt(T* p,
size_type n,
const char* methodName) {
2814 "Given insertion point is not valid for this Array.");
2819 "No elements can be inserted into a non-owner array.");
2829 moveElementsUp(p, n);
2831 setAllocated(calcNewCapacityForGrowthBy(n, methodName));
2834 moveConstructThenDestructSource(newdata, newdata+before,
data());
2837 moveConstructThenDestructSource(newdata+before+n,
2838 newdata+before+n+after,
2840 p = newdata + before;
2853template <
class IntegralType>
void
2854ctorDispatch(IntegralType n, IntegralType v, TrueType isIntegralType) {
2866template <
class InputIterator>
void
2867ctorDispatch(
const InputIterator& first,
const InputIterator& last1,
2868 FalseType isIntegralType)
2869{ ctorIteratorDispatch(first, last1,
2870 typename std::iterator_traits<InputIterator>::iterator_category()); }
2878template <
class InputIterator>
void
2879ctorIteratorDispatch(
const InputIterator& first,
const InputIterator& last1,
2880 std::input_iterator_tag)
2882 InputIterator src = first;
2883 while (src != last1) {
2892 "Array_::ctor(InputIterator first, InputIterator last1)",
2893 "There were still source elements available when the array"
2894 " reached its maximum size of %llu as determined by its index"
2895 " type %s.", ullMaxSize(), indexName());
2906template <
class ForwardIterator>
void
2907ctorIteratorDispatch(
const ForwardIterator& first,
const ForwardIterator& last1,
2908 std::forward_iterator_tag)
2910 typedef typename std::iterator_traits<ForwardIterator>::difference_type
2918 "Array_(ForwardIterator first, ForwardIterator last1)",
2919 "Iterators were out of order.");
2922 "Array_(ForwardIterator first, ForwardIterator last1)",
2923 "Source has %llu elements but this array is limited to %llu"
2924 " elements by its index type %s.",
2925 this->ull(nInput), ullMaxSize(), indexName());
2929 allocateNoConstruct(n);
2930 copyConstruct(
data(),
data()+n, first);
2938template <
class IntegralType>
2939T* insertDispatch(T* p, IntegralType n, IntegralType v,
2940 TrueType isIntegralType,
const char*)
2946template <
class InputIterator>
2947T* insertDispatch(T* p,
const InputIterator& first,
const InputIterator& last1,
2948 FalseType isIntegralType,
const char* methodName)
2949{
return insertIteratorDispatch(p, first, last1,
2950 typename std::iterator_traits<InputIterator>::iterator_category(),
2956template <
class InputIterator>
2957T* insertIteratorDispatch(T* p, InputIterator first, InputIterator last1,
2958 std::input_iterator_tag,
const char* methodName)
2961 while (first != last1) {
2964 "There were still source elements available when the array"
2965 " reached its maximum size of %llu as determined by its index"
2966 " type %s.", ullMaxSize(), indexName());
2980template <
class ForwardIterator>
2981T* insertIteratorDispatch(T* p,
const ForwardIterator& first,
2982 const ForwardIterator& last1,
2983 std::forward_iterator_tag,
2984 const char* methodName)
2986 typedef typename std::iterator_traits<ForwardIterator>::difference_type
2993 SimTK_ERRCHK(nInput >= 0, methodName,
"Iterators were out of order.");
2996 "Source has %llu elements which would make this array exceed the %llu"
2997 " elements allowed by its index type %s.",
2998 this->ull(nInput), ullMaxSize(), indexName());
3001 p = insertGapAt(p, n, methodName);
3002 copyConstruct(p, p+n, first);
3012template <
class IntegralType>
3013void assignDispatch(IntegralType n, IntegralType v, TrueType isIntegralType,
3014 const char* methodName)
3020template <
class InputIterator>
3021void assignDispatch(
const InputIterator& first,
const InputIterator& last1,
3022 FalseType isIntegralType,
const char* methodName)
3023{ assignIteratorDispatch(first, last1,
3024 typename std::iterator_traits<InputIterator>::iterator_category(),
3030template <
class InputIterator>
3031void assignIteratorDispatch(
const InputIterator& first,
3032 const InputIterator& last1,
3033 std::input_iterator_tag,
3034 const char* methodName)
3039 "Assignment to a non-owner array can only be done from a source"
3040 " designated with forward iterators or pointers because we"
3041 " must be able to verify that the source and destination sizes"
3045 InputIterator src = first;
3046 while (src != last1) {
3049 "There were still source elements available when the array"
3050 " reached its maximum size of %llu as determined by its index"
3051 " type %s.", ullMaxSize(), indexName());
3062template <
class ForwardIterator>
3063void assignIteratorDispatch(
const ForwardIterator& first,
3064 const ForwardIterator& last1,
3065 std::forward_iterator_tag,
3066 const char* methodName)
3068 typedef typename std::iterator_traits<ForwardIterator>::difference_type
3073 const IterDiffType nInput = this->iterDistance(first,last1);
3075 SimTK_ERRCHK(nInput >= 0, methodName,
"Iterators were out of order.");
3078 "Source has %llu elements but this Array is limited to %llu"
3079 " elements by its index type %s.",
3080 this->ull(nInput), ullMaxSize(), indexName());
3088 reallocateIfAdvisable(n);
3089 copyConstruct(
data(),
cdata()+n, first);
3097 "Source has %llu elements which does not match the size %llu "
3098 "of the non-owner array it is being assigned into.",
3099 this->ull(n), ullSize());
3102 ForwardIterator src = first;
3103 while (src != last1)
3119void reallocateIfAdvisable(
size_type n) {
3121 reallocateNoDestructOrConstruct(n);
3126{ setData(allocN(n)); setAllocated(n); }
3127void deallocateNoDestruct()
3128{ freeN(
data()); setData(0); setAllocated(0); }
3129void reallocateNoDestructOrConstruct(
size_type n)
3130{ deallocateNoDestruct(); allocateNoConstruct(n); }
3141 unsigned char* newdata =
new unsigned char[n *
sizeof(T)];
3143 unsigned char* b=newdata;
3144 const unsigned char* e=newdata+(n*
sizeof(T));
3145 while (b != e) *b++ = 0xff;
3147 return reinterpret_cast<T*
>(newdata);
3152static void freeN(T* p) {
3153 delete[]
reinterpret_cast<char*
>(p);
3157static void defaultConstruct(T* p) {
new(p) T();}
3159static void defaultConstruct(T* b,
const T* e)
3160{
while (b!=e)
new(b++) T(); }
3163static void fillConstruct(T* b,
const T* e,
const T& v)
3164{
while(b!=e)
new(b++) T(v); }
3167static void copyConstruct(T* p,
const T& v) {
new(p) T(v);}
3169static void moveConstruct(T* p, T&& v) {
new(p) T(std::move(v));}
3172static void copyConstruct(T* b,
const T* e, T* src)
3173{
while(b!=e)
new(b++) T(*src++); }
3175static void moveConstruct(T* b,
const T* e, T* src)
3176{
while(b!=e)
new(b++) T(std::move(*src++)); }
3180template <
class InputIterator>
3181static void copyConstruct(T* b,
const T* e, InputIterator src)
3182{
while(b!=e)
new(b++) T(*src++); }
3188static void copyConstructThenDestructSource(T* b,
const T* e, T* src)
3189{
while(b!=e) {
new(b++) T(*src); src++->~T();} }
3195static void moveConstructThenDestructSource(T* b,
const T* e, T* src)
3196{
while(b!=e) {
new(b++) T(std::move(*src)); src++->~T();} }
3202void moveOneElement(T* to, T* from) {
3205 moveConstruct(to, std::move(*from));
3212void moveElementsDown(T* p,
size_type n) {
3214 for (; p !=
end(); ++p)
3215 moveOneElement(p-n,p);
3226 moveOneElement(src+n, src);;
3231static void destruct(T* p) {p->~T();}
3233static void destruct(T* b,
const T* e)
3234{
while(b!=e) b++->~T(); }
3239bool isGrowthOK(S n)
const
3240{
return this->isSizeOK(ullCapacity() + this->ull(n)); }
3252void setData(
const T* p) {this->CBase::setData(p);}
3253void setSize(
size_type n) {this->CBase::setSize(n);}
3254void incrSize() {this->CBase::incrSize();}
3255void decrSize() {this->CBase::decrSize();}
3256void setAllocated(
size_type n) {this->CBase::setAllocated(n);}
3259unsigned long long ullSize()
const
3260{
return this->CBase::ullSize(); }
3261unsigned long long ullCapacity()
const
3262{
return this->CBase::ullCapacity(); }
3263unsigned long long ullMaxSize()
const
3264{
return this->CBase::ullMaxSize(); }
3267const char* indexName()
const {
return this->CBase::indexName();}
3279template <
class T,
class X>
static inline
3281 (std::istream& in,
bool isFixedSize,
Array_<T,X>& out)
3285 if (!in.good()) {in.setstate(std::ios::failbit);
return in;}
3295 numRequired = isFixedSize ? out.
size() : 0;
3303 std::ws(in);
if (in.fail())
return in;
3305 if (isFixedSize && numRequired != 0)
3306 in.setstate(std::ios_base::failbit);
3314 typename std::iostream::int_type ch;
3317 const typename std::iostream::int_type EOFch =
3318 std::iostream::traits_type::eof();
3322 bool lookForCloser =
true;
3323 ch = in.peek();
if (in.fail())
return in;
3324 assert(ch != EOFch);
3326 char openBracket{
static_cast<char>(ch)}, closeBracket{};
3327 if (openBracket==
'(') {in.get(); closeBracket =
')';}
3328 else if (openBracket==
'[') {in.get(); closeBracket =
']';}
3329 else if (openBracket==
'{') {in.get(); closeBracket =
'}';}
3330 else lookForCloser =
false;
3336 if (in.good()) std::ws(in);
3342 assert(lookForCloser);
3343 in.setstate(std::ios::failbit);
3353 bool commaOK =
true, commaRequired =
false;
3354 bool terminatorSeen =
false;
3371 if (lookForCloser) {
3373 std::ws(in);
if (!in.good())
break;
3374 ch = in.peek(); assert(ch != EOFch);
3375 if (!in.good())
break;
3377 if (c == closeBracket) {
3379 terminatorSeen =
true;
3389 if (isFixedSize && (nextIndex == numRequired))
3393 if (commaOK && nextIndex != 0) {
3395 std::ws(in);
if (!in.good())
break;
3396 ch = in.peek(); assert(ch != EOFch);
3397 if (!in.good())
break;
3401 commaRequired =
true;
3404 { in.setstate(std::ios::failbit);
break; }
3405 else commaOK =
false;
3407 if (!in.good())
break;
3418 in >> out[nextIndex];
if (in.fail())
break;
3421 if (!in.good())
break;
3435 if (lookForCloser && !terminatorSeen)
3436 in.setstate(std::ios::failbit);
3438 if (isFixedSize && nextIndex != numRequired)
3439 in.setstate(std::ios::failbit);
3471template <
class T,
class X>
inline void
3473 for (X i(0); i < v.
size(); ++i) {
3474 if (i != 0) o <<
" ";
3483template <
class T,
class X>
inline void
3486 for (X i(0); i < v.
size(); ++i) {
3487 if (i != 0) o <<
',';
3499template <
class T,
class X>
inline
3507 for (
const T* p = a.
begin()+1; p != a.
end(); ++p)
3517template <
class T,
class X>
inline bool
3531template <
class T,
class X>
inline bool
3533 for (X i(0); i < v.
size(); ++i)
3544template <
class T,
class X>
inline bool
3546 return !readArrayFromStream(in,v).fail();
3554template <
class T,
class X>
inline bool
3556 return !fillArrayViewFromStream(in,v).fail();
3588template <
class T,
class X>
static inline
3590{
return readArrayFromStreamHelper<T,X>(in,
false , out); }
3618template <
class T,
class X>
static inline
3620{
return readArrayFromStreamHelper<T,X>(in,
true , out); }
3626template <
class T,
class X>
static inline
3628{
return readArrayFromStreamHelper<T,X>(in,
true , out); }
3642template <
class T,
class X>
inline
3644{
return readArrayFromStream<T,X>(in, out); }
3653template <
class T,
class X>
inline
3655{
return fillArrayViewFromStream<T,X>(in, out); }
3669template <
class T1,
class X1,
class T2,
class X2>
inline bool
3672 const ptrdiff_t sz1 = a1.
end()-a1.
begin();
3673 const ptrdiff_t sz2 = a2.
end()-a2.
begin();
3674 if (sz1 != sz2)
return false;
3675 const T1* p1 = a1.
begin();
3676 const T2* p2 = a2.
begin();
3677 while (p1 != a1.
end())
3678 if (!(*p1++ == *p2++))
return false;
3683template <
class T1,
class X1,
class T2,
class X2>
inline bool
3685{
return !(a1 == a2); }
3691template <
class T1,
class X1,
class T2,
class X2>
inline bool
3693 const T1* p1 = a1.
begin();
3694 const T2* p2 = a2.
begin();
3695 while (p1 != a1.
end() && p2 != a2.
end()) {
3702 return p1 == a1.
end() && p2 != a2.
end();
3706template <
class T1,
class X1,
class T2,
class X2>
inline bool
3708{
return !(a1 < a2); }
3712template <
class T1,
class X1,
class T2,
class X2>
inline bool
3717template <
class T1,
class X1,
class T2,
class X2>
inline bool
3719{
return !(a1 > a2); }
3724template <
class T1,
class X1,
class T2,
class A2>
inline bool
3731template <
class T1,
class A1,
class T2,
class X2>
inline bool
3737template <
class T1,
class X1,
class T2,
class A2>
inline bool
3739{
return !(a1 == v2); }
3742template <
class T1,
class A1,
class T2,
class X2>
inline bool
3744{
return !(a2 == v1); }
3751template <
class T1,
class X1,
class T2,
class A2>
inline bool
3753{
return a1 < ArrayViewConst_<T2,size_t>(v2); }
3760template <
class T1,
class A1,
class T2,
class X2>
inline bool
3766template <
class T1,
class X1,
class T2,
class A2>
inline bool
3768{
return !(a1 < v2); }
3771template <
class T1,
class A1,
class T2,
class X2>
inline bool
3773{
return !(v1 < a2); }
3778template <
class T1,
class X1,
class T2,
class A2>
inline bool
3784template <
class T1,
class A1,
class T2,
class X2>
inline bool
3790template <
class T1,
class X1,
class T2,
class A2>
inline bool
3792{
return !(a1 > v2); }
3795template <
class T1,
class A1,
class T2,
class X2>
inline bool
3797{
return !(v1 > a2); }
3807template <
class T,
class X>
inline void
This file contains macros which are convenient to use for sprinkling error checking around liberally ...
#define SimTK_ERRCHK3_ALWAYS(cond, whereChecked, fmt, a1, a2, a3)
Definition ExceptionMacros.h:293
#define SimTK_INDEXCHECK(ix, ub, where)
Definition ExceptionMacros.h:145
#define SimTK_ERRCHK2_ALWAYS(cond, whereChecked, fmt, a1, a2)
Definition ExceptionMacros.h:289
#define SimTK_ERRCHK_ALWAYS(cond, whereChecked, msg)
Definition ExceptionMacros.h:281
#define SimTK_INDEXCHECK_ALWAYS(ix, ub, where)
Definition ExceptionMacros.h:106
#define SimTK_ERRCHK2(cond, whereChecked, fmt, a1, a2)
Definition ExceptionMacros.h:328
#define SimTK_ASSERT(cond, msg)
Definition ExceptionMacros.h:373
#define SimTK_ERRCHK1_ALWAYS(cond, whereChecked, fmt, a1)
Definition ExceptionMacros.h:285
#define SimTK_ERRCHK3(cond, whereChecked, fmt, a1, a2, a3)
Definition ExceptionMacros.h:330
#define SimTK_ERRCHK(cond, whereChecked, msg)
Definition ExceptionMacros.h:324
#define SimTK_SIZECHECK(sz, maxsz, where)
Definition ExceptionMacros.h:146
This file contains definitions of templatized serialize-to-stream methods specialized for the built-i...
Mandatory first inclusion for any Simbody source or header file.
#define SimTK_FORCE_INLINE
Definition SimTKcommon/include/SimTKcommon/internal/common.h:269
This Array_ helper class is the base class for ArrayView_ which is the base class for Array_; here we...
Definition Array.h:324
size_type allocated() const
Return the amount of heap space owned by this array; this is the same as capacity() for owner arrays ...
Definition Array.h:529
const T * end() const
The const version of end() is the same as cend().
Definition Array.h:650
const T & back() const
Return a const reference to the last element in this array, which must not be empty (we'll check in a...
Definition Array.h:585
bool empty() const
Return true if there are no elements currently stored in this array.
Definition Array.h:519
ArrayViewConst_ getSubArray(index_type index, size_type length) const
Same as const form of operator()(index,length); exists to provide non-operator access to that functio...
Definition Array.h:621
const T * cend() const
Return a const pointer to what would be the element just after the last one in the array; this may be...
Definition Array.h:646
ArrayIndexTraits< X >::difference_type difference_type
A signed integral type that can represent the difference between any two legitimate index values for ...
Definition Array.h:358
const T & operator[](index_type i) const
Select an element by its index, returning a const reference.
Definition Array.h:554
T * pointer
A writable pointer to a value_type.
Definition Array.h:339
T value_type
The type of object stored in this container.
Definition Array.h:335
T * iterator
A writable iterator for this container (same as pointer here).
Definition Array.h:347
const T & const_reference
A const value_type reference.
Definition Array.h:345
size_type max_size() const
Return the maximum allowable size for this array.
Definition Array.h:515
std::reverse_iterator< iterator > reverse_iterator
A writable reverse iterator for this container.
Definition Array.h:351
const T & getElt(index_type i) const
Same as the const form of operator[]; exists to provide a non-operator method for element access in c...
Definition Array.h:568
ArrayViewConst_(const ArrayViewConst_ &src)
Copy constructor is shallow; the constructed const array object will be referencing the original sour...
Definition Array.h:384
size_type size() const
Return the current number of elements stored in this array.
Definition Array.h:513
~ArrayViewConst_()
The destructor just disconnects the array view handle from its data; see disconnect() for more inform...
Definition Array.h:498
ArrayViewConst_()
Default constructor allocates no heap space and is very fast.
Definition Array.h:373
const T * begin() const
The const version of begin() is the same as cbegin().
Definition Array.h:648
const T * cdata() const
Return a const pointer to the first element of the array, or possibly (but not necessarily) null (0) ...
Definition Array.h:672
const T * const_iterator
A const iterator for this container (same as const_pointer here).
Definition Array.h:349
const T * const_pointer
A const pointer to a value_type.
Definition Array.h:341
const_reverse_iterator crend() const
Return the past-the-end reverse iterator that tests equal to a reverse iterator that has been increme...
Definition Array.h:659
const_reverse_iterator rbegin() const
The const version of rbegin() is the same as crbegin().
Definition Array.h:662
const T & front() const
Return a const reference to the first element in this array, which must not be empty (we'll check in ...
Definition Array.h:577
const T & at(index_type i) const
Same as operator[] but always range-checked, even in a Release build.
Definition Array.h:562
size_type capacity() const
Return the number of elements this array can currently hold without requiring reallocation.
Definition Array.h:524
const_reverse_iterator crbegin() const
Return a const reverse iterator pointing to the last element in the array or crend() if the array is ...
Definition Array.h:654
T & reference
A writable value_type reference.
Definition Array.h:343
std::reverse_iterator< const_iterator > const_reverse_iterator
A const reverse iterator for this container.
Definition Array.h:353
ArrayViewConst_ operator()(index_type index, size_type length) const
Select a contiguous subarray of the elements of this array and create another ArrayViewConst_ that re...
Definition Array.h:607
ArrayViewConst_(const T *first, const T *last1)
Construct an ArrayViewConst_<T> by referencing (sharing) a given range of const data [first,...
Definition Array.h:413
ArrayIndexTraits< X >::size_type size_type
An integral type suitable for all indices and sizes for this array.
Definition Array.h:355
ArrayViewConst_(const std::vector< T, A > &src)
Construct a ArrayViewConst_<T> by referencing (sharing) the data in a const std::vector<T>,...
Definition Array.h:461
void disconnect()
Disconnect this array handle from any data to which it refers, restoring it to the condition it would...
Definition Array.h:489
const T * data() const
The const version of the data() method is identical to cdata().
Definition Array.h:674
const_reverse_iterator rend() const
The const version of rend() is the same as crend().
Definition Array.h:664
ArrayIndexPackType< size_type >::packed_size_type packed_size_type
The integral type we actually use internally to store size_type values.
Definition Array.h:361
bool isOwner() const
Does this array own the data to which it refers? If not, it can't be resized, and the destructor will...
Definition Array.h:535
X index_type
The index type (an extension).
Definition Array.h:337
const T * cbegin() const
Return a const pointer to the first element of this array if any, otherwise cend(),...
Definition Array.h:641
This Array_ helper class is the base class for Array_, extending ArrayViewConst_ to add the ability t...
Definition Array.h:845
const T * cdata() const
Return a const pointer to the first element of the array, or possibly (but not necessarily) null (0) ...
Definition Array.h:1240
T & back()
Return a writable reference to the last element in this array, which must not be empty.
Definition Array.h:1135
void assign(size_type n, const T &fillValue)
This is the same as fill() but has the usual std::vector signature for compatibility; it will only wo...
Definition Array.h:985
bool isOwner() const
Definition Array.h:1268
const T * const_iterator
Definition Array.h:861
ArrayView_(std::vector< T, A > &v)
Construct to reference memory owned by a writable std::vector.
Definition Array.h:889
ArrayView_ & operator=(const ArrayViewConst_< T2, X2 > &src)
Assignment from any other array object is allowed as long as the number of elements matches and the t...
Definition Array.h:935
const T & at(index_type i) const
Same as operator[] but always range-checked, even in a Release build.
Definition Array.h:1092
const T & back() const
Return a const reference to the last element in this array, which must not be empty.
Definition Array.h:1128
ArrayView_ & operator=(const T &fillValue)
Fill assignment – all elements are set to fillValue.
Definition Array.h:968
size_type max_size() const
Definition Array.h:1264
const T * begin() const
The const version of begin() is the same as cbegin().
Definition Array.h:1190
T & front()
Return a writable reference to the first element in this array, which must not be empty.
Definition Array.h:1121
const_reverse_iterator crbegin() const
Return a const reverse iterator pointing to the last element in the array or crend() if the array is ...
Definition Array.h:1212
bool readUnformatted(std::istream &in, ArrayView_< T, X > &v)
Specialization of readUnformatted() for fixed-length ArrayView_<T,X>; reads whitespace-separated toke...
Definition Array.h:3532
ArrayView_ updSubArray(index_type index, size_type length)
Same as non-const operator()(index,length); exists to provide non-operator access to that functionali...
Definition Array.h:1169
void assign(const T2 *first, const T2 *last1)
Assign to this array to make it a copy of the elements in range [first,last1) given by ordinary point...
Definition Array.h:1013
T * pointer
Definition Array.h:856
T * end()
Return a writable pointer to what would be the element just after the last one in this array.
Definition Array.h:1208
static std::istream & fillArrayViewFromStream(std::istream &in, ArrayView_< T, X > &out)
Read in a fixed number of elements from a stream into an ArrayView.
Definition Array.h:3627
const T & getElt(index_type i) const
Same as the const form of operator[]; exists to provide a non-operator method for element access in c...
Definition Array.h:1102
const T & front() const
Return a const reference to the first element in this array, which must not be empty.
Definition Array.h:1114
~ArrayView_()
The destructor just disconnects the array view handle from its data; see ArrayViewConst_<T,...
Definition Array.h:905
const T * cend() const
Return a const pointer to what would be the element just after the last one in the array; this may be...
Definition Array.h:1201
size_type capacity() const
Definition Array.h:1266
T & at(index_type i)
Same as operator[] but always range-checked, even in a Release build.
Definition Array.h:1098
const T & const_reference
Definition Array.h:859
T * iterator
Definition Array.h:860
ArrayView_ & operator=(const Array_< T2, X2 > &src)
Assignment from any other array object is allowed as long as the number of elements matches and the t...
Definition Array.h:954
const T * cbegin() const
Return a const pointer to the first element of this array if any, otherwise end(),...
Definition Array.h:1188
std::reverse_iterator< iterator > reverse_iterator
Definition Array.h:862
reverse_iterator rend()
Return a writable past-the-end reverse iterator that tests equal to a reverse iterator that has been ...
Definition Array.h:1232
bool empty() const
Definition Array.h:1265
const T * end() const
The const version of end() is the same as cend().
Definition Array.h:1203
void disconnect()
Forward to base class disconnect() method – clears the handle without doing anything to the data.
Definition Array.h:901
ArrayView_(T *first, const T *last1)
Construct from a range of writable memory.
Definition Array.h:885
size_type size() const
Definition Array.h:1263
ArrayIndexPackType< size_type >::packed_size_type packed_size_type
Definition Array.h:867
T & operator[](index_type i)
Select an element by its index, returning a writable (lvalue) reference.
Definition Array.h:1085
bool readFormatted(std::istream &in, ArrayView_< T, X > &v)
Specialization of readFormatted() for fixed-length ArrayView_<T,X>; uses fillArrayViewFromStream() to...
Definition Array.h:3555
ArrayView_()
Default constructor allocates no heap space and is very fast.
Definition Array.h:879
T * begin()
Return a writable pointer to the first element of this array if any, otherwise end().
Definition Array.h:1195
T & reference
Definition Array.h:858
ArrayIndexTraits< X >::size_type size_type
Definition Array.h:864
ArrayView_ operator()(index_type index, size_type length)
Select a contiguous subarray of the elements of this array and create another ArrayView_ that refers ...
Definition Array.h:1155
ArrayIndexTraits< X >::difference_type difference_type
Definition Array.h:865
const T & operator[](index_type i) const
Select an element by its index, returning a const reference.
Definition Array.h:1075
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition Array.h:863
size_type allocated() const
Definition Array.h:1267
ArrayView_ & operator=(const std::vector< T2, A2 > &src)
Assignment from any std::vector object is allowed as long as the number of elements matches and the t...
Definition Array.h:960
std::istream & operator>>(std::istream &in, ArrayView_< T, X > &out)
Read a (fixed size n) ArrayView_<T> from a stream as a sequence of space- or comma-separated values o...
Definition Array.h:3654
const_reverse_iterator rbegin() const
The const version of rbegin() is the same as crbegin().
Definition Array.h:1215
const_reverse_iterator crend() const
Return the past-the-end reverse iterator that tests equal to a reverse iterator that has been increme...
Definition Array.h:1224
ArrayView_(const ArrayView_ &src)
Copy constructor is shallow.
Definition Array.h:882
ArrayView_ & fill(const T &fillValue)
Assign the supplied fill value to each element of this array, using T's copy assignment operator for ...
Definition Array.h:976
const T * const_pointer
Definition Array.h:857
T & updElt(index_type i)
Same as the non-const form of operator[]; exists to provide a non-operator method for element access ...
Definition Array.h:1106
reverse_iterator rbegin()
Return a writable reverse iterator pointing to the last element in the array or rend() if the array i...
Definition Array.h:1219
ArrayView_ & operator=(const ArrayView_< T2, X2 > &src)
Assignment from any other array object is allowed as long as the number of elements matches and the t...
Definition Array.h:949
const T * data() const
The const version of the data() method is identical to cdata().
Definition Array.h:1243
X index_type
Definition Array.h:855
T value_type
Definition Array.h:854
const_reverse_iterator rend() const
The const version of rend() is the same as crend().
Definition Array.h:1227
T * data()
Return a writable pointer to the first allocated element of the array, or a null pointer if no space ...
Definition Array.h:1247
void assign(const Iter &first, const Iter &last1)
Assign to this array to make it a copy of the elements in range [first,last1) given by non-pointer it...
Definition Array.h:1055
ArrayView_ & operator=(const ArrayView_ &src)
Copy assignment; source must be the same size as this array.
Definition Array.h:923
The Array_<T> container class is a plug-compatible replacement for the C++ standard template library ...
Definition Array.h:1520
void writeUnformatted(std::ostream &o, const Array_< T, X > &v)
Specialize writeUnformatted() for Array_<E,X> to delegate to element type E, with spaces separating t...
Definition Array.h:3472
T & back()
Return a writable reference to the last element in this array, which must not be empty.
Definition Array.h:2344
T * iterator
Definition Array.h:1540
static std::istream & readArrayFromStream(std::istream &in, Array_< T, X > &out)
Read in an Array_<T> from a stream, as a sequence of space-separated or comma-separated values option...
Definition Array.h:3589
ArrayView_< T, X > operator()(index_type index, size_type length)
Select a subrange of this array by starting index and length, and return an ArrayView_ referencing th...
Definition Array.h:2357
const T * cdata() const
Return a const pointer to the first element of the array, or possibly (but not necessarily) null (0) ...
Definition Array.h:2264
const T * begin() const
The const version of begin() is the same as cbegin().
Definition Array.h:2214
void assign(size_type n, const T &fillValue)
Set this array to be n copies of the supplied fillValue.
Definition Array.h:1818
void push_back(const T &value)
This method increases the size of the Array by one element at the end and initializes that element by...
Definition Array.h:2399
void assign(const T2 *first, const T2 *last1)
Assign to this array to to make it a copy of the elements in range [first,last1) given by ordinary po...
Definition Array.h:1877
void reserve(size_type n)
Ensure that this array has enough allocated capacity to hold the indicated number of elements.
Definition Array.h:2136
Array_ & operator=(const Array_ &src)
Copy assignment operator destructs the current contents of this array and then makes it a copy of the...
Definition Array.h:1935
bool operator>=(const std::vector< T1, A1 > &v1, const ArrayViewConst_< T2, X2 > &a2)
The greater than or equal operator is implemented using the less than operator.
Definition Array.h:3772
T & updElt(index_type i)
Same as the non-const form of operator[]; exists to provide a non-operator method for element access ...
Definition Array.h:2316
bool operator==(const ArrayViewConst_< T1, X1 > &a1, const ArrayViewConst_< T2, X2 > &a2)
Two Array_ objects are equal if and only if they are the same size() and each element compares equal ...
Definition Array.h:3670
const T * const_pointer
Definition Array.h:1537
Array_ & operator=(const std::vector< T2, A > &src)
This is assignment from a source std::vector<T2>.
Definition Array.h:1969
T * emplace(T *p, Args &&... args)
Insert a new element at a given location within this array, by invoking T's constructor whose signatu...
Definition Array.h:2658
const T & front() const
Return a const reference to the first element in this array, which must not be empty.
Definition Array.h:2323
T * raw_push_back()
(Deprecated, use emplace_back() instead) This dangerous non-standard method increases the Array's siz...
Definition Array.h:2477
T * insert(T *p, const T2 *first, const T2 *last1)
Insert elements in a range [first,last1) into this array at a given position p, moving all following ...
Definition Array.h:2696
Array_(std::vector< T, A > &v, const DontCopy &)
Construct an Array_<T> by referencing (sharing) the data in an std::vector<T>, without copying the da...
Definition Array.h:1736
static std::istream & fillArrayFromStream(std::istream &in, Array_< T, X > &out)
Read in a fixed number of elements from a stream into an Array.
Definition Array.h:3619
size_type allocated() const
Return the amount of heap space owned by this array; this is the same as capacity() for owner arrays ...
Definition Array.h:2187
Array_ & operator=(const Array_< T2, X2 > &src)
This is assignment from a source array whose element type T2 and/or index type X2 are different from ...
Definition Array.h:1956
bool operator==(const ArrayViewConst_< T1, X1 > &a1, const std::vector< T2, A2 > &v2)
An Array_<T1> and an std::vector<T2> are equal if and only if they are the same size() and each eleme...
Definition Array.h:3725
ArrayIndexTraits< X >::difference_type difference_type
Definition Array.h:1545
X index_type
Definition Array.h:1535
const T & const_reference
Definition Array.h:1539
void resize(size_type n)
Change the size of this Array, preserving all the elements that will still fit, and default construct...
Definition Array.h:2091
Array_(const std::vector< T2 > &v)
Construct an Array_<T> by copying from an std::vector<T2>, where T2 may be the same type as T but doe...
Definition Array.h:1636
Array_ & adoptData(T *newData, size_type dataSize)
A variant of adoptData() that assumes the capacity is the same as the current size.
Definition Array.h:2016
T & front()
Return a writable reference to the first element in this array, which must not be empty.
Definition Array.h:2330
const T * const_iterator
Definition Array.h:1541
void push_back(T &&value)
This is the move form of push_back(), taking an rvalue reference rather than an lvalue reference.
Definition Array.h:2410
const T & at(index_type i) const
Same as operator[] but always range-checked, even in a Release build.
Definition Array.h:2302
void swap(Array_ &other)
This is a specialized algorithm providing constant time exchange of data with another array that has ...
Definition Array.h:1983
Array_(T *first, const T *last1, const DontCopy &)
Construct an Array_<T> by referencing (sharing) a given range of data [first,last1),...
Definition Array.h:1706
void pop_back()
Remove the last element from this array, which must not be empty.
Definition Array.h:2487
reverse_iterator rend()
Return a writable past-the-end reverse iterator that tests equal to a reverse iterator that has been ...
Definition Array.h:2256
bool operator==(const std::vector< T1, A1 > &v1, const ArrayViewConst_< T2, X2 > &a2)
An std::vector<T1> and an Array_<T2> are equal if and only if they are the same size() and each eleme...
Definition Array.h:3732
T * end()
Return a writable pointer to what would be the element just after the last one in this array.
Definition Array.h:2232
T * erase(T *first, const T *last1)
Erase elements in range [first,last1), packing in any later elements into the newly-available space a...
Definition Array.h:2510
Array_ & deallocate()
Empty this array of its contents, returning the array to its default-constructed, all-zero state.
Definition Array.h:1753
bool readFormatted(std::istream &in, Array_< T, X > &v)
Specialization of readFormatted() for variable-length Array_<T,X>; uses readArrayFromStream() to cons...
Definition Array.h:3545
void fill(const T &fillValue)
Assign all current elements of the array to the same fillValue.
Definition Array.h:1852
bool operator!=(const ArrayViewConst_< T1, X1 > &a1, const std::vector< T2, A2 > &v2)
The not equal operator is implemented using the equal operator.
Definition Array.h:3738
void writeFormatted(std::ostream &o, const Array_< T, X > &v)
Specialize writeFormatted() for Array_<E,X> to delegate to element type E, with surrounding parenthes...
Definition Array.h:3484
bool readUnformatted(std::istream &in, Array_< T, X > &v)
Specialization of readUnformatted() for variable-length Array_<T,X>; continues reading whitespace-sep...
Definition Array.h:3518
T & operator[](index_type i)
Select an element by its index, returning a writable (lvalue) reference.
Definition Array.h:2296
Array_(const InputIter &first, const InputIter &last1)
Construct an Array_<T> from a range [first,last1) of values identified by a pair of iterators.
Definition Array.h:1598
T * insert(T *p, size_type n, const T &value)
Insert n copies of a given value at a particular location within this array, moving all following ele...
Definition Array.h:2632
Array_(const T2 *first, const T2 *last1)
Construct an Array_<T> from a range [first,last1) of values identified by a pair of ordinary pointers...
Definition Array.h:1608
size_type capacity() const
Return the number of elements this array can currently hold without requiring reallocation.
Definition Array.h:2085
Array_ & operator=(Array_ &&src)
Move assignment operator swaps the contents of this Array_ with the source Array_.
Definition Array.h:1945
Array_(size_type n)
Construct an array containing n default-constructed elements.
Definition Array.h:1566
T * eraseFast(T *p)
Be careful with this non-standard extension; it erases one element and then moves the last one in its...
Definition Array.h:2578
void push_back()
(Deprecated, use emplace_back() instead) This is a non-standard version of push_back() that increases...
Definition Array.h:2450
ArrayViewConst_< T, X > operator()(index_type index, size_type length) const
Select a subrange of this const array by starting index and length, and return a ArrayViewConst_ refe...
Definition Array.h:2348
bool operator!=(const std::vector< T1, A1 > &v1, const ArrayViewConst_< T2, X2 > &a2)
The not equal operator is implemented using the equal operator.
Definition Array.h:3743
ArrayIndexTraits< X >::size_type size_type
Definition Array.h:1544
Array_ & adoptData(T *newData, size_type dataSize, size_type dataCapacity)
This dangerous extension allows you to supply your own already-allocated heap space for use by this a...
Definition Array.h:1994
bool operator>=(const ArrayViewConst_< T1, X1 > &a1, const std::vector< T2, A2 > &v2)
The greater than or equal operator is implemented using the less than operator.
Definition Array.h:3767
const_reverse_iterator crend() const
Return the past-the-end reverse iterator that tests equal to a reverse iterator that has been increme...
Definition Array.h:2248
size_type size() const
Return the current number of elements stored in this array.
Definition Array.h:2075
Array_ & shareData(T *first, const T *last1)
Same as shareData(data,size) but uses a pointer range [first,last1) to identify the data to be refere...
Definition Array.h:2050
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition Array.h:1543
T * data()
Return a writable pointer to the first allocated element of the array, or a null pointer if no space ...
Definition Array.h:2271
std::reverse_iterator< iterator > reverse_iterator
Definition Array.h:1542
ArrayViewConst_< T, X > getSubArray(index_type index, size_type length) const
Same as const form of operator()(index,length); exists to provide non-operator access to that functio...
Definition Array.h:2352
const_reverse_iterator rend() const
The const version of rend() is the same as crend().
Definition Array.h:2251
bool operator!=(const ArrayViewConst_< T1, X1 > &a1, const ArrayViewConst_< T2, X2 > &a2)
The not equal operator is implemented using the equal operator.
Definition Array.h:3684
reverse_iterator rbegin()
Return a writable reverse iterator pointing to the last element in the array or rend() if the array i...
Definition Array.h:2243
T * erase(T *p)
Erase just one element, moving all subsequent elements down one slot and reducing the array's size by...
Definition Array.h:2545
void shrink_to_fit()
Request that the capacity of this array be reduced to the minimum necessary to hold the number of ele...
Definition Array.h:2172
void assign(const Iter &first, const Iter &last1)
Assign this array from a range [first,last1) given by non-pointer iterators.
Definition Array.h:1925
ArrayIndexPackType< size_type >::packed_size_type packed_size_type
Definition Array.h:1547
const T * end() const
The const version of end() is the same as cend().
Definition Array.h:2227
void resize(size_type n, const T &initVal)
Change the size of this array, preserving all the elements that will still fit, and initializing any ...
Definition Array.h:2113
Array_(std::initializer_list< T > ilist)
Construct an Array_<T> from an std::initializer_list whose elements were convertible to type T,...
Definition Array.h:1628
const T & back() const
Return a const reference to the last element in this array, which must not be empty.
Definition Array.h:2337
T value_type
Definition Array.h:1534
bool operator>(const ArrayViewConst_< T1, X1 > &a1, const ArrayViewConst_< T2, X2 > &a2)
The greater than operator is implemented by using less than with the arguments reversed,...
Definition Array.h:3713
bool empty() const
Return true if there are no elements currently stored in this array.
Definition Array.h:2080
bool operator>(const ArrayViewConst_< T1, X1 > &a1, const std::vector< T2, A2 > &v2)
The greater than operator is implemented by using less than with the arguments reversed,...
Definition Array.h:3779
const T * data() const
The const version of the data() method is identical to cdata().
Definition Array.h:2267
~Array_()
The destructor performs a deallocate() operation which may result in element destruction and freeing ...
Definition Array.h:1741
const T & operator[](index_type i) const
Select an element by its index, returning a const reference.
Definition Array.h:2286
void emplace_back(Args &&... args)
This is similar to push_back() but rather than copying, it constructs the element in place at the end...
Definition Array.h:2426
ArrayView_< T, X > updSubArray(index_type index, size_type length)
Same as non-const operator()(index,length); exists to provide non-operator access to that functionali...
Definition Array.h:2361
Array_(size_type n, const T &initVal)
Construct an array containing n elements each set to a copy of the given initial value.
Definition Array.h:1576
bool operator>(const std::vector< T1, A1 > &v1, const ArrayViewConst_< T2, X2 > &a2)
The greater than operator is implemented by using less than with the arguments reversed,...
Definition Array.h:3785
bool operator>=(const ArrayViewConst_< T1, X1 > &a1, const ArrayViewConst_< T2, X2 > &a2)
The greater than or equal operator is implemented using the less than operator.
Definition Array.h:3707
const_reverse_iterator rbegin() const
The const version of rbegin() is the same as crbegin().
Definition Array.h:2239
std::istream & operator>>(std::istream &in, Array_< T, X > &out)
Read an Array_<T> from a stream as a sequence of space- or comma-separated values of type T,...
Definition Array.h:3643
Array_()
Default constructor allocates no heap space and is very fast.
Definition Array.h:1560
size_type max_size() const
Return the maximum allowable size for this array.
Definition Array.h:2077
T * pointer
Definition Array.h:1536
T & reference
Definition Array.h:1538
const T & getElt(index_type i) const
Same as the const form of operator[]; exists to provide a non-operator method for element access in c...
Definition Array.h:2312
T & at(index_type i)
Same as operator[] but always range-checked, even in a Release build.
Definition Array.h:2308
T * insert(T *p, const Iter &first, const Iter &last1)
Insert elements in a range [first,last1) where the range is given by non-pointer iterators.
Definition Array.h:2711
const T * cbegin() const
Return a const pointer to the first element of this array if any, otherwise cend(),...
Definition Array.h:2212
bool isOwner() const
Does this array own the data to which it refers? If not, it can't be resized, and the destructor will...
Definition Array.h:2194
const_reverse_iterator crbegin() const
Return a const reverse iterator pointing to the last element in the array or crend() if the array is ...
Definition Array.h:2236
Array_ & shareData(T *newData, size_type dataSize)
This dangerous extension allows you to make this array handle refer to someone else's data without co...
Definition Array.h:2033
Array_(Array_ &&src)
Move constructor swaps in the source and leaves the source default constructed.
Definition Array.h:1662
T * begin()
Return a writable pointer to the first element of this array if any, otherwise end().
Definition Array.h:2219
Array_(const Array_< T2, X2 > &src)
Construct this Array_<T,X> as a copy of another Array_<T2,X2> where T2!=T or X2!=X.
Definition Array.h:1673
void clear()
Erase all the elements currently in this array without changing the capacity; equivalent to erase(beg...
Definition Array.h:2598
T * insert(T *p, const T &value)
Insert a new element at a given location within this array, initializing it to a copy of a given valu...
Definition Array.h:2644
const T * cend() const
Return a const pointer to what would be the element just after the last one in the array; this may be...
Definition Array.h:2225
Array_(const Array_ &src)
Copy constructor allocates exactly as much memory as is in use in the source (not its capacity) and c...
Definition Array.h:1654
An element has (1) a tagword, (2) a map of (name,value) pairs called attributes, and (3) a list of ch...
Definition Xml.h:1033
bool readUnformatted(std::istream &in, T &v)
The default implementation of readUnformatted<T> reads in the next whitespace-separated token and the...
Definition Serialize.h:176
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition Assembler.h:37
bool isSizeInRange(char sz, char mx)
Definition SimTKcommon/include/SimTKcommon/internal/common.h:338
std::ostream & operator<<(std::ostream &o, const ContactForce &f)
Definition CompliantContactSubsystem.h:387
static std::istream & readArrayFromStreamHelper(std::istream &in, bool isFixedSize, Array_< T, X > &out)
Definition Array.h:3281
bool operator<(const Row< N, E1, S1 > &l, const Row< N, E2, S2 > &r)
bool = v1[i] < v2[i], for all elements i
Definition Row.h:822
bool operator<=(const L &left, const R &right)
Definition SimTKcommon/include/SimTKcommon/internal/common.h:653
This is a special type used for causing invocation of a particular constructor or method overload tha...
Definition SimTKcommon/include/SimTKcommon/internal/common.h:670
This is a compile-time equivalent of "false", used in compile-time condition checking in templatized ...
Definition SimTKcommon/include/SimTKcommon/internal/common.h:678
static const char * name()
The default implementation of name() here returns the raw result from typeid(T).
Definition SimTKcommon/include/SimTKcommon/internal/common.h:862
This is a compile-time equivalent of "true", used in compile-time condition checking in templatized i...
Definition SimTKcommon/include/SimTKcommon/internal/common.h:681