ScummVM API documentation
Common::Array< T > Class Template Reference

#include <array.h>

Inheritance diagram for Common::Array< T >:
AGS3::std::array< T > AGS3::std::unordered_set< T, Hash, Pred > Common::SortedArray< T, CompareArgType > Pink::Array< T > Sci::PlaneList Common::SortedArray< T, const T &> Ultima::Shared::ItemArray< T > Ultima::Std::vector< T >

Public Types

typedef T * iterator
 
typedef const T * const_iterator
 
typedef T value_type
 
typedef uint size_type
 

Public Member Functions

 Array (size_type count)
 
 Array (size_type count, const T &value)
 
 Array (const Array< T > &array)
 
 Array (Array< T > &&old)
 
 Array (std::initializer_list< T > list)
 
template<class T2 >
 Array (const T2 *array, size_type n)
 
void push_back (const T &element)
 
void push_back (const Array< T > &array)
 
void pop_back ()
 
const T * data () const
 
T * data ()
 
T & front ()
 
const T & front () const
 
T & back ()
 
const T & back () const
 
void insert_at (size_type idx, const T &element)
 
void insert_at (size_type idx, const Array< T > &array)
 
void insert (iterator pos, const T &element)
 
remove_at (size_type idx)
 
T & operator[] (size_type idx)
 
const T & operator[] (size_type idx) const
 
Array< T > & operator= (const Array< T > &array)
 
Arrayoperator= (Array< T > &&old)
 
size_type size () const
 
void clear ()
 
iterator erase (iterator pos)
 
iterator erase (iterator first, iterator last)
 
bool empty () const
 
bool operator== (const Array< T > &other) const
 
bool operator!= (const Array< T > &other) const
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
void reserve (size_type newCapacity)
 
void resize (size_type newSize)
 
void resize (size_type newSize, const T value)
 
void assign (const_iterator first, const_iterator last)
 
void swap (Array &arr)
 

Protected Member Functions

void allocCapacity (size_type capacity)
 
void freeStorage (T *storage, const size_type elements)
 
iterator insert_aux (iterator pos, const_iterator first, const_iterator last)
 

Static Protected Member Functions

static size_type roundUpCapacity (size_type capacity)
 

Protected Attributes

size_type _capacity
 
size_type _size
 
T * _storage
 

Detailed Description

template<class T>
class Common::Array< T >

This class implements a dynamically sized container, which can be accessed similarly to a regular C++ array. Accessing elements is performed in constant time (like with plain arrays). In addition, you can append, insert, and remove entries (this is the 'dynamic' part). In general, doing that takes time proportional to the number of elements in the array.

The container class closest to this in the C++ standard library is std::vector. However, there are some differences.

Member Typedef Documentation

◆ iterator

template<class T>
typedef T* Common::Array< T >::iterator

Array iterator.

◆ const_iterator

template<class T>
typedef const T* Common::Array< T >::const_iterator

Const-qualified array iterator.

◆ value_type

template<class T>
typedef T Common::Array< T >::value_type

Value type of the array.

◆ size_type

template<class T>
typedef uint Common::Array< T >::size_type

Size type of the array.

Constructor & Destructor Documentation

◆ Array() [1/6]

template<class T>
Common::Array< T >::Array ( size_type  count)
inlineexplicit

Construct an array with count default-inserted instances of T. No copies are made.

◆ Array() [2/6]

template<class T>
Common::Array< T >::Array ( size_type  count,
const T &  value 
)
inline

Construct an array with count copies of elements with value value.

◆ Array() [3/6]

template<class T>
Common::Array< T >::Array ( const Array< T > &  array)
inline

Construct an array as a copy of the given array.

◆ Array() [4/6]

template<class T>
Common::Array< T >::Array ( Array< T > &&  old)
inline

Construct an array as a copy of the given array using the C++11 move semantic.

◆ Array() [5/6]

template<class T>
Common::Array< T >::Array ( std::initializer_list< T >  list)
inline

Construct an array using list initialization. For example:

Common::Array<int> myArray = {1, 7, 42};

constructs an array with 3 elements whose values are 1, 7, and 42 respectively.

Note
This constructor is only available when C++11 support is enabled.

◆ Array() [6/6]

template<class T>
template<class T2 >
Common::Array< T >::Array ( const T2 *  array,
size_type  n 
)
inline

Construct an array by copying data from a regular array.

Member Function Documentation

◆ push_back() [1/2]

template<class T>
void Common::Array< T >::push_back ( const T &  element)
inline

Append an element to the end of the array.

◆ push_back() [2/2]

template<class T>
void Common::Array< T >::push_back ( const Array< T > &  array)
inline

Append an element to the end of the array.

◆ pop_back()

template<class T>
void Common::Array< T >::pop_back ( )
inline

Remove the last element of the array.

◆ data() [1/2]

template<class T>
const T* Common::Array< T >::data ( ) const
inline

Return a pointer to the underlying memory serving as element storage.

◆ data() [2/2]

template<class T>
T* Common::Array< T >::data ( )
inline

Return a pointer to the underlying memory serving as element storage.

◆ front() [1/2]

template<class T>
T& Common::Array< T >::front ( )
inline

Return a reference to the first element of the array.

◆ front() [2/2]

template<class T>
const T& Common::Array< T >::front ( ) const
inline

Return a reference to the first element of the array.

◆ back() [1/2]

