cocos2d-x  3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Vector< T > Class Template Reference

#include <CCVector.h>

Public Types

typedef std::vector< T >::iterator iterator
 
typedef std::vector< T >
::const_iterator 
const_iterator
 
typedef std::vector< T >
::reverse_iterator 
reverse_iterator
 
typedef std::vector< T >
::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
 
 Vector ()
 Constructor. More...
 
 Vector (ssize_t capacity)
 Constructor with a capacity. More...
 
 ~Vector ()
 Destructor. More...
 
 Vector (const Vector< T > &other)
 Copy constructor. More...
 
 Vector (Vector< T > &&other)
 Move constructor. More...
 
Vector< T > & operator= (const Vector< T > &other)
 Copy assignment operator. More...
 
Vector< T > & operator= (Vector< T > &&other)
 Move assignment operator. More...
 
void reserve (ssize_t n)
 Request a change in capacity. More...
 
ssize_t capacity () const
 Returns the size of the storage space currently allocated for the vector, expressed in terms of elements. More...
 
ssize_t size () const
 Returns the number of elements in the vector. More...
 
bool empty () const
 Returns whether the vector is empty (i.e. More...
 
ssize_t max_size () const
 Returns the maximum number of elements that the vector can hold. More...
 
ssize_t getIndex (T object) const
 Returns index of a certain object, return UINT_MAX if doesn't contain the object. More...
 
const_iterator find (T object) const
 Find the object in the vector. More...
 
iterator find (T object)
 
at (ssize_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...
 
getRandomObject () const
 Returns a random 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 Vector< T > &other)
 Returns true if the two vectors are equal. More...
 
void pushBack (T object)
 Adds a new element at the end of the vector, after its current last element. More...
 
void pushBack (const Vector< T > &other)
 Push all elements of an existing vector to the end of current vector. More...
 
void insert (ssize_t index, T object)
 Insert a certain object at a certain index. More...
 
void popBack ()
 Removes the last element in the vector, effectively reducing the container size by one, decrease the referece count of the deleted object. More...
 
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 (ssize_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. More...
 
void swap (ssize_t index1, ssize_t index2)
 Swap two elements with certain indexes. More...
 
void replace (ssize_t index, T object)
 Replace object at index with another object. More...
 
void reverse ()
 reverses the vector More...
 
void shrinkToFit ()
 Shrinks the vector so the memory footprint corresponds with the number of items. More...
 

Protected Member Functions

void addRefForAllObjects ()
 Retains all the objects in the vector. More...
 

Protected Attributes

std::vector< T > _data
 

Member Typedef Documentation

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

Constructor & Destructor Documentation

Vector ( )
inline

Constructor.

Vector ( ssize_t  capacity)
inlineexplicit

Constructor with a capacity.

~Vector ( )
inline

Destructor.

Vector ( const Vector< T > &  other)
inline

Copy constructor.

Vector ( Vector< T > &&  other)
inline

Move constructor.

Member Function Documentation

void addRefForAllObjects ( )
inlineprotected

Retains all the objects in the vector.

T at ( ssize_t  index) const
inline

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

T back ( ) const
inline

Returns the last element of the vector.

iterator begin ( )
inline
const_iterator begin ( ) const
inline
ssize_t capacity ( ) const
inline

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

Note
This capacity is not necessarily equal to the vector 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 vector, measured in terms of the number elements it can hold.
const_iterator cbegin ( ) const
inline
const_iterator cend ( ) const
inline
void 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 (referece count will be decreased).
bool contains ( object) const
inline

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

const_reverse_iterator crbegin ( ) const
inline
const_reverse_iterator crend ( ) const
inline
bool 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.
iterator end ( )
inline
const_iterator end ( ) const
inline
bool equals ( const Vector< T > &  other)
inline

Returns true if the two vectors are equal.

iterator 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.
iterator 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.
iterator erase ( ssize_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.
void 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.
const_iterator 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.
iterator find ( object)
inline
T front ( ) const
inline

Returns the first element in the vector.

ssize_t getIndex ( object) const
inline

Returns index of a certain object, return UINT_MAX if doesn't contain the object.

T getRandomObject ( ) const
inline

Returns a random element of the vector.

void insert ( ssize_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.
ssize_t max_size ( ) const
inline

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

Vector<T>& operator= ( const Vector< T > &  other)
inline

Copy assignment operator.

Vector<T>& operator= ( Vector< T > &&  other)
inline

Move assignment operator.

void popBack ( )
inline

Removes the last element in the vector, effectively reducing the container size by one, decrease the referece count of the deleted object.

void pushBack ( 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.
void pushBack ( const Vector< T > &  other)
inline

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

reverse_iterator rbegin ( )
inline
const_reverse_iterator rbegin ( ) const
inline
reverse_iterator rend ( )
inline
const_reverse_iterator rend ( ) const
inline
void replace ( ssize_t  index,
object 
)
inline

Replace object at index with another object.

void reserve ( ssize_t  n)
inline

Request a change in capacity.

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

reverses the vector

void shrinkToFit ( )
inline

Shrinks the vector so the memory footprint corresponds with the number of items.

ssize_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.
void swap ( object1,
object2 
)
inline

Swap two elements.

void swap ( ssize_t  index1,
ssize_t  index2 
)
inline

Swap two elements with certain indexes.

Member Data Documentation

std::vector<T> _data
protected

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