59template <
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)
Allows efficient repeated insertions into a list.
Appender(LinkedListPointer &endOfListPointer) noexcept
Creates an appender which will add items to the given list.
void append(ObjectType *const newItem) noexcept
Appends an item to the list.
Helps to manipulate singly-linked lists of objects.
LinkedListPointer & getLast() noexcept
Returns the last item in the list which this pointer points to.
LinkedListPointer * findPointerTo(ObjectType *const itemToLookFor) noexcept
Finds a pointer to a given item.
LinkedListPointer & operator[](int index) noexcept
Returns the item at a given index in the list.
ObjectType * replaceNext(ObjectType *const newItem) noexcept
Replaces the object that this pointer points to, appending the rest of the list to the new object,...
void append(ObjectType *const newItem)
Adds an item to the end of the list.
void deleteAll()
Iterates the list, calling the delete operator on all of its elements and leaving this pointer empty.
LinkedListPointer & operator=(ObjectType *const newItem) noexcept
Sets this pointer to point to a new list.
bool contains(const ObjectType *const itemToLookFor) const noexcept
Returns true if the list contains the given item.
ObjectType * removeNext() noexcept
Removes the head item from the list.
LinkedListPointer(ObjectType *const headItem) noexcept
Creates a pointer to a list whose head is the item provided.
void insertNext(ObjectType *const newItem)
Inserts an item into the list, placing it before the item that this pointer currently points to.
ObjectType * get() const noexcept
Returns the item which this pointer points to.
void addCopyOfList(const LinkedListPointer &other)
Creates copies of all the items in another list and adds them to this one.
int size() const noexcept
Returns the number of items in the list.
void insertAtIndex(int index, ObjectType *newItem)
Inserts an item at a numeric index in the list.
void copyToArray(ObjectType **destArray) const noexcept
Copies the items in the list to an array.
LinkedListPointer() noexcept
Creates a null pointer to an empty list.
void swapWith(LinkedListPointer &other) noexcept
Swaps this pointer with another one.
void remove(ObjectType *const itemToRemove)
Removes a specific item from the list.