template<class T>
T& Common::Array< T >::back ( )
inline

Return a reference to the last element of the array.

◆ back() [2/2]

template<class T>
const T& Common::Array< T >::back ( ) const
inline

Return a reference to the last element of the array.

◆ insert_at() [1/2]

template<class T>
void Common::Array< T >::insert_at ( size_type  idx,
const T &  element 
)
inline

Insert an element into the array at the given position.

◆ insert_at() [2/2]

template<class T>
void Common::Array< T >::insert_at ( size_type  idx,
const Array< T > &  array 
)
inline

Insert copies of all the elements from the given array into this array at the given position.

◆ insert()

template<class T>
void Common::Array< T >::insert ( iterator  pos,
const T &  element 
)
inline

Insert an element before pos.

◆ remove_at()

template<class T>
T Common::Array< T >::remove_at ( size_type  idx)
inline

Remove an element at the given position from the array and return the value of that element.

◆ operator[]() [1/2]

template<class T>
T& Common::Array< T >::operator[] ( size_type  idx)
inline

Return a reference to the element at the given position in the array.

◆ operator[]() [2/2]

template<class T>
const T& Common::Array< T >::operator[] ( size_type  idx) const
inline

Return a const reference to the element at the given position in the array.

◆ operator=() [1/2]

template<class T>
Array<T>& Common::Array< T >::operator= ( const Array< T > &  array)
inline

Assign the given array to this array.

◆ operator=() [2/2]

template<class T>
Array& Common::Array< T >::operator= ( Array< T > &&  old)
inline

Assign the given array to this array using the C++11 move semantic.

◆ size()

template<class T>
size_type Common::Array< T >::size ( ) const
inline

Return the size of the array.

◆ clear()

template<class T>
void Common::Array< T >::clear ( )
inline

Clear the array of all its elements.

◆ erase() [1/2]

template<class T>
iterator Common::Array< T >::erase ( iterator  pos)
inline

Erase the element at pos position and return an iterator pointing to the next element in the array.

◆ erase() [2/2]

template<class T>
iterator Common::Array< T >::erase ( iterator  first,
iterator  last 
)
inline

Erase the elements from first to last and return an iterator pointing to the next element in the array.

◆ empty()

template<class T>
bool Common::Array< T >::empty ( ) const
inline

Check whether the array is empty.

◆ operator==()

template<class T>
bool Common::Array< T >::operator== ( const Array< T > &  other) const
inline

Check whether two arrays are identical.

◆ operator!=()

template<class T>
bool Common::Array< T >::operator!= ( const Array< T > &  other) const
inline

Check if two arrays are different.

◆ begin() [1/2]

template<class T>
iterator Common::Array< T >::begin ( )
inline

Return an iterator pointing to the first element in the array.

◆ end() [1/2]

template<class T>
iterator Common::Array< T >::end ( )
inline

Return an iterator pointing past the last element in the array.

◆ begin() [2/2]

template<class T>
const_iterator Common::Array< T >::begin ( ) const
inline

Return a const iterator pointing to the first element in the array.

◆ end() [2/2]

template<class T>
const_iterator Common::Array< T >::end ( ) const
inline

Return a const iterator pointing past the last element in the array.

◆ reserve()

template<class T>
void Common::Array< T >::reserve ( size_type  newCapacity)
inline

Reserve enough memory in the array so that it can store at least the given number of elements. The current content of the array is not modified.

◆ resize() [1/2]

template<class T>
void Common::Array< T >::resize ( size_type  newSize)
inline

Change the size of the array.

◆ resize() [2/2]

template<class T>
void Common::Array< T >::resize ( size_type  newSize,
const T  value 
)
inline

Change the size of the array and initialize new elements that exceed the current array's size with copies of value.

◆ assign()

template<class T>
void Common::Array< T >::assign ( const_iterator  first,
const_iterator  last 
)
inline

Assign to this array the elements between the given iterators from another array, from first included to last excluded.

◆ roundUpCapacity()

template<class T>
static size_type Common::Array< T >::roundUpCapacity ( size_type  capacity)
inlinestaticprotected

Round up capacity to the next power of 2. A minimal capacity of 8 is used.

◆ allocCapacity()

template<class T>
void Common::Array< T >::allocCapacity ( size_type  capacity)
inlineprotected

Allocate a specific capacity for the array.

◆ freeStorage()

template<class T>
void Common::Array< T >::freeStorage ( T *  storage,
const size_type  elements 
)
inlineprotected

Free the storage used by the array.

◆ insert_aux()

template<class T>
iterator Common::Array< T >::insert_aux ( iterator  pos,
const_iterator  first,
const_iterator  last 
)
inlineprotected

Insert a range of elements coming from this or another array. Unlike std::vector::insert, this method does not accept arbitrary iterators, mainly because our iterator system is seriously limited and does not distinguish between input iterators, output iterators, forward iterators, or random access iterators.

So, we simply restrict to Array iterators. Extending this to arbitrary random access iterators would be trivial.

Moreover, this method does not handle all cases of inserting a subrange of an array into itself; this is why it is private for now.

Member Data Documentation

◆ _capacity

template<class T>
size_type Common::Array< T >::_capacity
protected

Maximum number of elements the array can hold.

◆ _size

template<class T>
size_type Common::Array< T >::_size
protected

How many elements the array holds.

◆ _storage

template<class T>
T* Common::Array< T >::_storage
protected

Memory used for element storage.


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