Helps to manipulate singly-linked lists of objects. More...
#include <juce_LinkedListPointer.h>
Classes | |
class | Appender |
Allows efficient repeated insertions into a list. More... | |
Public Member Functions | |
LinkedListPointer () noexcept | |
Creates a null pointer to an empty list. More... | |
LinkedListPointer (LinkedListPointer &&other) noexcept | |
LinkedListPointer (ObjectType *const headItem) noexcept | |
Creates a pointer to a list whose head is the item provided. More... | |
void | addCopyOfList (const LinkedListPointer &other) |
Creates copies of all the items in another list and adds them to this one. More... | |
void | append (ObjectType *const newItem) |
Adds an item to the end of the list. More... | |
bool | contains (const ObjectType *const itemToLookFor) const noexcept |
Returns true if the list contains the given item. More... | |
void | copyToArray (ObjectType **destArray) const noexcept |
Copies the items in the list to an array. More... | |
void | deleteAll () |
Iterates the list, calling the delete operator on all of its elements and leaving this pointer empty. More... | |
LinkedListPointer * | findPointerTo (ObjectType *const itemToLookFor) noexcept |
Finds a pointer to a given item. More... | |
ObjectType * | get () const noexcept |
Returns the item which this pointer points to. More... | |
LinkedListPointer & | getLast () noexcept |
Returns the last item in the list which this pointer points to. More... | |
void | insertAtIndex (int index, ObjectType *newItem) |
Inserts an item at a numeric index in the list. More... | |
void | insertNext (ObjectType *const newItem) |
Inserts an item into the list, placing it before the item that this pointer currently points to. More... | |
operator ObjectType * () const noexcept | |
Returns the item which this pointer points to. More... | |
LinkedListPointer & | operator= (LinkedListPointer &&other) noexcept |
LinkedListPointer & | operator= (ObjectType *const newItem) noexcept |
Sets this pointer to point to a new list. More... | |
const LinkedListPointer & | operator[] (int index) const noexcept |
Returns the item at a given index in the list. More... | |
LinkedListPointer & | operator[] (int index) noexcept |
Returns the item at a given index in the list. More... | |
void | remove (ObjectType *const itemToRemove) |
Removes a specific item from the list. More... | |
ObjectType * | removeNext () noexcept |
Removes the head item from the list. More... | |
ObjectType * | replaceNext (ObjectType *const newItem) noexcept |
Replaces the object that this pointer points to, appending the rest of the list to the new object, and returning the old one. More... | |
int | size () const noexcept |
Returns the number of items in the list. More... | |
void | swapWith (LinkedListPointer &other) noexcept |
Swaps this pointer with another one. More... | |
Private Attributes | |
ObjectType * | item |
Helps to manipulate singly-linked lists of objects.
For objects that are designed to contain a pointer to the subsequent item in the list, this class contains methods to deal with the list. To use it, the ObjectType class that it points to must contain a LinkedListPointer called nextListItem, e.g.
@tags{Core}
|
inlinenoexcept |
Creates a null pointer to an empty list.
|
inlineexplicitnoexcept |
Creates a pointer to a list whose head is the item provided.
|
inlinenoexcept |
|
inline |
Creates copies of all the items in another list and adds them to this one.
This will use the ObjectType's copy constructor to try to create copies of each item in the other list, and appends them to this list.
|
inline |
|
inlinenoexcept |
Returns true if the list contains the given item.
|
inlinenoexcept |
Copies the items in the list to an array.
The destArray must contain enough elements to hold the entire list - no checks are made for this!
|
inline |
Iterates the list, calling the delete operator on all of its elements and leaving this pointer empty.
|
inlinenoexcept |
Finds a pointer to a given item.
If the item is found in the list, this returns the pointer that points to it. If the item isn't found, this returns null.
Referenced by juce::LinkedListPointer< juce::XmlElement::XmlAttributeNode >::remove().
|
inlinenoexcept |
Returns the item which this pointer points to.
|
inlinenoexcept |
Returns the last item in the list which this pointer points to.
This will iterate the list and return the last item found. Obviously the speed of this operation will be proportional to the size of the list. If the list is empty the return value will be this object. If you're planning on appending a number of items to your list, it's much more efficient to use the Appender class than to repeatedly call getLast() to find the end.
Referenced by juce::LinkedListPointer< juce::XmlElement::XmlAttributeNode >::append().
|
inline |
Inserts an item at a numeric index in the list.
Obviously this will involve iterating the list to find the item at the given index, so be careful about the impact this may have on execution time.
|
inline |
Inserts an item into the list, placing it before the item that this pointer currently points to.
|
inlinenoexcept |
Returns the item which this pointer points to.
References juce::LinkedListPointer< ObjectType >::item.
|
inlinenoexcept |
|
inlinenoexcept |
Sets this pointer to point to a new list.
|
inlinenoexcept |
Returns the item at a given index in the list.
Since the only way to find an item is to iterate the list, this operation can obviously be slow, depending on its size, so you should be careful when using this in algorithms.
|
inlinenoexcept |
Returns the item at a given index in the list.
Since the only way to find an item is to iterate the list, this operation can obviously be slow, depending on its size, so you should be careful when using this in algorithms.
|
inline |
Removes a specific item from the list.
Note that this will not delete the item, it simply unlinks it from the list.
|
inlinenoexcept |
Removes the head item from the list.
This won't delete the object that is removed, but returns it, so the caller can delete it if necessary.
|
inlinenoexcept |
Replaces the object that this pointer points to, appending the rest of the list to the new object, and returning the old one.
|
inlinenoexcept |
Returns the number of items in the list.
Obviously with a simple linked list, getting the size involves iterating the list, so this can be a lengthy operation - be careful when using this method in your code.
|
inlinenoexcept |
Swaps this pointer with another one.
|
private |
Referenced by juce::LinkedListPointer< juce::XmlElement::XmlAttributeNode >::addCopyOfList(), juce::LinkedListPointer< juce::XmlElement::XmlAttributeNode >::append(), juce::LinkedListPointer< juce::XmlElement::XmlAttributeNode >::contains(), juce::LinkedListPointer< juce::XmlElement::XmlAttributeNode >::copyToArray(), juce::LinkedListPointer< juce::XmlElement::XmlAttributeNode >::deleteAll(), juce::LinkedListPointer< juce::XmlElement::XmlAttributeNode >::get(), juce::LinkedListPointer< juce::XmlElement::XmlAttributeNode >::insertNext(), juce::LinkedListPointer< ObjectType >::operator ObjectType *(), juce::LinkedListPointer< juce::XmlElement::XmlAttributeNode >::operator=(), juce::LinkedListPointer< juce::XmlElement::XmlAttributeNode >::removeNext(), juce::LinkedListPointer< juce::XmlElement::XmlAttributeNode >::replaceNext(), juce::LinkedListPointer< juce::XmlElement::XmlAttributeNode >::size(), and juce::LinkedListPointer< juce::XmlElement::XmlAttributeNode >::swapWith().