17 #if !defined(ON_ARRAY_DEFS_INC_) 18 #define ON_ARRAY_DEFS_INC_ 22 #pragma ON_PRAGMA_WARNING_PUSH 30 #pragma ON_PRAGMA_WARNING_DISABLE_MSC(4100) 37 #pragma ON_PRAGMA_WARNING_DISABLE_MSC(4211) 59 return (T*)onrealloc(ptr,capacity*
sizeof(T));
115 #if defined(ON_HAS_RVALUEREF) 169 return ((
unsigned int)
m_count);
181 return ((
unsigned int)(
m_capacity*
sizeof(T)));
187 return ((
unsigned int)(
sizeof(T)));
194 return ON_CRC32(current_remainder,
m_count*
sizeof(
m_a[0]),
m_a);
200 #if defined(ON_DEBUG) 203 ON_ERROR(
"ON_SimpleArray[i]: i out of range.");
212 #if defined(ON_DEBUG) 215 ON_ERROR(
"ON_SimpleArray[i]: i out of range.");
225 #if defined(ON_DEBUG) 228 ON_ERROR(
"ON_SimpleArray[i]: i out of range.");
237 #if defined(ON_DEBUG) 240 ON_ERROR(
"ON_SimpleArray[i]: i out of range.");
247 #if defined(ON_RUNTIME_APPLE) 251 #if defined(ON_DEBUG) 254 ON_ERROR(
"ON_SimpleArray[i]: i out of range.");
264 #if defined(ON_DEBUG) 267 ON_ERROR(
"ON_SimpleArray[i]: i out of range.");
276 #if defined(ON_DEBUG) 279 ON_ERROR(
"ON_SimpleArray[i]: i out of range.");
289 #if defined(ON_DEBUG) 292 ON_ERROR(
"ON_SimpleArray[i]: i out of range.");
301 #if defined(ON_DEBUG) 304 ON_ERROR(
"ON_SimpleArray[i]: i out of range.");
310 #if defined(ON_RUNTIME_APPLE) 314 #if defined(ON_DEBUG) 317 ON_ERROR(
"ON_SimpleArray[i]: i out of range.");
397 return (i < (
unsigned int)
m_count) ?
m_a+i : 0;
409 return (i < (
unsigned int)
m_count) ?
m_a+i : 0;
415 return (i >= 0 && i < (ON__INT64)
m_count) ?
m_a+i : 0;
427 return (i >= 0 && i < (ON__INT64)
m_count) ?
m_a+i : 0;
455 if ( ele_cnt <= 0 || src_i < 0 || dest_i < 0 || src_i == dest_i ||
459 int capacity = dest_i + ele_cnt;
466 memmove( &
m_a[dest_i], &
m_a[src_i], ele_cnt*
sizeof(T) );
477 memset( (
void*)(&
m_a[
m_count]), 0,
sizeof(T) );
478 return m_a[m_count++];
489 const int s = (int)(&x -
m_a);
511 if ( count > 0 && p )
516 if ( newcapacity < count +
m_count )
520 memcpy( (
void*)(
m_a +
m_count), (
void*)(p), count*
sizeof(T) );
553 memset( (
void*)(&
m_a[
m_count]), 0,
sizeof(T) );
574 for ( ; i < j; i++, j-- ) {
595 for (
int i = 0; i <
m_count; i++ ) {
596 if (!memcmp(p,
m_a+i,
sizeof(T)))
605 for (
int i = 0; i <
m_count; i++ ) {
606 if (!compar(key,
m_a+i))
616 ? (
const T*)bsearch( key,
m_a,
m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar )
626 #if defined(ON_COMPILER_MSC1300) 627 rc = ((int)(found -
m_a));
628 #elif 8 == ON_SIZEOF_POINTER 632 const ON__UINT64 fptr = (ON__UINT64)found;
633 const ON__UINT64 aptr = (ON__UINT64)
m_a;
634 const ON__UINT64 sz = (ON__UINT64)
sizeof(T);
635 const ON__UINT64 i = (fptr - aptr)/sz;
641 const ON__UINT32 fptr = (ON__UINT32)found;
642 const ON__UINT32 aptr = (ON__UINT32)
m_a;
643 const ON__UINT32 sz = (ON__UINT32)
sizeof(T);
644 const ON__UINT32 i = (fptr - aptr)/sz;
666 ? (
const T*)bsearch( key,
m_a, count,
sizeof(T), (
int(*)(
const void*,
const void*))compar )
676 #if defined(ON_COMPILER_MSC1300) 677 rc = ((int)(found -
m_a));
678 #elif 8 == ON_SIZEOF_POINTER 682 const ON__UINT64 fptr = (ON__UINT64)found;
683 const ON__UINT64 aptr = (ON__UINT64)
m_a;
684 const ON__UINT64 sz = (ON__UINT64)
sizeof(T);
685 const ON__UINT64 i = (fptr - aptr)/sz;
691 const ON__UINT32 fptr = (ON__UINT32)found;
692 const ON__UINT32 aptr = (ON__UINT32)
m_a;
693 const ON__UINT32 sz = (ON__UINT32)
sizeof(T);
694 const ON__UINT32 i = (fptr - aptr)/sz;
714 ON_hsort(
m_a,
m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
726 ON_qsort(
m_a,
m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
736 if (
m_a &&
m_count > 0 && compar && index ) {
738 ON_Sort(sa, index,
m_a,
m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
747 bool ON_SimpleArray<T>::Sort( ON::sort_algorithm sa,
int* index,
int (*compar)(
const T*,
const T*,
void*),
void* p )
const 750 if (
m_a &&
m_count > 0 && compar && index ) {
752 ON_Sort(sa, index,
m_a,
m_count,
sizeof(T), (
int(*)(
const void*,
const void*,
void*))compar, p );
766 T* buffer = (T*)onmalloc(
m_count*
sizeof(buffer[0]));
767 memcpy( (
void*)(buffer), (
void*)(
m_a),
m_count*
sizeof(T) );
769 memcpy( (
void*)(
m_a+i), (
void*)(buffer+index[i]),
sizeof(T) );
835 int capacity = (new_capacity > 0 && new_capacity < ON_UNSET_UINT_INDEX)
885 const size_t cap_size = 32*
sizeof(
void*)*1024*1024;
891 int delta_count = 8 + cap_size/
sizeof(T);
894 return (
m_count + delta_count);
917 const size_t cap_size = 32*
sizeof(
void*)*1024*1024;
923 int delta_count = 8 + cap_size/
sizeof(T);
926 return (
m_count + delta_count);
958 #if defined(ON_HAS_RVALUEREF) 994 T* reptr = (T*)onrealloc(ptr,capacity*
sizeof(T));
995 if ( ptr && reptr && reptr != ptr )
1000 for ( i = 0; i < this->
m_count; i++ )
1002 reptr[i].MemoryRelocate();
1018 return (T*)onrealloc(ptr,capacity*
sizeof(T));
1027 for ( i = 0; i < this->
m_count; i++ )
1029 current_remainder = this->
m_a[i].DataCRC(current_remainder);
1031 return current_remainder;
1071 if(
this != &src ) {
1081 for ( i = 0; i <
m_count; i++ ) {
1090 #if defined(ON_HAS_RVALUEREF) 1144 return ((
unsigned int)
m_count);
1156 return ((
unsigned int)(
m_capacity*
sizeof(T)));
1162 return ((
unsigned int)(
sizeof(T)));
1168 #if defined(ON_DEBUG) 1171 ON_ERROR(
"ON_ClassArray[i]: i out of range.");
1181 #if defined(ON_DEBUG) 1184 ON_ERROR(
"ON_ClassArray[i]: i out of range.");
1193 #if defined(ON_DEBUG) 1196 ON_ERROR(
"ON_ClassArray[i]: i out of range.");
1205 #if defined(ON_DEBUG) 1208 ON_ERROR(
"ON_ClassArray[i]: i out of range.");
1214 #if defined(ON_RUNTIME_APPLE) 1218 #if defined(ON_DEBUG) 1221 ON_ERROR(
"ON_ClassArray[i]: i out of range.");
1231 #if defined(ON_DEBUG) 1234 ON_ERROR(
"ON_ClassArray[i]: i out of range.");
1243 #if defined(ON_DEBUG) 1246 ON_ERROR(
"ON_ClassArray[i]: i out of range.");
1255 #if defined(ON_DEBUG) 1258 ON_ERROR(
"ON_ClassArray[i]: i out of range.");
1267 #if defined(ON_DEBUG) 1270 ON_ERROR(
"ON_ClassArray[i]: i out of range.");
1276 #if defined(ON_RUNTIME_APPLE) 1280 #if defined(ON_DEBUG) 1283 ON_ERROR(
"ON_ClassArray[i]: i out of range.");
1363 return (i < (
unsigned int)
m_count) ?
m_a+i : 0;
1375 return (i < (
unsigned int)
m_count) ?
m_a+i : 0;
1382 return (i >= 0 && i < (ON__INT64)
m_count) ?
m_a+i : 0;
1388 return (i < (ON__UINT64)
m_count) ?
m_a+i : 0;
1394 return (i >= 0 && i < (ON__INT64)
m_count) ?
m_a+i : 0;
1400 return (i < (ON__UINT64)
m_count) ?
m_a+i : 0;
1424 if ( ele_cnt <= 0 || src_i < 0 || dest_i < 0 || src_i == dest_i ||
1428 int capacity = dest_i + ele_cnt;
1439 memmove( (
void*)(&
m_a[dest_i]), (
const void*)(&
m_a[src_i]), ele_cnt*
sizeof(T) );
1482 const int s = (int)(&x -
m_a);
1505 if ( count > 0 && p )
1510 if ( newcapacity < count +
m_count )
1511 newcapacity = count +
m_count;
1514 for ( i = 0; i < count; i++ ) {
1533 if ( i < m_count-1 ) {
1534 Move( i+1, i, m_count-1-i );
1537 memset( (
void*)(&
m_a[i]), 0,
sizeof(T) );
1561 memset( (
void*)(&
m_a[i]), 0,
sizeof(T) );
1565 memset( (
void*)(&
m_a[
m_count-1]), 0,
sizeof(T) );
1579 memset( (
void*)(&
m_a[i]), 0,
sizeof(T) );
1594 for ( ; i < j; i++, j-- ) {
1595 memcpy( (
void*)(t), (
void*)(&
m_a[i]),
sizeof(T) );
1596 memcpy( (
void*)(&
m_a[i]), (
void*)(&
m_a[j]),
sizeof(T) );
1597 memcpy( (
void*)(&
m_a[j]), (
void*)(t),
sizeof(T) );
1604 if ( i != j && i >= 0 && j >= 0 && i <
m_count && j <
m_count ) {
1606 memcpy( (
void*)(t), (
void*)(&
m_a[i]),
sizeof(T) );
1607 memcpy( (
void*)(&
m_a[i]), (
void*)(&
m_a[j]),
sizeof(T) );
1608 memcpy( (
void*)(&
m_a[j]), (
void*)(t),
sizeof(T) );
1615 for (
int i = 0; i <
m_count; i++ )
1626 const T* found = (key&&
m_a&&m_count>0) ? (
const T*)bsearch( key,
m_a, m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar ) :
nullptr;
1627 return (
nullptr != found && found >=
m_a) ? ((int)(found -
m_a)) : -1;
1633 if ( count > m_count )
1637 const T* found = (key&&
m_a&&m_count>0) ? (
const T*)bsearch( key,
m_a, count,
sizeof(T), (
int(*)(
const void*,
const void*))compar ) : nullptr;
1638 return (
nullptr != found && found >=
m_a) ? ((int)(found -
m_a)) : -1;
1645 if (
m_a && m_count > 0 && compar )
1648 ON_hsort(
m_a, m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
1658 if (
m_a && m_count > 0 && compar )
1661 ON_qsort(
m_a, m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
1675 if ( this->
m_a && this->m_count > 0 && compar )
1677 if ( this->m_count > 1 )
1679 ON_hsort( this->
m_a, this->m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
1684 for ( i = 0; i < this->
m_count; i++ )
1686 this->
m_a[i].MemoryRelocate();
1700 if ( this->
m_a && this->m_count > 0 && compar )
1702 if ( this->m_count > 1 )
1704 ON_qsort( this->
m_a, this->m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
1709 for ( i = 0; i < this->
m_count; i++ )
1711 this->
m_a[i].MemoryRelocate();
1724 if (
m_a && m_count > 0 && compar && index )
1727 ON_Sort(sa, index,
m_a, m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
1728 else if ( m_count == 1 )
1736 bool ON_ClassArray<T>::Sort( ON::sort_algorithm sa,
int* index,
int (*compar)(
const T*,
const T*,
void*),
void* p )
const 1739 if (
m_a && m_count > 0 && compar && index )
1742 ON_Sort(sa, index,
m_a, m_count,
sizeof(T), (
int(*)(
const void*,
const void*,
void*))compar, p );
1743 else if ( m_count == 1 )
1754 if (
m_a && m_count > 0 && index )
1757 T* buffer = (T*)onmalloc(m_count*
sizeof(buffer[0]));
1758 memcpy( (
void*)(buffer), (
void*)(
m_a), m_count*
sizeof(T) );
1759 for (i = 0; i <
m_count; i++ )
1760 memcpy( (
void*)(
m_a+i), (
void*)(buffer+index[i]),
sizeof(T) );
1776 memset( (
void*)(&
m_a[i]), 0,
sizeof(T) );
1825 int capacity = (new_capacity > 0 && new_capacity < ON_UNSET_UINT_INDEX)
1829 if ( capacity <= 0 ) {
1865 for ( i =
m_capacity-1; i >= capacity; i-- ) {
1868 if ( m_count > capacity )
1887 int ON_CompareIncreasing(
const T* a,
const T* b)
1897 int ON_CompareDecreasing(
const T* a,
const T* b)
1906 #pragma ON_PRAGMA_WARNING_POP void Empty()
Definition: opennurbs_array_defs.h:558
void EmergencyDestroy(void)
emergency bailout ///////////////////////////////////////////////////
Definition: opennurbs_array_defs.h:1129
int Capacity() const
Definition: opennurbs_array_defs.h:173
virtual ~ON_SimpleArray()
Definition: opennurbs_array_defs.h:90
T & operator[](int)
Definition: opennurbs_array_defs.h:1169
ON_SimpleArray() ON_NOEXCEPT
construction ////////////////////////////////////////////////////////
Definition: opennurbs_array_defs.h:63
T * At(int)
At(index) returns nullptr if index < 0 or index >= count.
Definition: opennurbs_array_defs.h:389
void Zero()
Definition: opennurbs_array_defs.h:778
void Append(const T &)
Definition: opennurbs_array_defs.h:1478
void Empty()
Definition: opennurbs_array_defs.h:1575
int Count() const
query ///////////////////////////////////////////////////////////////
Definition: opennurbs_array_defs.h:1139
T * Last()
Definition: opennurbs_array_defs.h:1408
T * KeepArray()
Definition: opennurbs_array_defs.h:1318
void Move(int, int, int)
implimentation //////////////////////////////////////////////////////
Definition: opennurbs_array_defs.h:451
int NewCapacity() const
Definition: opennurbs_array_defs.h:900
T * KeepArray()
Expert user tool to take charge of the memory used by the dyanmic array.
Definition: opennurbs_array_defs.h:349
T * Last()
Definition: opennurbs_array_defs.h:437
int m_count
Definition: opennurbs_array.h:360
virtual ~ON_ClassArray()
Definition: opennurbs_array_defs.h:1065
unsigned int SizeOfArray() const
Definition: opennurbs_array_defs.h:1157
ON_ObjectArray()
Class ON_ObjectArray<>
Definition: opennurbs_array_defs.h:937
void SetArray(T *)
Do not use this version of SetArray(). Use the one that takes a pointer, count and capacity...
Definition: opennurbs_array_defs.h:359
ON_SimpleArray< T > & operator=(const ON_SimpleArray< T > &)
Definition: opennurbs_array_defs.h:96
Definition: opennurbs_array.h:36
void Swap(int, int)
Definition: opennurbs_array_defs.h:583
bool Permute(const int *)
Definition: opennurbs_array_defs.h:1755
int Capacity() const
Definition: opennurbs_array_defs.h:1151
void Shrink()
Definition: opennurbs_array_defs.h:804
T * SetCapacity(size_t)
Definition: opennurbs_array_defs.h:825
virtual bool QuickSort(int(*)(const T *, const T *))
Sorts the array using the heap sort algorithm.
Definition: opennurbs_array_defs.h:1659
int m_capacity
Definition: opennurbs_array.h:708
ON_Object array is used to store lists of classes that are derived from ON_Object. It differs from ON_ClassArray in that the virtual ON_Object::MemoryRelocate function is called when growing the dynamic array requires changing the location of the memory buffer used to store the elements in the array.
Definition: opennurbs_array.h:725
int BinarySearch(const T *, int(*)(const T *, const T *)) const
Definition: opennurbs_array_defs.h:614
void ConstructDefaultElement(T *)
Definition: opennurbs_array_defs.h:1446
T * Reserve(size_t)
memory managment /////////////////////////////////////////////////
Definition: opennurbs_array_defs.h:1789
int BinarySearch(const T *, int(*)(const T *, const T *)) const
Definition: opennurbs_array_defs.h:1628
int Search(const T &) const
Definition: opennurbs_array_defs.h:593
virtual T * Realloc(T *, int)
low level memory managment //////////////////////////////////////////
Definition: opennurbs_array_defs.h:57
void Move(int, int, int)
implimentation //////////////////////////////////////////////////////
Definition: opennurbs_array_defs.h:1422
bool Sort(ON::sort_algorithm sort_algorithm, int *, int(*)(const T *, const T *)) const
Sort() fills in the index[] array so that array[index[i]] <= array[index[i+1]]. The array is not modi...
Definition: opennurbs_array_defs.h:1725
T * Realloc(T *, int)
low level memory managment ///////////////////////////////////////
Definition: opennurbs_array_defs.h:995
T * m_a
Definition: opennurbs_array.h:359
virtual bool HeapSort(int(*)(const T *, const T *))
Definition: opennurbs_array_defs.h:1646
void Insert(int, const T &)
Insert called with a reference uses operator =.
Definition: opennurbs_array_defs.h:1525
void MemSet(unsigned char)
Definition: opennurbs_array_defs.h:786
ON__UINT32 DataCRC(ON__UINT32 current_remainder) const
Definition: opennurbs_array_defs.h:1025
bool QuickSort(int(*)(const T *, const T *))
Definition: opennurbs_array_defs.h:722
void Insert(int, const T &)
Definition: opennurbs_array_defs.h:526
void SetCount(int)
low level memory managment //////////////////////////////////////////
Definition: opennurbs_array_defs.h:1811
int m_capacity
Definition: opennurbs_array.h:361
bool QuickSort(int(*)(const T *, const T *))
Sorts the array using the heap sort algorithm.
Definition: opennurbs_array_defs.h:1699
bool HeapSort(int(*)(const T *, const T *))
Definition: opennurbs_array_defs.h:1674
T * First()
Definition: opennurbs_array_defs.h:1346
ON_ClassArray< T > & operator=(const ON_ClassArray< T > &)
Assignment operator.
Definition: opennurbs_array_defs.h:1071
void Remove()
Definition: opennurbs_array_defs.h:1551
bool Permute(const int *)
Definition: opennurbs_array_defs.h:762
unsigned int UnsignedCount() const
Definition: opennurbs_array_defs.h:167
void Shrink()
Definition: opennurbs_array_defs.h:1797
void Append(const T &)
Definition: opennurbs_array_defs.h:482
T * Reserve(size_t)
memory managment ////////////////////////////////////////////////////
Definition: opennurbs_array_defs.h:796
bool Sort(ON::sort_algorithm sort_algorithm, int *, int(*)(const T *, const T *)) const
Sort() fills in the index[] array so that array[index[i]] <= array[index[i+1]]. The array is not modi...
Definition: opennurbs_array_defs.h:734
int m_count
Definition: opennurbs_array.h:707
void Swap(int, int)
Definition: opennurbs_array_defs.h:1606
ON__UINT32 DataCRC(ON__UINT32 current_remainder) const
Definition: opennurbs_array_defs.h:192
virtual T * Realloc(T *, int)
low level memory managment ///////////////////////////////////////
Definition: opennurbs_array_defs.h:1019
T * m_a
Definition: opennurbs_array.h:706
void Zero()
Definition: opennurbs_array_defs.h:1772
unsigned int SizeOfElement() const
Definition: opennurbs_array_defs.h:185
T & operator[](int)
Definition: opennurbs_array_defs.h:198
T & AppendNew()
array operations ////////////////////////////////////////////////////
Definition: opennurbs_array_defs.h:1460
void Destroy()
Definition: opennurbs_array_defs.h:1803
void SetArray(T *)
Do not use this version of SetArray(). Use the one that takes a pointer, count and capacity: SetArray...
Definition: opennurbs_array_defs.h:1328
~ON_ObjectArray()
Definition: opennurbs_array_defs.h:942
void Reverse()
Definition: opennurbs_array_defs.h:566
unsigned int SizeOfArray() const
Definition: opennurbs_array_defs.h:179
unsigned int SizeOfElement() const
Definition: opennurbs_array_defs.h:1163
ON_ObjectArray< T > & operator=(const ON_ObjectArray< T > &)
Definition: opennurbs_array_defs.h:952
Definition: opennurbs_array.h:409
void SetCount(int)
low level memory managment //////////////////////////////////////////
Definition: opennurbs_array_defs.h:818
void Reverse()
Definition: opennurbs_array_defs.h:1589
ON_ClassArray() ON_NOEXCEPT
construction ////////////////////////////////////////////////////////
Definition: opennurbs_array_defs.h:1038
T * SetCapacity(size_t)
Definition: opennurbs_array_defs.h:1818
T * First()
Definition: opennurbs_array_defs.h:377
void EmergencyDestroy(void)
emergency bailout ///////////////////////////////////////////////////
Definition: opennurbs_array_defs.h:151
T * At(int)
At(index) returns nullptr if index < 0 or index >= count.
Definition: opennurbs_array_defs.h:1358
T * Array()
Definition: opennurbs_array_defs.h:1306
int NewCapacity() const
Definition: opennurbs_array_defs.h:867
bool HeapSort(int(*)(const T *, const T *))
Definition: opennurbs_array_defs.h:710
void DestroyElement(T &)
Definition: opennurbs_array_defs.h:1454
int Count() const
query ///////////////////////////////////////////////////////////////
Definition: opennurbs_array_defs.h:161
T * Array()
Definition: opennurbs_array_defs.h:337
int Search(const T *, int(*)(const T *, const T *)) const
Definition: opennurbs_array_defs.h:1617
void Remove()
Definition: opennurbs_array_defs.h:542
void Destroy()
Definition: opennurbs_array_defs.h:810
T & AppendNew()
array operations ////////////////////////////////////////////////////
Definition: opennurbs_array_defs.h:470
unsigned int UnsignedCount() const
Definition: opennurbs_array_defs.h:1145