My Project
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
unordered_ref_array< T > Class Template Reference

similar to unordered array except that it will automatically call addref/Release when obj is added/removed. More...

#include <unordered_ref_array.h>

Public Types

typedef std::vector< T > base_class_type
 
typedef base_class_type::iterator iterator
 
typedef base_class_type::const_iterator const_iterator
 
typedef base_class_type::reverse_iterator reverse_iterator
 
typedef base_class_type::const_reverse_iterator const_reverse_iterator
 

Public Member Functions

iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
reverse_iterator rbegin ()
 
const_reverse_iterator rbegin () const
 
reverse_iterator rend ()
 
const_reverse_iterator rend () const
 
const_reverse_iterator crbegin () const
 
const_reverse_iterator crend () const
 
 unordered_ref_array ()
 Constructor.
 
 unordered_ref_array (size_t capacity)
 Constructor with a capacity.
 
 ~unordered_ref_array ()
 Destructor.
 
 unordered_ref_array (const unordered_ref_array< T > &other)
 Copy constructor.
 
 unordered_ref_array (unordered_ref_array< T > &&other)
 Move constructor.
 
unordered_ref_array< T > & operator= (const unordered_ref_array< T > &other)
 Copy assignment operator.
 
unordered_ref_array< T > & operator= (unordered_ref_array< T > &&other)
 Move assignment operator.
 
void reserve (size_t n)
 Request a change in capacity. More...
 
size_t capacity () const
 Returns the size of the storage space currently allocated for the array, expressed in terms of elements. More...
 
size_t size () const
 Returns the number of elements in the vector. More...
 
