13 #ifndef DYNAARRAYIMPL_H 14 #define DYNAARRAYIMPL_H 17 #include <type_traits> 25 #define MAKE_ARRAYTYPE_INSTANCE(C, T) \ 26 template class DynaAllocArray<C>; \ 27 template class DynaArray<C>; \ 28 typedef DynaAllocArray<C> T##AllocArray; \ 29 typedef DynaArray<C> T##Array 39 adjustSize(initCapacity);
43 _insertArray(array, 0, 0, count);
52 _flags = other._flags;
53 _insertArray(other._members, 0, 0, other._count);
64 if ((_count + count) >= _capacity)
67 memmove(_members + toIndex + count, _members + toIndex, (_count - toIndex) *
sizeof(T));
69 memmove(_members + toIndex, array + arrayOffset, count *
sizeof(T));
73 T tmp = _members[ index1 ];
74 _members[ index1 ] = _members[ index2 ];
75 _members[ index2 ] = tmp;
79 int range = toIndex - frIndex + 1;
82 newArray->_insertArray(getInternalTypedArray(), frIndex, 0, range);
96 memmove(_members + frIndex, _members + toIndex, (_count - toIndex) *
sizeof(T));
97 _count -= (toIndex - frIndex);
99 for (
int idx = _count; idx < _capacity; ++idx) {
103 _deleteExcessCapacity();
108 toIndex = _count - 1;
109 for (
int idx = frIndex; idx <= toIndex; ++idx) {
114 _deleteExcessCapacity();
119 _deleteRange(frIndex, toIndex);
121 _clearRange(frIndex, toIndex);
145 if (!_setAutoPack(pack))
187 if (newCapacity != _capacity) {
189 _capacity = newCapacity;
190 if (_count > _capacity)
198 for (
int i = 0; i < _capacity; ++i) {
199 if (_members[i] == invalidValue) {
229 if (count != _count) {
230 if (count > _capacity)
237 setCapacity(_count + delta);
241 setCapacity(((_count + delta) * 3 / 2) + 1);
245 for (
int idx = _count - 1; idx >= 0; --idx) {
246 if (_members[idx] == 0)
253 deleteItems(0, _count - 1);
257 uint cnt = getCount();
258 for (uint i = start; i < cnt; i += step) {
259 if (_members[i] == value)
266 uint cnt = getCount();
267 for (uint i = start; i < cnt; i += step) {
268 for (uint j = 0; j < arraySize; ++j) {
269 if (_members[i] == value[j])
277 return indexOf(value, 0, 1);
281 return indexOf(value, arraySize, 0, 1);
285 int last = getCount() - 1;
286 for (
int i = last - start; i >= 0; i -= step) {
287 if (_members[i] == value)
294 int last = getCount() - 1;
295 for (
int i = last - start; i >= 0; i -= step) {
296 for (
int j = arraySize - 1; j >= 0; --j) {
297 if (_members[i] == value[j])
305 return revIndexOf(value, 0, 1);
309 return revIndexOf(value, arraySize, 0, 1);
317 if (_count >= _capacity)
320 memmove(_members + index + 1, _members + index, (_count - index) *
sizeof(T));
322 _members[index] =
value;
327 return insert(index, *value);
351 return insert(
END_OF_LIST, values, offset, length);
360 T oldItem = _members[index];
361 _members[index] =
value;
368 if (index != destIndex) {
369 T item = _members[index];
370 if (destIndex < index) {
371 int moveCount = index - destIndex;
373 _swap(index, destIndex);
375 memmove(_members + destIndex + 1, _members + destIndex, (index - destIndex) *
sizeof(T));
376 _members[destIndex] = item;
379 else if (index < --destIndex){
380 int moveCount = destIndex - index;
382 _swap(index, destIndex);
384 memmove(_members + index, _members + index + 1, (destIndex - index) *
sizeof(T));
385 _members[destIndex] = item;
394 if ( frIndex != toIndex ) {
395 T item = _members[ frIndex ];
396 if ( frIndex < toIndex ) {
397 memmove(_members + frIndex, _members + frIndex + 1, (toIndex - frIndex) *
sizeof(T));
398 _members[ toIndex ] = item;
401 memmove( _members + toIndex + 1, _members + toIndex, (frIndex - toIndex) *
sizeof(T));
402 _members[ toIndex ] = item;
409 T item = _members[index];
410 _deleteOrClear(index, index);
418 _deleteOrClear(frIndex, toIndex);
424 _deleteOrClear(index, index);
430 _deleteOrClear(frIndex, toIndex);
446 return remove(_count - 1);
460 #endif //DYNAARRAYIMPL_H void push(T value)
Definition: DynaArrayImpl.h:433
#define END_OF_LIST
Definition: DynaArray.h:19
GeneratorWrapper< T > values(std::initializer_list< T > values)
Definition: catch.hpp:4009
Definition: DynaAlloc.h:13
static bool assertInBounds(int index, int maxIndex, const std::string &msg="???")
Definition: CheckForError.cpp:42
void deleteItem(int index)
Definition: DynaArrayImpl.h:422
GeneratorWrapper< T > value(T &&value)
Definition: catch.hpp:4005
void deleteItems(int frIndex, int toIndex)
Definition: DynaArrayImpl.h:427
T popLast()
Definition: DynaArrayImpl.h:444
GeneratorWrapper< T > range(T const &start, T const &end, T const &step)
Definition: catch.hpp:4699
#define SET_BITS(value, bits)
Definition: BitManip.h:8
virtual ~DynaArray()
Definition: DynaArrayImpl.h:46
DynaArray< T > & operator<<(T value)
Definition: DynaArrayImpl.h:176
#define AUTO_TRIM
Definition: DynaArray.h:18
void slide(int frIndex, int toIndex)
Definition: DynaArrayImpl.h:391
#define AUTO_PACK
Definition: DynaArray.h:16
void pack()
Definition: DynaArrayImpl.h:244
DynaArrayIter< T > begin() const
Definition: DynaArrayImpl.h:451
void setAutoPackTrim(bool pack, bool trim)
Definition: DynaArrayImpl.h:144
T setValue(int index, T value)
Definition: DynaArrayImpl.h:358
std::string trim(std::string const &str)
Returns a new string without whitespace at the start/end.
Definition: DynaArray.h:28
Definition: Exception.h:65
void adjustSizeLog(int delta)
Definition: DynaArrayImpl.h:240
void adjustSize(int delta)
Definition: DynaArrayImpl.h:236
static T * reallocArray(T *array, uint oldCount, uint newCount)
Definition: DynaAllocImpl.h:19
static T * deleteArray(T *array)
Definition: DynaAllocImpl.h:46
T remove(int index)
Definition: DynaArrayImpl.h:407
int revIndexOf(T value, uint start, uint step)
Definition: DynaArrayImpl.h:284
#define PACK_NEEDED
Definition: DynaArray.h:17
CONSTDATA date::last_spec last
Definition: date.h:1834
int insert(int index, T value)
Definition: DynaArrayImpl.h:312
void move(int index, int destIndex)
Definition: DynaArrayImpl.h:365
#define IS_ALL_SET(value, bits)
Definition: BitManip.h:10
DynaArray< T > & operator-=(int index)
Definition: DynaArrayImpl.h:171
DynaArray< T > & operator=(const DynaArray< T > &array)
Definition: DynaArrayImpl.h:152
int indexOf(T value, uint start, uint step)
Definition: DynaArrayImpl.h:256
int append(T value)
Definition: DynaArrayImpl.h:342
void setCapacity(uint newCapacity)
Definition: DynaArrayImpl.h:186
DynaArray< T > & operator+=(T value)
Definition: DynaArrayImpl.h:161
DynaArrayIter< T > end() const
Definition: DynaArrayImpl.h:455
void determineTheCount(int invalidValue)
Definition: DynaArrayImpl.h:195
void setAllFlags(uint8_t flags)
Definition: DynaArray.h:49
Definition: DynaArray.h:26
void setCount(uint count)
Definition: DynaArrayImpl.h:228
DynaArray< T > * copy() override
Definition: DynaArrayImpl.h:56
void clear()
Definition: DynaArrayImpl.h:251
T pop()
Definition: DynaArrayImpl.h:437