Loading...
Searching...
No Matches
juce::LinkedListPointer< ObjectType > Class Template Reference

## Detailed Description

template<class ObjectType>
class juce::LinkedListPointer< ObjectType >

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.

struct MyObject
{
int x, y, z;
// A linkable object must contain a member with this name and type, which must be
// accessible by the LinkedListPointer class. (This doesn't mean it has to be public -
// you could make your class a friend of a LinkedListPointer<MyObject> instead).
LinkedListPointer<MyObject> nextListItem;
};
LinkedListPointer<MyObject> myList;
myList.append (new MyObject());
myList.append (new MyObject());
int numItems = myList.size(); // returns 2
MyObject* lastInList = myList.getLast();
juce::LinkedListPointer
Helps to manipulate singly-linked lists of objects.
Definition juce_LinkedListPointer.h:69
juce::LinkedListPointer::getLast
LinkedListPointer & getLast() noexcept
Returns the last item in the list which this pointer points to.
Definition juce_LinkedListPointer.h:126
juce::LinkedListPointer::append
void append(ObjectType *const newItem)
Adds an item to the end of the list.
Definition juce_LinkedListPointer.h:243
juce::LinkedListPointer::size
int size() const noexcept
Returns the number of items in the list.
Definition juce_LinkedListPointer.h:140
juce::LinkedListPointer::LinkedListPointer
LinkedListPointer() noexcept
Creates a null pointer to an empty list.
Definition juce_LinkedListPointer.h:73
x
float x
Definition juce_UnityPluginInterface.h:197
y
float float y
Definition juce_UnityPluginInterface.h:197

The documentation for this class was generated from the following file:

- juce_core/containers/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.
| LinkedListPointer (ObjectType *const headItem) noexcept
| Creates a pointer to a list whose head is the item provided.
LinkedListPointer & | operator= (ObjectType *const newItem) noexcept
| Sets this pointer to point to a new list.
| LinkedListPointer (LinkedListPointer &&other) noexcept
LinkedListPointer & | operator= (LinkedListPointer &&other) noexcept
| operator ObjectType * () const noexcept
| Returns the item which this pointer points to.
ObjectType * | get () const noexcept
| Returns the item which this pointer points to.
LinkedListPointer & | getLast () noexcept
| Returns the last item in the list which this pointer points to.
int | size () const noexcept
| Returns the number of items in the list.
LinkedListPointer & | operator[] (int index) noexcept
| Returns the item at a given index in the list.
const LinkedListPointer & | operator[] (int index) const noexcept
| Returns the item at a given index in the list.
bool | contains (const ObjectType *const itemToLookFor) const noexcept
| Returns true if the list contains the given item.
void | insertNext (ObjectType *const newItem)
| Inserts an item into the list, placing it before the item that this pointer currently points to.
void | insertAtIndex (int index, ObjectType *newItem)
| Inserts an item at a numeric 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, and returning the old one.
void | append (ObjectType *const newItem)
| Adds an item to the end of the list.
void | addCopyOfList (const LinkedListPointer &other)
| Creates copies of all the items in another list and adds them to this one.
ObjectType * | removeNext () noexcept
| Removes the head item from the list.
void | remove (ObjectType *const itemToRemove)
| Removes a specific item from the list.
void | deleteAll ()
| Iterates the list, calling the delete operator on all of its elements and leaving this pointer empty.
LinkedListPointer * | findPointerTo (ObjectType *const itemToLookFor) noexcept
| Finds a pointer to a given item.
void | copyToArray (ObjectType **destArray) const noexcept
| Copies the items in the list to an array.
void | swapWith (LinkedListPointer &other) noexcept
| Swaps this pointer with another one.

## Constructors and Destructors

## LinkedListPointer() [1/3]

template<class ObjectType>

juce::LinkedListPointer< ObjectType >::LinkedListPointer | ( |  | ) |

inline noexcept

Creates a null pointer to an empty list.

Referenced by addCopyOfList(), juce::LinkedListPointer< ObjectType >::Appender::Appender(), findPointerTo(), getLast(), LinkedListPointer(), operator=(), operator=(), operator[](), operator[](), and swapWith().

## LinkedListPointer() [2/3]

template<class ObjectType>

juce::LinkedListPointer< ObjectType >::LinkedListPointer | ( | ObjectType *const | headItem | ) |

inline explicit noexcept

Creates a pointer to a list whose head is the item provided.

## LinkedListPointer() [3/3]

template<class ObjectType>

juce::LinkedListPointer< ObjectType >::LinkedListPointer | ( | LinkedListPointer< ObjectType > && | other | ) |

inline noexcept

References LinkedListPointer().

## Member Functions

## operator=() [1/2]

template<class ObjectType>

LinkedListPointer & juce::LinkedListPointer< ObjectType >::operator= | ( | ObjectType *const | newItem | ) |

