Holds a set of unique primitive objects, such as ints or doubles. More...
Public Types | |
| typedef TypeOfCriticalSectionToUse::ScopedLockType | ScopedLockType |
| Returns the type of scoped lock to use for locking this array. | |
Public Member Functions | |
| SortedSet () throw () | |
| Creates an empty set. | |
| SortedSet (const SortedSet &other) throw () | |
| Creates a copy of another set. | |
| ~SortedSet () throw () | |
| Destructor. | |
| SortedSet & | operator= (const SortedSet &other) throw () |
| Copies another set over this one. | |
| bool | operator== (const SortedSet< ElementType > &other) const throw () |
| Compares this set to another one. | |
| bool | operator!= (const SortedSet< ElementType > &other) const throw () |
| Compares this set to another one. | |
| void | clear () throw () |
| Removes all elements from the set. | |
| void | clearQuick () throw () |
| Removes all elements from the set without freeing the array's allocated storage. | |
| int | size () const throw () |
| Returns the current number of elements in the set. | |
| ElementType | operator[] (const int index) const throw () |
| Returns one of the elements in the set. | |
| ElementType | getUnchecked (const int index) const throw () |
| Returns one of the elements in the set, without checking the index passed in. | |
| ElementType | getFirst () const throw () |
| Returns the first element in the set, or 0 if the set is empty. | |
| ElementType | getLast () const throw () |
| Returns the last element in the set, or 0 if the set is empty. | |
| int | indexOf (const ElementType elementToLookFor) const throw () |
| Finds the index of the first element which matches the value passed in. | |
| bool | contains (const ElementType elementToLookFor) const throw () |
| Returns true if the set contains at least one occurrence of an object. | |
| void | add (const ElementType newElement) throw () |
| Adds a new element to the set, (as long as it's not already in there). | |
| void | addArray (const ElementType *elementsToAdd, int numElementsToAdd) throw () |
| Adds elements from an array to this set. | |
| template<class OtherSetType > | |
| void | addSet (const OtherSetType &setToAddFrom, int startIndex=0, int numElementsToAdd=-1) throw () |
| Adds elements from another set to this one. | |
| ElementType | remove (const int indexToRemove) throw () |
| Removes an element from the set. | |
| void | removeValue (const ElementType valueToRemove) throw () |
| Removes an item from the set. | |
| template<class OtherSetType > | |
| void | removeValuesIn (const OtherSetType &otherSet) throw () |
| Removes any elements which are also in another set. | |
| template<class OtherSetType > | |
| void | removeValuesNotIn (const OtherSetType &otherSet) throw () |
| Removes any elements which are not found in another set. | |
| void | minimiseStorageOverheads () throw () |
| Reduces the amount of storage being used by the set. | |
| const TypeOfCriticalSectionToUse & | getLock () const throw () |
| Returns the CriticalSection that locks this array. | |
Holds a set of unique primitive objects, such as ints or doubles.
A set can only hold one item with a given value, so if for example it's a set of integers, attempting to add the same integer twice will do nothing the second time.
Internally, the list of items is kept sorted (which means that whatever kind of primitive type is used must support the ==, <, >, <= and >= operators to determine the order), and searching the set for known values is very fast because it uses a binary-chop method.
Note that if you're using a class or struct as the element type, it must be capable of being copied or moved with a straightforward memcpy, rather than needing construction and destruction code.
To make all the set's methods thread-safe, pass in "CriticalSection" as the templated TypeOfCriticalSectionToUse parameter, instead of the default DummyCriticalSection.
| typedef TypeOfCriticalSectionToUse::ScopedLockType SortedSet< ElementType, TypeOfCriticalSectionToUse >::ScopedLockType |
Returns the type of scoped lock to use for locking this array.
| SortedSet< ElementType, TypeOfCriticalSectionToUse >::SortedSet | ( | ) | throw () |
Creates an empty set.
| SortedSet< ElementType, TypeOfCriticalSectionToUse >::SortedSet | ( | const SortedSet< ElementType, TypeOfCriticalSectionToUse > & | other | ) | throw () |
Creates a copy of another set.
| other | the set to copy |
| SortedSet< ElementType, TypeOfCriticalSectionToUse >::~SortedSet | ( | ) | throw () |
Destructor.
| SortedSet& SortedSet< ElementType, TypeOfCriticalSectionToUse >::operator= | ( | const SortedSet< ElementType, TypeOfCriticalSectionToUse > & | other | ) | throw () |
Copies another set over this one.
| other | the set to copy |
| bool SortedSet< ElementType, TypeOfCriticalSectionToUse >::operator== | ( | const SortedSet< ElementType > & | other | ) | const throw () |
Compares this set to another one.
Two sets are considered equal if they both contain the same set of elements.
| other | the other set to compare with |
Referenced by SortedSet< AudioIODeviceCallback * >::operator!=().
| bool SortedSet< ElementType, TypeOfCriticalSectionToUse >::operator!= | ( | const SortedSet< ElementType > & | other | ) | const throw () |
Compares this set to another one.
Two sets are considered equal if they both contain the same set of elements.
| other | the other set to compare with |
| void SortedSet< ElementType, TypeOfCriticalSectionToUse >::clear | ( | ) | throw () |
Removes all elements from the set.
This will remove all the elements, and free any storage that the set is using. To clear it without freeing the storage, use the clearQuick() method instead.
Referenced by SortedSet< AudioIODeviceCallback * >::removeValuesIn(), and SortedSet< AudioIODeviceCallback * >::removeValuesNotIn().
| void SortedSet< ElementType, TypeOfCriticalSectionToUse >::clearQuick | ( | ) | throw () |
Removes all elements from the set without freeing the array's allocated storage.
| int SortedSet< ElementType, TypeOfCriticalSectionToUse >::size | ( | ) | const throw () |
Returns the current number of elements in the set.
| ElementType SortedSet< ElementType, TypeOfCriticalSectionToUse >::operator[] | ( | const int | index | ) | const throw () |
Returns one of the elements in the set.
If the index passed in is beyond the range of valid elements, this will return zero.
If you're certain that the index will always be a valid element, you can call getUnchecked() instead, which is faster.
| index | the index of the element being requested (0 is the first element in the set) |
| ElementType SortedSet< ElementType, TypeOfCriticalSectionToUse >::getUnchecked | ( | const int | index | ) | const throw () |
Returns one of the elements in the set, without checking the index passed in.
Unlike the operator[] method, this will try to return an element without checking that the index is within the bounds of the set, so should only be used when you're confident that it will always be a valid index.
| index | the index of the element being requested (0 is the first element in the set) |
| ElementType SortedSet< ElementType, TypeOfCriticalSectionToUse >::getFirst | ( | ) | const throw () |
Returns the first element in the set, or 0 if the set is empty.
| ElementType SortedSet< ElementType, TypeOfCriticalSectionToUse >::getLast | ( | ) | const throw () |
Returns the last element in the set, or 0 if the set is empty.
| int SortedSet< ElementType, TypeOfCriticalSectionToUse >::indexOf | ( | const ElementType | elementToLookFor | ) | const throw () |
Finds the index of the first element which matches the value passed in.
This will search the set for the given object, and return the index of its first occurrence. If the object isn't found, the method will return -1.
| elementToLookFor | the value or object to look for |
Referenced by SortedSet< AudioIODeviceCallback * >::removeValue().
| bool SortedSet< ElementType, TypeOfCriticalSectionToUse >::contains | ( | const ElementType | elementToLookFor | ) | const throw () |
Returns true if the set contains at least one occurrence of an object.
| elementToLookFor | the value or object to look for |
| void SortedSet< ElementType, TypeOfCriticalSectionToUse >::add | ( | const ElementType | newElement | ) | throw () |
Adds a new element to the set, (as long as it's not already in there).
| newElement | the new object to add to the set |
Referenced by SortedSet< AudioIODeviceCallback * >::addArray().
| void SortedSet< ElementType, TypeOfCriticalSectionToUse >::addArray | ( | const ElementType * | elementsToAdd, | |
| int | numElementsToAdd | |||
| ) | throw () |
Adds elements from an array to this set.
| elementsToAdd | the array of elements to add | |
| numElementsToAdd | how many elements are in this other array |
Referenced by SortedSet< AudioIODeviceCallback * >::addSet().
| void SortedSet< ElementType, TypeOfCriticalSectionToUse >::addSet | ( | const OtherSetType & | setToAddFrom, | |
| int | startIndex = 0, |
|||
| int | numElementsToAdd = -1 | |||
| ) | throw () |
Adds elements from another set to this one.
| setToAddFrom | the set from which to copy the elements | |
| startIndex | the first element of the other set to start copying from | |
| numElementsToAdd | how many elements to add from the other set. If this value is negative or greater than the number of available elements, all available elements will be copied. |
| ElementType SortedSet< ElementType, TypeOfCriticalSectionToUse >::remove | ( | const int | indexToRemove | ) | throw () |
Removes an element from the set.
This will remove the element at a given index. If the index passed in is out-of-range, nothing will happen.
| indexToRemove | the index of the element to remove |
| void SortedSet< ElementType, TypeOfCriticalSectionToUse >::removeValue | ( | const ElementType | valueToRemove | ) | throw () |
Removes an item from the set.
This will remove the given element from the set, if it's there.
| valueToRemove | the object to try to remove |
| void SortedSet< ElementType, TypeOfCriticalSectionToUse >::removeValuesIn | ( | const OtherSetType & | otherSet | ) | throw () |
Removes any elements which are also in another set.
| otherSet | the other set in which to look for elements to remove |
| void SortedSet< ElementType, TypeOfCriticalSectionToUse >::removeValuesNotIn | ( | const OtherSetType & | otherSet | ) | throw () |
Removes any elements which are not found in another set.
Only elements which occur in this other set will be retained.
| otherSet | the set in which to look for elements NOT to remove |
| void SortedSet< ElementType, TypeOfCriticalSectionToUse >::minimiseStorageOverheads | ( | ) | throw () |
Reduces the amount of storage being used by the set.
Sets typically allocate slightly more storage than they need, and after removing elements, they may have quite a lot of unused space allocated. This method will reduce the amount of allocated storage to a minimum.
Referenced by SortedSet< AudioIODeviceCallback * >::operator=(), and SortedSet< AudioIODeviceCallback * >::remove().
| const TypeOfCriticalSectionToUse& SortedSet< ElementType, TypeOfCriticalSectionToUse >::getLock | ( | ) | const throw () |
Returns the CriticalSection that locks this array.
To lock, you can call getLock().enter() and getLock().exit(), or preferably use an object of ScopedLockType as an RAII lock for it.
Referenced by SortedSet< AudioIODeviceCallback * >::add(), SortedSet< AudioIODeviceCallback * >::addArray(), SortedSet< AudioIODeviceCallback * >::addSet(), SortedSet< AudioIODeviceCallback * >::clear(), SortedSet< AudioIODeviceCallback * >::clearQuick(), SortedSet< AudioIODeviceCallback * >::contains(), SortedSet< AudioIODeviceCallback * >::getFirst(), SortedSet< AudioIODeviceCallback * >::getLast(), SortedSet< AudioIODeviceCallback * >::getUnchecked(), SortedSet< AudioIODeviceCallback * >::indexOf(), SortedSet< AudioIODeviceCallback * >::minimiseStorageOverheads(), SortedSet< AudioIODeviceCallback * >::operator=(), SortedSet< AudioIODeviceCallback * >::operator==(), SortedSet< AudioIODeviceCallback * >::operator[](), SortedSet< AudioIODeviceCallback * >::remove(), SortedSet< AudioIODeviceCallback * >::removeValue(), SortedSet< AudioIODeviceCallback * >::removeValuesIn(), and SortedSet< AudioIODeviceCallback * >::removeValuesNotIn().
1.6.3