4template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
5base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >::base_array()
18template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
19base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >::~base_array ()
22 if (m_pData !=
nullptr)
32template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
33::collection::count base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >::resize(::collection::count nNewSize, ARG_TYPE t, ::collection::count nGrowBy)
36 return allocate(nNewSize, nGrowBy, &t);
41template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
42::collection::count base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >::allocate_in_bytes(::collection::count nNewSize,::collection::count nGrowBy)
48 return allocate(nNewSize /
sizeof(TYPE),-1);
54 return allocate(nNewSize /
sizeof(TYPE),nGrowBy /
sizeof(TYPE));
61template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
67 ::collection::index nUpperBound = nIndex + nCount;
69 if (nIndex < 0 || nCount < 0 || (nUpperBound > m_nSize) || (nUpperBound < nIndex) || (nUpperBound < nCount))
72 throw ::exception(error_bad_argument);
76 ::collection::count nMoveCount = m_nSize - (nUpperBound);
78 ALLOCATOR::destruct_count(m_pData + nIndex, nCount REFERENCING_DEBUGGING_COMMA_THIS);
82 ::safe_memory_transfer(m_pData + nIndex,(
size_t)nMoveCount *
sizeof(TYPE),m_pData + nUpperBound,(
size_t)nMoveCount *
sizeof(TYPE));
92template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
93::collection::index base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >::erase_item(TYPE * p)
96 return erase_at(p - m_pData);
102template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
103void base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >::free_extra()
106 if(m_nSize != m_nMaxSize)
110 ASSERT(m_nSize <= SIZE_T_MAX /
sizeof(TYPE));
112 TYPE* pNewData =
nullptr;
116#if defined(__MCRTDBG) || MEMDLEAK
118 if (::get_task() !=
nullptr)
120 if (::get_task()->m_strFile.has_character())
122 pNewData = ALLOCATOR::alloc(m_nSize, ::get_task()->m_strFile, ::get_task()->m_iLine);
126 pNewData = ALLOCATOR::alloc(m_nSize, __FILE__, __LINE__);
131 pNewData = ALLOCATOR::alloc(m_nSize, __FILE__, __LINE__);
135 if (::get_task_object_debug().has_character())
138 pNewData = ALLOCATOR::alloc(m_nSize, ::get_task_object_debug(), 0);
144 pNewData = ALLOCATOR::alloc(m_nSize, __FILE__, __LINE__);
152 pNewData = ALLOCATOR::alloc(m_nSize);
157 ::safe_memory_copy(pNewData, (
size_t)m_nSize *
sizeof(TYPE),m_pData, (
size_t)m_nSize *
sizeof(TYPE));
162 ALLOCATOR::_free(m_pData);
166 m_nMaxSize = m_nSize;
174template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
175void base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >::destroy()
178 if(m_pData !=
nullptr)
181 ALLOCATOR::destruct_count(m_pData, m_nSize REFERENCING_DEBUGGING_COMMA_THIS);
183 ALLOCATOR::_free(m_pData);
194template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
195::collection::index base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >::insert_at(::collection::index nIndex,
const TYPE & newElement,::collection::count nCount )
198 ::collection::index nIndexParam = make_room_at(nIndex, nCount);
203 ALLOCATOR::copy(m_pData + nIndex, &newElement);
213template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
214::collection::index base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >::make_room_at(::collection::index nIndex, ::collection::count nCount )
223 throw ::exception(error_bad_argument);
225 if(nIndex >= m_nSize)
229 set_size(nIndex + nCount,-1);
236 ::collection::count nOldSize = (::collection::count) m_nSize;
238 set_size((::collection::count) m_nSize + nCount,-1);
241 ::safe_memory_transfer(m_pData + nIndex + nCount,(
size_t) ((nOldSize - nIndex) *
sizeof(TYPE)),m_pData + nIndex,(
size_t)((nOldSize - nIndex) *
sizeof(TYPE)));
243 ::zero(m_pData + nIndex, nCount*
sizeof(TYPE));
245 ALLOCATOR::construct_count(m_pData + nIndex,nCount);
250 ASSERT(nIndex + nCount <= m_nSize);
258template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
259::collection::count base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >::append(
const base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer > & src)
262 ::collection::count nOldSize = m_nSize;
264 ::collection::count nSrcSize = src.m_nSize;
266 allocate(nOldSize + nSrcSize);
268 ALLOCATOR::copy_count(m_pData + nOldSize, src.m_pData, nSrcSize);
275template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
276void base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >::copy(
const base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer > & src)
286 ::collection::count nSrcSize = src.m_nSize;
290 ALLOCATOR::copy_count(m_pData,src.m_pData, nSrcSize);
300template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
301void base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >::_001RemoveIndexes(index_array & ia)
305 ::sort::quick_sort(ia,
true);
307 ::collection::index i = ia.get_upper_bound();
310 while(i >= 0 && ia[i] >= get_size())
320 while(ia.get_size() > 0 && ia[0] < 0)
327 i = ia.get_upper_bound();
330 while(i > 0 && ia[i] >= get_size())
333 if(ia[i] == ia[i - 1])
345template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
346void base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >::erase_indexes(
const index_array & ia)
351 for(::collection::index i = ia.get_upper_bound(); i >= 0; i--)
361template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
362void base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >::erase_descending_indexes(
const index_array & ia)
365 for(::collection::index i = 0; i < ia.get_count(); i++)
376template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
377::collection::index base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >::insert_at(::collection::index nIndex,base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer > * pNewArray)
380 ASSERT(pNewArray !=
nullptr);
383 ::collection::count nCount = pNewArray->get_size();
389 throw ::exception(error_bad_argument);
391 if (nIndex >= m_nSize)
395 set_size(nIndex + nCount, -1);
402 ::collection::count nOldSize = (::collection::count) m_nSize;
404 set_size((::collection::count) (m_nSize + nCount), -1);
407 ::safe_memory_transfer(m_pData + nIndex + nCount, (
size_t) ((nOldSize - nIndex) *
sizeof(TYPE)), m_pData + nIndex, (
size_t) ((nOldSize - nIndex) *
sizeof(TYPE)));
409 ::zero(m_pData + nIndex, nCount*
sizeof(TYPE));
411 ALLOCATOR::construct_count(m_pData + nIndex, nCount);
416 ASSERT(nIndex + nCount <= m_nSize);
418 ::collection::index nIndexParam = nIndex;
420 ::collection::index i = 0;
425 ALLOCATOR::copy(m_pData + nIndex, pNewArray->m_pData + i);
437template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
438TYPE base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >::pick_at(::collection::index nIndex)
441 ::collection::count nCount = 1;
443 ::collection::index nUpperBound = nIndex + nCount;
445 if (nIndex < 0 || nCount < 0 || (nUpperBound > m_nSize) || (nUpperBound < nIndex) || (nUpperBound < nCount))
448 throw ::exception(error_bad_argument);
452 ::collection::count nMoveCount = m_nSize - (nUpperBound);
454 auto t = m_pData[nIndex];
456 ALLOCATOR::destruct_count(m_pData + nIndex, nCount REFERENCING_DEBUGGING_COMMA_THIS);
461 ::safe_memory_transfer(m_pData + nIndex, (
size_t)nMoveCount *
sizeof(TYPE), m_pData + nUpperBound, (
size_t)nMoveCount *
sizeof(TYPE));
467 return ::transfer(t);
472template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
473base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer > base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >::pick_at(::collection::index nIndex, ::collection::count nCount)
478 ::collection::index nUpperBound = nIndex + nCount;
480 if (nIndex < 0 || nCount < 0 || (nUpperBound > m_nSize) || (nUpperBound < nIndex) || (nUpperBound < nCount))
483 throw ::exception(error_bad_argument);
487 ::collection::count nMoveCount = m_nSize - (nUpperBound);
489 base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer > a(m_pData + nIndex, (
size_t)nMoveCount);
491 ALLOCATOR::destruct_count(m_pData + nIndex, nCount REFERENCING_DEBUGGING_COMMA_THIS);
496 ::safe_memory_transfer(m_pData + nIndex, (
size_t)nMoveCount *
sizeof(TYPE), m_pData + nUpperBound, (
size_t)nMoveCount *
sizeof(TYPE));
507template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
508::collection::count base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >::set_raw_size(::collection::count nNewSize,::collection::count nGrowBy)
511 ::collection::count countOld = get_count();
513 ASSERT(nNewSize >= 0);
516 throw ::exception(error_bad_argument);
525 if(m_pData !=
nullptr)
528 ALLOCATOR::_free(m_pData);
534 m_nSize = m_nMaxSize = 0;
536 else if (m_pData ==
nullptr)
541 if (nNewSize > SIZE_T_MAX /
sizeof(TYPE))
542 throw ::exception(error_no_memory);
543 ASSERT(nNewSize <= SIZE_T_MAX /
sizeof(TYPE));
545 ::collection::count nAllocSize = (::collection::count) maximum(nNewSize, m_nGrowBy);
546#if defined(__MCRTDBG) || MEMDLEAK
547 if (::get_task() !=
nullptr)
551 if (::get_task()->m_strFile.has_character())
554 m_pData = ALLOCATOR::alloc(nAllocSize, ::get_task()->m_strFile, 0);
560 m_pData = ALLOCATOR::alloc(nAllocSize, __FILE__, __LINE__);
566 if (::get_task_object_debug().has_character())
569 m_pData = ALLOCATOR::alloc(nAllocSize, ::get_task_object_debug(), ::get_task()->m_iLine);
575 m_pData = ALLOCATOR::alloc(nAllocSize, __FILE__, __LINE__);
585 m_pData = ALLOCATOR::alloc(nAllocSize, __FILE__, __LINE__);
591 m_pData = ALLOCATOR::alloc(nAllocSize);
596 m_nMaxSize = nAllocSize;
598 else if(nNewSize <= m_nMaxSize)
605 nGrowBy = (::collection::count) m_nGrowBy;
610 nGrowBy = (::collection::count) m_nSize;
611 nGrowBy = (nGrowBy < 4) ? 4 : ((nGrowBy > 1024) ? 1024 : nGrowBy);
613 ::collection::count nNewMax;
614 if(nNewSize < m_nMaxSize + nGrowBy)
615 nNewMax = (::collection::count) (m_nMaxSize + nGrowBy);
619 ASSERT(nNewMax >= m_nMaxSize);
621 if(nNewMax < m_nMaxSize)
622 throw ::exception(error_bad_argument);
625 ASSERT(nNewMax <= SIZE_T_MAX /
sizeof(TYPE));
628#if defined(__MCRTDBG) || MEMDLEAK
631 if (::get_task() !=
nullptr)
634 if (::get_task()->m_strFile.has_character())
637 pNewData = ALLOCATOR::alloc(nNewMax, ::get_task()->m_strFile, ::get_task()->m_iLine);
643 pNewData = ALLOCATOR::alloc(nNewMax, __FILE__, __LINE__);
651 pNewData = ALLOCATOR::alloc(nNewMax, __FILE__, __LINE__);
657 if (::get_task_object_debug().has_character())
660 pNewData = ALLOCATOR::alloc(nNewMax, ::get_task_object_debug(), ::get_task()->m_iLine);
666 pNewData = ALLOCATOR::alloc(nNewMax, __FILE__, __LINE__);
674 pNewData = ALLOCATOR::alloc(nNewMax);
678 ::safe_memory_copy(pNewData,(
size_t)nNewMax *
sizeof(TYPE),m_pData,(
size_t)m_nSize *
sizeof(TYPE));
682 ALLOCATOR::_free(m_pData);
688 m_nMaxSize = nNewMax;
697template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
701 ::collection::count countOld = get_count();
703 ASSERT(nNewSize >= 0);
708 throw ::exception(error_bad_argument);
720 if(nNewSize == m_nSize)
731 if(m_pData !=
nullptr)
734 ALLOCATOR::destruct_count(m_pData, m_nSize REFERENCING_DEBUGGING_COMMA_THIS);
736 ALLOCATOR::_free(m_pData);
742 m_nSize = m_nMaxSize = 0;
745 else if(m_pData ==
nullptr)
751 if(::comparison::gt(nNewSize, SIZE_T_MAX /
sizeof(TYPE)))
752 throw ::exception(error_no_memory);
753 ASSERT(::comparison::lt(nNewSize, SIZE_T_MAX /
sizeof(TYPE)));
756 auto nAllocSize = maximum(nNewSize, m_nGrowBy);
758#if MEMDLEAK || defined(__MCRTDBG)
760 if(::get_task() !=
nullptr)
763#if defined(__MCRTDBG)
765 if(::get_task()->m_strFile.has_character())
768 m_pData = ALLOCATOR::alloc(nAllocSize, ::get_task()->m_strFile, ::get_task()->m_iLine);
774 m_pData = ALLOCATOR::alloc(nAllocSize, __FILE__, __LINE__);
780 if (::get_task_object_debug().has_character())
783 m_pData = ALLOCATOR::alloc(nAllocSize,
"thread://" + ::get_task_object_name() +
", " + ::get_task_object_debug() +
", " +
string(__FILE__), __LINE__;
789 m_pData = ALLOCATOR::alloc(nAllocSize,
"thread://" + ::get_task_object_name() +
", " +
string(__FILE__), __LINE__;
799 m_pData = ALLOCATOR::alloc(nAllocSize, __FILE__, __LINE__);
805 m_pData = ALLOCATOR::alloc(nAllocSize);
809 if (::is_null(ptype))
812 ALLOCATOR::construct_count(m_pData, nNewSize);
818 ALLOCATOR::copy_construct_count(m_pData, nNewSize, *ptype);
824 m_nMaxSize = nAllocSize;
827 else if(nNewSize <= m_nMaxSize)
830 if(nNewSize > m_nSize)
833 if (::is_null(ptype))
836 ALLOCATOR::construct_count(m_pData + m_nSize, nNewSize - m_nSize);
842 ALLOCATOR::copy_construct_count(m_pData + m_nSize, nNewSize - m_nSize, *ptype);
847 else if(m_nSize > nNewSize)
850 ALLOCATOR::destruct_count(m_pData + nNewSize,m_nSize - nNewSize REFERENCING_DEBUGGING_COMMA_THIS);
869 nGrowBy = (nGrowBy < 4) ? 4 : ((nGrowBy > 1024) ? 1024 : nGrowBy);
873 ::collection::count nNewMax;
875 if(nNewSize < m_nMaxSize+ nGrowBy)
878 nNewMax = m_nMaxSize+ nGrowBy;
888 ASSERT(nNewMax >= m_nMaxSize);
890 if(nNewMax < m_nMaxSize)
893 throw ::exception(error_bad_argument);
899 ASSERT(::comparison::lt(nNewMax, SIZE_T_MAX /
sizeof(TYPE)));
903#if MEMDLEAK || defined(__MCRTDBG)
905 TYPE* pNewData =
nullptr;
907 if(::get_task() !=
nullptr)
910#if defined(__MCRTDBG)
912 if(::get_task()->m_strFile.has_character())
915 pNewData = ALLOCATOR::alloc(nNewMax, ::get_task()->m_strFile,::get_task()->m_iLine);
921 pNewData = ALLOCATOR::alloc(nNewMax, __FILE__, __LINE__);
927 if (::get_task_object_debug().has_character())
930 pNewData = ALLOCATOR::alloc(nNewMax,
"thread://" + ::get_task_object_name() +
", " + ::get_task_object_debug() +
", " +
string(__FILE__), __LINE__;
936 pNewData = ALLOCATOR::alloc(nNewMax,
"thread://" + ::get_task_object_name() +
", " +
string(__FILE__), __LINE__;
946 pNewData = ALLOCATOR::alloc(nNewMax, __FILE__, __LINE__);
953 TYPE* pNewData = ALLOCATOR::alloc(nNewMax);
958 ::safe_memory_copy(pNewData,(
size_t)nNewMax *
sizeof(TYPE),m_pData,(
size_t)m_nSize *
sizeof(TYPE));
961 ASSERT(nNewSize > m_nSize);
963 if (nNewSize > m_nSize)
966 if (::is_null(ptype))
969 ALLOCATOR::construct_count(pNewData + m_nSize, nNewSize - m_nSize);
975 ALLOCATOR::copy_construct_count(pNewData + m_nSize, nNewSize - m_nSize, *ptype);
982 ALLOCATOR::_free(m_pData);
988 m_nMaxSize = nNewMax;
998template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
999void base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >::on_after_read()
1009template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
1010inline void base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer > ::set_at_grow(::collection::index nIndex, ARG_TYPE newElement, ::collection::count nGrowBy)
1013 ASSERT(nIndex >= 0);
1015 if (nIndex >= this->m_nSize)
1018 this->set_size(nIndex + 1, nGrowBy);
1022 m_pData[nIndex] = newElement;
1027template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
1028inline TYPE & base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer > ::element_at_grow(::collection::index nIndex, ::collection::count nGrowBy)
1031 ASSERT(nIndex >= 0);
1033 if (nIndex >= this->m_nSize)
1036 this->set_size(nIndex + 1, nGrowBy);
1040 return m_pData[nIndex];
1045template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
1046inline void base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer > ::set_each(ARG_TYPE element, ::collection::index first, ::collection::count in_count_out_last)
1049 prepare_first_in_count_last_out(first, in_count_out_last);
1051 for(::collection::index i = first; i <= in_count_out_last; i++)
1054 m_pData[i] = element;
1060template <
typename TYPE,
typename ARG_TYPE,
typename ALLOCATOR, ::enum_type t_etypeContainer >
1061 template <
typename ITERATOR >
1062 inline void base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer > ::erase(
const ITERATOR & begin,
const ITERATOR & last) { ::erase(*
this, begin, last); }
::collection::count allocate(::collection::count nNewSize, bool bShrink, bool bRaw, P &p)
if bRaw is true does not call default constructors on ___new elements
Definition base_array.h:972
::collection::index erase_at(::collection::index nIndex, ::collection::count nCount=1)
Definition aaa__array_base_impl.h:62