inline noexcept

Sets this pointer to point to a new list.

References LinkedListPointer().

## operator=() [2/2]

template<class ObjectType>

LinkedListPointer & juce::LinkedListPointer< ObjectType >::operator= | ( | LinkedListPointer< ObjectType > && | other | ) |

inline noexcept

References jassert, and LinkedListPointer().

## operator ObjectType *()

template<class ObjectType>

juce::LinkedListPointer< ObjectType >::operator ObjectType * | ( |  | ) | const

inline noexcept

Returns the item which this pointer points to.

## get()

template<class ObjectType>

ObjectType * juce::LinkedListPointer< ObjectType >::get | ( |  | ) | const

inline noexcept

Returns the item which this pointer points to.

## getLast()

template<class ObjectType>

LinkedListPointer & juce::LinkedListPointer< ObjectType >::getLast | ( |  | ) |

inline noexcept

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.

References LinkedListPointer().

Referenced by append().

## size()

template<class ObjectType>

int juce::LinkedListPointer< ObjectType >::size | ( |  | ) | const

inline noexcept

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.

## operator[]() [1/2]

template<class ObjectType>

LinkedListPointer & juce::LinkedListPointer< ObjectType >::operator[] | ( | int | index | ) |

inline noexcept

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.

References LinkedListPointer().

## operator[]() [2/2]

template<class ObjectType>

const LinkedListPointer & juce::LinkedListPointer< ObjectType >::operator[] | ( | int | index | ) | const

inline noexcept

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.

References LinkedListPointer().

## contains()

template<class ObjectType>

bool juce::LinkedListPointer< ObjectType >::contains | ( | const ObjectType *const | itemToLookFor | ) | const

inline noexcept

Returns true if the list contains the given item.

## insertNext()

template<class ObjectType>

void juce::LinkedListPointer< ObjectType >::insertNext | ( | ObjectType *const | newItem | ) |

inline

Inserts an item into the list, placing it before the item that this pointer currently points to.

References jassert, JUCE_BEGIN_IGNORE_WARNINGS_MSVC, and JUCE_END_IGNORE_WARNINGS_MSVC.

## insertAtIndex()

template<class ObjectType>

void juce::LinkedListPointer< ObjectType >::insertAtIndex | ( | int | index,
|  | ObjectType * | newItem )

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.

References jassert.

## replaceNext()

template<class ObjectType>

ObjectType * juce::LinkedListPointer< ObjectType >::replaceNext | ( | ObjectType *const | newItem | ) |

inline noexcept

Replaces the object that this pointer points to, appending the rest of the list to the new object, and returning the old one.

References jassert, JUCE_BEGIN_IGNORE_WARNINGS_MSVC, and JUCE_END_IGNORE_WARNINGS_MSVC.

## append()

template<class ObjectType>

void juce::LinkedListPointer< ObjectType >::append | ( | ObjectType *const | newItem | ) |

inline

Adds an item to the end of the list.

This operation involves iterating the whole list, so can be slow - if you need to append a number of items to your list, it's much more efficient to use the Appender class than to repeatedly call append().

References getLast().

## addCopyOfList()

template<class ObjectType>

void juce::LinkedListPointer< ObjectType >::addCopyOfList | ( | const LinkedListPointer< ObjectType > & | other | ) |

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.

References LinkedListPointer().

## removeNext()

template<class ObjectType>

ObjectType * juce::LinkedListPointer< ObjectType >::removeNext | ( |  | ) |

inline noexcept

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.

## remove()

template<class ObjectType>

void juce::LinkedListPointer< ObjectType >::remove | ( | ObjectType *const | itemToRemove | ) |

inline

Removes a specific item from the list.

Note that this will not delete the item, it simply unlinks it from the list.

References findPointerTo().

## deleteAll()

template<class ObjectType>

void juce::LinkedListPointer< ObjectType >::deleteAll | ( |  | ) |

inline

Iterates the list, calling the delete operator on all of its elements and leaving this pointer empty.

## findPointerTo()

template<class ObjectType>

LinkedListPointer * juce::LinkedListPointer< ObjectType >::findPointerTo | ( | ObjectType *const | itemToLookFor | ) |

inline noexcept

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.

References LinkedListPointer().

Referenced by remove().

## copyToArray()

template<class ObjectType>

void juce::LinkedListPointer< ObjectType >::copyToArray | ( | ObjectType ** | destArray | ) | const

inline noexcept

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!

References jassert, JUCE_BEGIN_IGNORE_WARNINGS_MSVC, and JUCE_END_IGNORE_WARNINGS_MSVC.

## swapWith()

template<class ObjectType>

void juce::LinkedListPointer< ObjectType >::swapWith | ( | LinkedListPointer< ObjectType > & | other | ) |

inline noexcept

Swaps this pointer with another one.

References LinkedListPointer().

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited