5 #ifndef DYNALINKEDLISTIMPL_H 6 #define DYNALINKEDLISTIMPL_H 10 #define MAKE_LINKEDLISTTYPE_INSTANCE(C, T) \ 11 template class LinkedEntry<C>; \ 12 typedef LinkedEntry<C> T##LinkedEntry; \ 13 template class DynaLinkedList<C>; \ 14 typedef DynaLinkedList<C> T##LinkedList 20 _owner(nullptr), _prev(nullptr), _next(nullptr), _ownsObject(ownsObject), _object(object){}
23 if (_object !=
nullptr && _ownsObject) {
33 _object = other._object;
34 _ownsObject = other._ownsObject;
86 _first(nullptr), _last(nullptr), _ownsMembers(true), _entryCount(0){}
95 _ownsMembers(other._ownsMembers), _entryCount(other._entryCount) {
109 while (it.hasNext()) {
135 return entry !=
nullptr && entry == _first;
140 return entry !=
nullptr && entry == _last;
150 _ownsMembers = ownsMembers;
194 if (entry->getObject() == object)
227 if (entry !=
nullptr) {
230 if (destLink ==
nullptr)
232 if (_first ==
nullptr)
234 if (_last ==
nullptr || destLink == _last)
236 if (destLink !=
nullptr) {
239 if (destLink->
getNext() !=
nullptr)
240 destLink->
getNext()->setPrevious(entry);
245 if (destLink ==
nullptr)
247 if (_first ==
nullptr || destLink == _first)
249 if (_last ==
nullptr)
251 if (destLink !=
nullptr) {
270 if (
object !=
nullptr) {
299 if (entry !=
nullptr) {
303 if (entry->
getNext() !=
nullptr)
321 if (entry !=
nullptr)
323 if (entry !=
nullptr) {
342 if (entry !=
nullptr && entry != destEntry) {
345 else if (entry->
getOwner() !=
nullptr)
346 entry->
getOwner()->removeEntry(entry);
347 if (destEntry ==
nullptr || destEntry->
getOwner() ==
this) {
351 else if (destEntry->
getOwner() !=
nullptr) {
352 destEntry->
getOwner()->insertEntry(entry, destEntry, after);
361 return move(entry, _first,
false);
366 return move(entry, _last,
true);
371 if (atEntry !=
nullptr && atEntry->
getOwner() ==
this) {
373 newList->_first = atEntry;
374 newList->_last = _last;
381 _first = _last =
nullptr;
386 entry->setOwner(newList);
389 _entryCount -=
count;
390 newList->_entryCount =
count;
398 if (list !=
this && list->_first !=
nullptr) {
399 if (_last !=
nullptr) {
400 _last->setNext(list->_first);
401 if (list->_first !=
nullptr)
402 list->_first->setPrevious(_last);
406 _first = list->_first;
412 entry->setOwner(
this);
415 _entryCount +=
count;
416 list->_first = list->_last =
nullptr;
417 list->_entryCount = 0;
428 if (
object !=
nullptr) {
437 return insert(
object, _last,
true);
442 return insert(
object, _first,
false);
446 if (entry !=
nullptr)
448 if (entry !=
nullptr) {
459 return remove(_first);
464 return remove(_last);
480 : _list(list), _current(list->
getFirst()) {}
483 : _current(start), _list(list) {}
486 return _current ==
nullptr ? _list->getFirst() != nullptr : _current->getNext() !=
nullptr;
490 return _current ==
nullptr ? _list->getLast() != nullptr : _current->getPrevious() !=
nullptr;
494 _current = _current ==
nullptr ? _list->getFirst() : _current->getNext();
495 return _current !=
nullptr ? _current->getObject() :
nullptr;
499 _current = _current ==
nullptr ? _list->getLast() : _current->getPrevious();
500 return _current !=
nullptr ? _current->getObject() :
nullptr;
504 if (_current !=
nullptr) {
507 next = _current->getPrevious();
508 _list->deleteEntry(_current);
514 return _current == other._current;
518 return _current != other._current;
522 return _current->getObject();
548 : _list(list), _current(list->getFirst()) {}
551 : _current(start),_list(list) {}
554 return _current ==
nullptr ? _list->getFirst() != nullptr :
555 ( _current->getNext() !=
nullptr || _list->getLast() != nullptr );
559 return _current ==
nullptr ? _list->getLast() != nullptr :
560 ( _current->getPrevious() !=
nullptr || _list->getFirst() != nullptr );
564 _current = _current ==
nullptr ? _list->getFirst() :
565 ( _current->getNext() !=
nullptr ? _current->getNext() : _list->getLast() );
570 _current = _current ==
nullptr ? _list->getLast() :
571 ( _current->getPrevious() !=
nullptr ? _current->getPrevious() : _list->getFirst() );
576 if (_current !=
nullptr) {
579 next = _current->getPrevious();
580 _list->deleteEntry(_current);
586 return _current == other._current;
590 return _current != other._current;
615 #endif //DYNALINKEDLISTIMPL_H LinkedIter< T > end()
Definition: DynaLinkedListImpl.h:471
T * getObject() const
Definition: DynaLinkedListImpl.h:58
T * append(T *object)
Definition: DynaLinkedListImpl.h:436
DynaLinkedList< T > * copy() override
Definition: DynaLinkedListImpl.h:103
T * insert(T *object, LinkedEntry< T > *destLink, bool after)
Definition: DynaLinkedListImpl.h:427
DynaLinkedList()
Definition: DynaLinkedListImpl.h:85
void setOwnsMembers(bool ownsMembers)
Definition: DynaLinkedListImpl.h:149
LinkedEntry(T *object, bool ownsObject)
Definition: DynaLinkedListImpl.h:19
LinkedEntryIter< T > end()
Definition: DynaLinkedListImpl.h:611
LinkedEntry< T > * previous()
Definition: DynaLinkedListImpl.h:569
LinkedEntry< T > * operator*() const
Definition: DynaLinkedListImpl.h:593
LinkedEntry< T > * setOwner(DynaLinkedList< T > *owner)
Definition: DynaLinkedListImpl.h:62
bool hasNext()
Definition: DynaLinkedListImpl.h:553
bool isLast(LinkedEntry< T > *entry)
Definition: DynaLinkedListImpl.h:139
int indexOfEntry(LinkedEntry< T > *entry)
Definition: DynaLinkedListImpl.h:179
LinkedIter< T > end()
Definition: DynaLinkedListImpl.h:539
Definition: DynaLinkedList.h:29
T * find(T *object)
Definition: DynaLinkedListImpl.h:213
T * operator*() const
Definition: DynaLinkedListImpl.h:521
LinkedEntry< T > * getLast() const
Definition: DynaLinkedListImpl.h:129
Definition: DynaLinkedList.h:32
bool hasPrevious()
Definition: DynaLinkedListImpl.h:558
#define INVALID_INDEX
Definition: DynaArray.h:20
bool operator==(const LinkedEntryIter< T > &other) const
Definition: DynaLinkedListImpl.h:585
int indexOf(T *object)
Definition: DynaLinkedListImpl.h:201
virtual ~LinkedEntry()
Definition: DynaLinkedListImpl.h:22
const LinkedIter< T > & operator++()
Definition: DynaLinkedListImpl.h:525
bool isOwnsObject()
Definition: DynaLinkedListImpl.h:54
int size()
Definition: DynaLinkedListImpl.h:118
LinkedEntry< T > * next()
Definition: DynaLinkedListImpl.h:563
void remove()
Definition: DynaLinkedListImpl.h:503
LinkedEntryIter< T > begin()
Definition: DynaLinkedListImpl.h:607
LinkedEntry< T > * copy() override
Definition: DynaLinkedListImpl.h:37
bool operator!=(const LinkedEntryIter< T > &other) const
Definition: DynaLinkedListImpl.h:589
LinkedEntry< T > * appendEntry(LinkedEntry< T > *entry)
Definition: DynaLinkedListImpl.h:279
bool hasNext()
Definition: DynaLinkedListImpl.h:485
LinkedEntry< T > * setObject(T *object)
Definition: DynaLinkedListImpl.h:77
LinkedEntry< T > * get(int index)
Definition: DynaLinkedListImpl.h:154
LinkedEntry< T > * insertEntry(LinkedEntry< T > *entry, LinkedEntry< T > *destLink, bool after)
Definition: DynaLinkedListImpl.h:226
bool isFirst(LinkedEntry< T > *entry)
Definition: DynaLinkedListImpl.h:134
bool operator==(const LinkedIter< T > &other) const
Definition: DynaLinkedListImpl.h:513
bool move(LinkedEntry< T > *entry, LinkedEntry< T > *destEntry, bool after)
Definition: DynaLinkedListImpl.h:341
LinkedEntry< T > * setPrevious(LinkedEntry< T > *previous)
Definition: DynaLinkedListImpl.h:72
LinkedEntry< T > * pushEntry(LinkedEntry< T > *entry)
Definition: DynaLinkedListImpl.h:289
T * push(T *object)
Definition: DynaLinkedListImpl.h:441
T * popLast()
Definition: DynaLinkedListImpl.h:463
uint count()
Definition: DynaLinkedListImpl.h:171
uint getCount()
Definition: DynaLinkedListImpl.h:166
Definition: DynaLinkedList.h:28
bool isOwnsMembers()
Definition: DynaLinkedListImpl.h:144
Definition: DynaLinkedList.h:30
LinkedEntryIter(DynaLinkedList< T > *list)
Definition: DynaLinkedListImpl.h:547
LinkedEntry< T > * getNext()
Definition: DynaLinkedListImpl.h:50
LinkedEntry< T > * popEntry()
Definition: DynaLinkedListImpl.h:331
T * remove(LinkedEntry< T > *entry)
Definition: DynaLinkedListImpl.h:445
T * previous()
Definition: DynaLinkedListImpl.h:498
bool deleteEntry(LinkedEntry< T > *entry)
Definition: DynaLinkedListImpl.h:320
const LinkedIter< T > & operator--()
Definition: DynaLinkedListImpl.h:530
LinkedIter< T > begin()
Definition: DynaLinkedListImpl.h:535
bool moveToLast(LinkedEntry< T > *entry)
Definition: DynaLinkedListImpl.h:365
LinkedIter< T > begin()
Definition: DynaLinkedListImpl.h:467
const LinkedEntryIter< T > & operator--()
Definition: DynaLinkedListImpl.h:602
LinkedEntry< T > * getPrevious()
Definition: DynaLinkedListImpl.h:46
bool hasPrevious()
Definition: DynaLinkedListImpl.h:489
LinkedEntry< T > * popLastEntry()
Definition: DynaLinkedListImpl.h:336
DynaLinkedList< T > * splitList(LinkedEntry< T > *atEntry)
Definition: DynaLinkedListImpl.h:370
LinkedIter(DynaLinkedList< T > *list)
Definition: DynaLinkedListImpl.h:479
T * next()
Definition: DynaLinkedListImpl.h:493
LinkedEntry< T > * removeEntry(LinkedEntry< T > *entry)
Definition: DynaLinkedListImpl.h:298
LinkedEntry< T > * findEntry(T *object)
Definition: DynaLinkedListImpl.h:191
bool operator!=(const LinkedIter< T > &other) const
Definition: DynaLinkedListImpl.h:517
virtual ~DynaLinkedList()
Definition: DynaLinkedListImpl.h:89
bool moveToFirst(LinkedEntry< T > *entry)
Definition: DynaLinkedListImpl.h:360
DynaLinkedList< T > * getOwner()
Definition: DynaLinkedListImpl.h:42
void remove()
Definition: DynaLinkedListImpl.h:575
T * pop()
Definition: DynaLinkedListImpl.h:458
DynaLinkedList< T > * appendList(DynaLinkedList< T > *list)
Definition: DynaLinkedListImpl.h:397
void clear()
Definition: DynaLinkedListImpl.h:107
LinkedEntry< T > * getFirst() const
Definition: DynaLinkedListImpl.h:124
LinkedEntry< T > * setNext(LinkedEntry< T > *next)
Definition: DynaLinkedListImpl.h:67
const LinkedEntryIter< T > & operator++()
Definition: DynaLinkedListImpl.h:597