20 #ifndef DYNALISTIMPL_H 21 #define DYNALISTIMPL_H 24 #include <type_traits> 32 #define MAKE_LISTTYPE_INSTANCE(C, T) \ 33 template class DynaAllocVect<C>; \ 34 template class DynaList<C>; \ 35 typedef DynaAllocVect<C> T##AllocVect; \ 36 typedef DynaList<C> T##List 50 adjustSize(initCapacity);
54 _insertArray(&array, 0, 0, count);
64 _count = other._count;
65 _capacity = other._capacity;
66 _flags = other._flags;
67 _members =
new T*[other._capacity];
68 for (
int i = 0, len = other._capacity; i < len; ++i) {
69 item = other._members[i];
70 if (item !=
nullptr) {
72 T* newItem = item->copy();
73 _members[i] = newItem;
89 if ((_count + count) >= _capacity)
92 memmove(_members + toIndex + count, _members + toIndex, (_count - toIndex) *
sizeof(T*));
94 memmove(_members + toIndex, array + arrayOffset, count *
sizeof(T*));
98 T* tmp = _members[ index1 ];
99 _members[ index1 ] = _members[ index2 ];
100 _members[ index2 ] = tmp;
104 int idx = _count - 1;
105 for (; idx >= 0; --idx) {
106 if (_members[idx] !=
nullptr)
113 int range = toIndex - frIndex + 1;
116 newList->_insertArray(getInternalTypedArray(), frIndex, 0, range);
132 for (
int idx = frIndex; idx < toIndex; ++idx) {
133 delete _members[idx];
137 if (_count > toIndex) {
138 memmove(_members + frIndex, _members + toIndex, (_count - toIndex) *
sizeof(T*));
140 _count -= (toIndex - frIndex);
142 for (
int idx = _count; idx < _capacity; ++idx) {
143 _members[idx] =
nullptr;
146 _deleteExcessCapacity();
151 toIndex = _count - 1;
153 for (
int idx = frIndex; idx <= toIndex; ++idx) {
154 delete _members[idx];
155 _members[idx] =
nullptr;
159 for (
int idx = frIndex; idx <= toIndex; ++idx) {
160 _members[idx] =
nullptr;
165 _deleteExcessCapacity();
170 toIndex = _count - 1;
171 for (
int idx = frIndex; idx <= toIndex; ++idx) {
172 _members[idx] =
nullptr;
175 _deleteExcessCapacity();
180 _deleteRange(frIndex, toIndex);
182 _clearRange(frIndex, toIndex);
206 if (!_setAutoPack(pack))
221 for (; idx < _count; ++idx) {
222 if (_members[idx] ==
nullptr)
225 if ((idx == _count) && (_count >= _capacity))
239 auto v =
new T(
value);
255 auto v =
new T(
value);
261 for (
int idx = 0; idx < _count; ++idx) {
262 if (_members[idx] ==
nullptr)
269 if (newCapacity != _capacity) {
271 _capacity = newCapacity;
272 if (_count > _capacity)
279 setCapacity(_count + delta);
283 setCapacity(((_count + delta) * 3 / 2) + 1);
293 for (
int idx = _count - 1; idx >= 0; --idx) {
294 if (_members[idx] ==
nullptr)
301 deleteItems(0, _count - 1);
305 uint cnt = getCount();
306 for (uint i = start; i < cnt; i += step) {
307 if (_members[i] == value)
314 uint cnt = getCount();
315 for (uint i = start; i < cnt; i += step) {
316 for (uint j = 0; j < arraySize; ++j) {
317 if (_members[i] == value[j])
327 index = _nextFreeSlot();
331 if (index >= _capacity)
332 adjustSizeLog(index - _capacity + 1);
344 if (_count >= _capacity)
347 memmove(_members + index + 1, _members + index, (_count - index) *
sizeof(T*));
350 _members[index] =
value;
355 return insert(index, &
value);
365 _insertArray(array, 0, index, length);
367 return index + length - 1;
371 int length = list !=
nullptr ? list->
getCount() : 0;
380 return append(&
value);
393 T* oldItem = _members[index];
394 _members[index] =
value;
401 if (index != destIndex) {
402 T* item = _members[index];
403 if (destIndex < index) {
404 int moveCount = index - destIndex;
406 _swap(index, destIndex);
408 memmove(_members + destIndex + 1, _members + destIndex, (index - destIndex) *
sizeof(T*));
409 _members[destIndex] = item;
412 else if (index < --destIndex){
413 int moveCount = destIndex - index;
415 _swap(index, destIndex);
417 memmove(_members + index, _members + index + 1, (destIndex - index) *
sizeof(T*));
418 _members[destIndex] = item;
427 if ( frIndex != toIndex ) {
428 T* item = _members[ frIndex ];
429 if ( frIndex < toIndex ) {
430 memmove(_members + frIndex, _members + frIndex + 1, (toIndex - frIndex) *
sizeof(T*));
431 _members[ toIndex ] = item;
434 memmove( _members + toIndex + 1, _members + toIndex, (frIndex - toIndex) *
sizeof(T*));
435 _members[ toIndex ] = item;
442 T* item = _members[index];
443 _nullRange(index, index);
444 _deleteOrClear(index, index);
451 DynaList<T>* newArray = _copyRange(frIndex, toIndex);
452 _nullRange(frIndex, toIndex);
453 _deleteOrClear(frIndex, toIndex);
459 _deleteOrClear(index, index);
465 _deleteOrClear(frIndex, toIndex);
486 return remove(_count - 1);
499 #endif //DYNALISTIMPL_H #define END_OF_LIST
Definition: DynaArray.h:19
#define OWNS_MEMBERS
Definition: DynaList.h:26
T * remove(int index)
Definition: DynaListImpl.h:440
static bool assertInBounds(int index, int maxIndex, const std::string &msg="???")
Definition: CheckForError.cpp:42
int insert(int index, T *value)
Definition: DynaListImpl.h:324
void _trimTheCount()
Definition: DynaListImpl.h:103
void push(T *value)
Definition: DynaListImpl.h:469
#define INVALID_INDEX
Definition: DynaArray.h:20
GeneratorWrapper< T > value(T &&value)
Definition: catch.hpp:4005
DynaList< T > * setCapacity(uint newCapacity)
Definition: DynaListImpl.h:268
DynaList< T > * copy() override
Definition: DynaListImpl.h:81
void setAllFlags(uint8_t flags)
Definition: DynaList.h:62
GeneratorWrapper< T > range(T const &start, T const &end, T const &step)
Definition: catch.hpp:4699
static bool assertNotNull(void *obj, const std::string &msg="???")
Definition: CheckForError.cpp:36
uint getCount()
Definition: DynaList.h:80
DynaList()
Definition: DynaListImpl.h:45
void _nullRange(int frIndex, int toIndex)
Definition: DynaListImpl.h:168
void deleteItems(int frIndex, int toIndex)
Definition: DynaListImpl.h:462
void _clearRange(int frIndex, int toIndex)
Definition: DynaListImpl.h:149
void move(int index, int destIndex)
Definition: DynaListImpl.h:398
void _insertArray(T **array, int arrayOffset, int toIndex, int count)
Definition: DynaListImpl.h:88
void deleteItem(int index)
Definition: DynaListImpl.h:457
void _deleteExcessCapacity()
Definition: DynaListImpl.h:120
#define AUTO_TRIM
Definition: DynaArray.h:18
#define AUTO_PACK
Definition: DynaArray.h:16
void _deleteOrClear(int frIndex, int toIndex)
Definition: DynaListImpl.h:178
T ** getInternalTypedArray()
Definition: DynaList.h:86
void pushLast(T *value)
Definition: DynaListImpl.h:473
static T ** deleteVect(T **array, uint arrayCount, bool isOwner)
Definition: DynaAllocImpl.h:103
void pack()
Definition: DynaListImpl.h:291
void clear()
Definition: DynaListImpl.h:299
int _nextFreeSlot()
Definition: DynaListImpl.h:219
std::string trim(std::string const &str)
Returns a new string without whitespace at the start/end.
DynaList< T > * _copyRange(int frIndex, int toIndex)
Definition: DynaListImpl.h:112
void slide(int frIndex, int toIndex)
Definition: DynaListImpl.h:424
DynaListIter< T > end() const
Definition: DynaListImpl.h:495
Definition: DynaList.h:38
bool _setAutoPack(bool isPack)
Definition: DynaListImpl.h:185
int firstNullSlot()
Definition: DynaListImpl.h:260
Definition: Exception.h:65
int indexOf(T *value, uint start, uint step)
Definition: DynaListImpl.h:304
DynaList< T > * setOwnsMembers(bool ownsMembers)
Definition: DynaListImpl.h:211
T * set(int index, T *value)
Definition: DynaListImpl.h:391
#define PACK_NEEDED
Definition: DynaArray.h:17
void adjustSize(int delta)
Definition: DynaListImpl.h:278
static bool assertValidArg(bool expResult, const std::string &msg="???")
Definition: CheckForError.cpp:30
std::string to_string(std::uint64_t x)
Definition: date.h:7722
DynaList< T > & operator-=(int index)
Definition: DynaListImpl.h:244
void _swap(int index1, int index2)
Definition: DynaListImpl.h:97
virtual ~DynaList()
Definition: DynaListImpl.h:57
Definition: Exception.h:13
static T ** reallocVect(T **array, uint oldCount, uint newCount, bool isOwner)
Definition: DynaAllocImpl.h:61
DynaList< T > & operator<<(T *value)
Definition: DynaListImpl.h:249
DynaList< T > & operator+=(T *value)
Definition: DynaListImpl.h:233
void trim()
Definition: DynaListImpl.h:286
DynaListIter< T > begin() const
Definition: DynaListImpl.h:491
T * pop()
Definition: DynaListImpl.h:477
void adjustSizeLog(int delta)
Definition: DynaListImpl.h:282
void _deleteRange(int frIndex, int toIndex)
Definition: DynaListImpl.h:125
bool _setAutoTrim(bool isTrim)
Definition: DynaListImpl.h:195
#define FIRST_FREE
Definition: DynaArray.h:21
int append(T *value)
Definition: DynaListImpl.h:375
Definition: DynaList.h:36
DynaList< T > * setAutoPackTrim(bool pack, bool trim)
Definition: DynaListImpl.h:205
T * popLast()
Definition: DynaListImpl.h:484
Definition: DynaAlloc.h:26