59 template <
class ObjectType>
91 jassert (
this != &other);
100 inline operator ObjectType*()
const noexcept
106 inline ObjectType*
get()
const noexcept
122 while (l->item !=
nullptr)
123 l = &(l->item->nextListItem);
136 for (
auto* i = item; i !=
nullptr; i = i->nextListItem)
150 while (--index >= 0 && l->item !=
nullptr)
151 l = &(l->item->nextListItem);
164 while (--index >= 0 && l->item !=
nullptr)
165 l = &(l->item->nextListItem);
171 bool contains (
const ObjectType*
const itemToLookFor)
const noexcept
173 for (
auto* i = item; i !=
nullptr; i = i->nextListItem)
174 if (itemToLookFor == i)
186 jassert (newItem !=
nullptr);
187 jassert (newItem->nextListItem ==
nullptr);
188 newItem->nextListItem = item;
198 jassert (newItem !=
nullptr);
201 while (index != 0 && l->item !=
nullptr)
203 l = &(l->item->nextListItem);
207 l->insertNext (newItem);
215 jassert (newItem !=
nullptr);
216 jassert (newItem->nextListItem ==
nullptr);
220 item->nextListItem = oldItem->nextListItem.item;
221 oldItem->nextListItem.item =
nullptr;
242 auto* insertPoint =
this;
244 for (
auto* i = other.item; i !=
nullptr; i = i->nextListItem)
246 insertPoint->insertNext (
new ObjectType (*i));
247 insertPoint = &(insertPoint->item->nextListItem);
259 if (oldItem !=
nullptr)
261 item = oldItem->nextListItem;
262 oldItem->nextListItem.item =
nullptr;
271 void remove (ObjectType*
const itemToRemove)
282 while (item !=
nullptr)
285 item = oldItem->nextListItem;
298 while (l->item !=
nullptr)
300 if (l->item == itemToLookFor)
303 l = &(l->item->nextListItem);
315 jassert (destArray !=
nullptr);
317 for (
auto* i = item; i !=
nullptr; i = i->nextListItem)
324 std::swap (item, other.item);
341 : endOfList (&endOfListPointer)
344 jassert (endOfListPointer.item ==
nullptr);
348 void append (ObjectType*
const newItem) noexcept
350 *endOfList = newItem;
351 endOfList = &(newItem->nextListItem);
357 JUCE_DECLARE_NON_COPYABLE (
Appender)
void insertNext(ObjectType *const newItem)
Inserts an item into the list, placing it before the item that this pointer currently points to...
LinkedListPointer & operator[](int index) noexcept
Returns the item at a given index in the list.
void deleteAll()
Iterates the list, calling the delete operator on all of its elements and leaving this pointer empty...
void copyToArray(ObjectType **destArray) const noexcept
Copies the items in the list to an array.
LinkedListPointer & operator=(ObjectType *const newItem) noexcept
Sets this pointer to point to a new list.
void append(ObjectType *const newItem) noexcept
Appends an item to the list.
LinkedListPointer() noexcept
Creates a null pointer to an empty list.
ObjectType * removeNext() noexcept
Removes the head item from the list.
Appender(LinkedListPointer &endOfListPointer) noexcept
Creates an appender which will add items to the given list.
int size() const noexcept
Returns the number of items in the list.
void swapWith(LinkedListPointer &other) noexcept
Swaps this pointer with another one.
void addCopyOfList(const LinkedListPointer &other)
Creates copies of all the items in another list and adds them to this one.
void append(ObjectType *const newItem)
Adds an item to the end of the list.
LinkedListPointer & getLast() noexcept
Returns the last item in the list which this pointer points to.
ObjectType * replaceNext(ObjectType *const newItem) noexcept
Replaces the object that this pointer points to, appending the rest of the list to the new object...
Allows efficient repeated insertions into a list.
void insertAtIndex(int index, ObjectType *newItem)
Inserts an item at a numeric index in the list.
LinkedListPointer * findPointerTo(ObjectType *const itemToLookFor) noexcept
Finds a pointer to a given item.
bool contains(const ObjectType *const itemToLookFor) const noexcept
Returns true if the list contains the given item.
LinkedListPointer(ObjectType *const headItem) noexcept
Creates a pointer to a list whose head is the item provided.
Helps to manipulate singly-linked lists of objects.