SortedSet< ElementType, TypeOfCriticalSectionToUse > Class Template Reference

Holds a set of unique primitive objects, such as ints or doubles. More...

List of all members.

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.
SortedSetoperator= (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 TypeOfCriticalSectionToUsegetLock () const throw ()
 Returns the CriticalSection that locks this array.

Detailed Description

template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
class SortedSet< ElementType, TypeOfCriticalSectionToUse >

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.

See also:
Array, OwnedArray, ReferenceCountedArray, StringArray, CriticalSection

Member Typedef Documentation

template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
typedef TypeOfCriticalSectionToUse::ScopedLockType SortedSet< ElementType, TypeOfCriticalSectionToUse >::ScopedLockType

Returns the type of scoped lock to use for locking this array.


Constructor & Destructor Documentation

template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
SortedSet< ElementType, TypeOfCriticalSectionToUse >::SortedSet (  )  throw ()

Creates an empty set.

template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
SortedSet< ElementType, TypeOfCriticalSectionToUse >::SortedSet ( const SortedSet< ElementType, TypeOfCriticalSectionToUse > &  other  )  throw ()

Creates a copy of another set.

Parameters:
other the set to copy
template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
SortedSet< ElementType, TypeOfCriticalSectionToUse >::~SortedSet (  )  throw ()

Destructor.


Member Function Documentation

template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
SortedSet& SortedSet< ElementType, TypeOfCriticalSectionToUse >::operator= ( const SortedSet< ElementType, TypeOfCriticalSectionToUse > &  other  )  throw ()

Copies another set over this one.

Parameters:
other the set to copy
template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
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.

Parameters:
other the other set to compare with

Referenced by SortedSet< AudioIODeviceCallback * >::operator!=().

template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
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.

Parameters:
other the other set to compare with
template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
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.

See also:
clearQuick

Referenced by SortedSet< AudioIODeviceCallback * >::removeValuesIn(), and SortedSet< AudioIODeviceCallback * >::removeValuesNotIn().

template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
void SortedSet< ElementType, TypeOfCriticalSectionToUse >::clearQuick (  )  throw ()

Removes all elements from the set without freeing the array's allocated storage.

See also:
clear
template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
int SortedSet< ElementType, TypeOfCriticalSectionToUse >::size (  )  const throw ()

Returns the current number of elements in the set.

template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
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.

Parameters:
index the index of the element being requested (0 is the first element in the set)
See also:
getUnchecked, getFirst, getLast
template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
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.

Parameters:
index the index of the element being requested (0 is the first element in the set)
See also:
operator[], getFirst, getLast
template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
ElementType SortedSet< ElementType, TypeOfCriticalSectionToUse >::getFirst (  )  const throw ()

Returns the first element in the set, or 0 if the set is empty.

See also:
operator[], getUnchecked, getLast
template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
ElementType SortedSet< ElementType, TypeOfCriticalSectionToUse >::getLast (  )  const throw ()

Returns the last element in the set, or 0 if the set is empty.

See also:
operator[], getUnchecked, getFirst
template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
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.

Parameters:
elementToLookFor the value or object to look for
Returns:
the index of the object, or -1 if it's not found

Referenced by SortedSet< AudioIODeviceCallback * >::removeValue().

template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
bool SortedSet< ElementType, TypeOfCriticalSectionToUse >::contains ( const ElementType  elementToLookFor  )  const throw ()

Returns true if the set contains at least one occurrence of an object.

Parameters:
elementToLookFor the value or object to look for
Returns:
true if the item is found
template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
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).

Parameters:
newElement the new object to add to the set
See also:
set, insert, addIfNotAlreadyThere, addSorted, addSet, addArray

Referenced by SortedSet< AudioIODeviceCallback * >::addArray().

template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
void SortedSet< ElementType, TypeOfCriticalSectionToUse >::addArray ( const ElementType *  elementsToAdd,
int  numElementsToAdd 
) throw ()

Adds elements from an array to this set.

Parameters:
elementsToAdd the array of elements to add
numElementsToAdd how many elements are in this other array
See also:
add

Referenced by SortedSet< AudioIODeviceCallback * >::addSet().

template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
template<class OtherSetType >
void SortedSet< ElementType, TypeOfCriticalSectionToUse >::addSet ( const OtherSetType &  setToAddFrom,
int  startIndex = 0,
int  numElementsToAdd = -1 
) throw ()

Adds elements from another set to this one.

Parameters:
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.
See also:
add
template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
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.

Parameters:
indexToRemove the index of the element to remove
Returns:
the element that has been removed
See also:
removeValue, removeRange
template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
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.

Parameters:
valueToRemove the object to try to remove
See also:
remove, removeRange
template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
template<class OtherSetType >
void SortedSet< ElementType, TypeOfCriticalSectionToUse >::removeValuesIn ( const OtherSetType &  otherSet  )  throw ()

Removes any elements which are also in another set.

Parameters:
otherSet the other set in which to look for elements to remove
See also:
removeValuesNotIn, remove, removeValue, removeRange
template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
template<class OtherSetType >
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.

Parameters:
otherSet the set in which to look for elements NOT to remove
See also:
removeValuesIn, remove, removeValue, removeRange
template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
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().

template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
const TypeOfCriticalSectionToUse& SortedSet< ElementType, TypeOfCriticalSectionToUse >::getLock (  )  const throw ()

The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Mon Apr 26 11:42:17 2010 for JUCE by  doxygen 1.6.3