bool empty () const
 Returns whether the vector is empty (i.e. More...
 
size_t max_size () const
 Returns the maximum number of elements that the vector can hold. More...
 
size_t getIndex (T object) const
 Returns index of a certain object, return UINT_MAX if doesn't contain the object.
 
const_iterator find (T object) const
 Find the object in the vector. More...
 
iterator find (T object)
 
at (size_t index) const
 Returns the element at position 'index' in the vector. More...
 
front () const
 Returns the first element in the vector. More...
 
back () const
 Returns the last element of the vector. More...
 
bool contains (T object) const
 Returns a Boolean value that indicates whether object is present in vector. More...
 
bool equals (const unordered_ref_array< T > &other)
 Returns true if the two vectors are equal.
 
void push_back (T object)
 Adds a new element at the end of the vector, after its current last element. More...
 
void push_back (const unordered_ref_array< T > &other)
 Push all elements of an existing vector to the end of current vector. More...
 
void insert (size_t index, T object)
 Insert a certain object at a certain index. More...
 
void pop_back ()
 Removes the last element in the vector, effectively reducing the container size by one, decrease the reference count of the deleted object.
 
void eraseObject (T object, bool removeAll=false)
 Remove a certain object in Vector. More...
 
iterator erase (iterator position)
 Removes from the vector with an iterator. More...
 
iterator erase (iterator first, iterator last)
 Removes from the vector with a range of elements ( [first, last) ). More...
 
iterator erase (size_t index)
 Removes from the vector with an index. More...
 
void clear ()
 Removes all elements from the vector (which are destroyed), leaving the container with a size of 0. More...
 
void swap (T object1, T object2)
 Swap two elements.
 
void swap (size_t index1, size_t index2)
 Swap two elements with certain indexes.
 
void replace (size_t index, T object)
 Replace object at index with another object. More...
 
void reverse ()
 reverses the vector
 
void shrink_to_fit ()
 Shrinks the vector so the memory footprint corresponds with the number of items.
 

Protected Member Functions

void addRefForAllObjects ()
 addrefs all the objects in the vector
 

Protected Attributes

base_class_type m_data
 

Detailed Description

template<typename T>
class unordered_ref_array< T >

similar to unordered array except that it will automatically call addref/Release when obj is added/removed.

it has fast random access, insertion, and deletion. This class is often used to keep track of a collection of CBaseObject or other reference counted objects, such as child nodes. e.g. typedef unordered_ref_array<CBaseObject*> CChildObjectList_Type; typedef unordered_ref_array<CRefCounted*> CChildObjectList_Type;

Member Function Documentation

§ at()

template<typename T>
T unordered_ref_array< T >::at ( size_t  index) const
inline

Returns the element at position 'index' in the vector.

§ back()

template<typename T>
T unordered_ref_array< T >::back ( ) const
inline

Returns the last element of the vector.

§ capacity()

template<typename T>
size_t unordered_ref_array< T >::capacity ( ) const
inline

Returns the size of the storage space currently allocated for the array, expressed in terms of elements.

Note
This capacity is not necessarily equal to the array size. It can be equal or greater, with the extra space allowing to accommodate for growth without the need to reallocate on each insertion.
Returns
The size of the currently allocated storage capacity in the array, measured in terms of the number elements it can hold.

§ clear()

template<typename T>
void unordered_ref_array< T >::clear ( )
inline

Removes all elements from the vector (which are destroyed), leaving the container with a size of 0.

Note
All the elements in the vector will be Released (reference count will be decreased).

§ contains()

template<typename T>
bool unordered_ref_array< T >::contains ( object) const
inline

Returns a Boolean value that indicates whether object is present in vector.

§ empty()

template<typename T>
bool unordered_ref_array< T >::empty ( ) const
inline

Returns whether the vector is empty (i.e.

whether its size is 0).

Note
This function does not modify the container in any way. To clear the content of a vector, see Vector<T>::clear.

§ erase() [1/3]

template<typename T>
iterator unordered_ref_array< T >::erase ( iterator  position)
inline

Removes from the vector with an iterator.

Parameters
positionIterator pointing to a single element to be removed from the vector.
Returns
An iterator pointing to the new location of the element that followed the last element erased by the function call. This is the container end if the operation erased the last element in the sequence.

§ erase() [2/3]

template<typename T>
iterator unordered_ref_array< T >::erase ( iterator  first,
iterator  last 
)
inline

Removes from the vector with a range of elements ( [first, last) ).

Parameters
firstThe beginning of the range
lastThe end of the range, the 'last' will not used, it's only for indicating the end of range.
Returns
An iterator pointing to the new location of the element that followed the last element erased by the function call. This is the container end if the operation erased the last element in the sequence.

§ erase() [3/3]

template<typename T>
iterator unordered_ref_array< T >::erase ( size_t  index)
inline

Removes from the vector with an index.

Parameters
indexThe index of the element to be removed from the vector.
Returns
An iterator pointing to the new location of the element that followed the last element erased by the function call. This is the container end if the operation erased the last element in the sequence.

§ eraseObject()

template<typename T>
void unordered_ref_array< T >::eraseObject ( object,
bool  removeAll = false 
)
inline

Remove a certain object in Vector.

Parameters
objectThe object to be removed.
removeAllWhether to remove all elements with the same value. If its value is 'false', it will just erase the first occurrence.

§ find()

template<typename T>
const_iterator unordered_ref_array< T >::find ( object) const
inline

Find the object in the vector.

Returns
Returns an iterator to the first element in the range [first,last) that compares equal to val. If no such element is found, the function returns last.

§ front()

template<typename T>
T unordered_ref_array< T >::front ( ) const
inline

Returns the first element in the vector.

§ insert()

template<typename T>
void unordered_ref_array< T >::insert ( size_t  index,
object 
)
inline

Insert a certain object at a certain index.

Note
The vector is extended by inserting new elements before the element at the specified 'index', effectively increasing the container size by the number of elements inserted. This causes an automatic reallocation of the allocated storage space if -and only if- the new vector size surpasses the current vector capacity.

§ max_size()

template<typename T>
size_t unordered_ref_array< T >::max_size ( ) const
inline

Returns the maximum number of elements that the vector can hold.

§ push_back() [1/2]

template<typename T>
void unordered_ref_array< T >::push_back ( object)
inline

Adds a new element at the end of the vector, after its current last element.

Note
This effectively increases the container size by one, which causes an automatic reallocation of the allocated storage space if -and only if- the new vector size surpasses the current vector capacity.

§ push_back() [2/2]

template<typename T>
void unordered_ref_array< T >::push_back ( const unordered_ref_array< T > &  other)
inline

Push all elements of an existing vector to the end of current vector.

§ replace()

template<typename T>
void unordered_ref_array< T >::replace ( size_t  index,
object 
)
inline

Replace object at index with another object.

§ reserve()

template<typename T>
void unordered_ref_array< T >::reserve ( size_t  n)
inline

Request a change in capacity.

Parameters
capacityMinimum capacity for the array. If n is greater than the current array capacity, the function causes the container to reallocate its storage increasing its capacity to n (or greater).

§ size()

template<typename T>
size_t unordered_ref_array< T >::size ( ) const
inline

Returns the number of elements in the vector.

Note
This is the number of actual objects held in the vector, which is not necessarily equal to its storage capacity.
Returns
The number of elements in the container.

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