ScummVM
Common::Array< T > Class Template Reference

This class implements a dynamically sized container, which can be accessed similar to a regular C++ array. More...

#include <array.h>

Inherited by Common::SortedArray< T >, Glk::Array< T >, Glk::Quest::Set< T >, Pink::Array< T >, and Sci::PlaneList.

Collaboration diagram for Common::Array< T >:

Public Types

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

Public Member Functions

 Array ()
 
 Array (size_type count)
 Constructs an array with count default-inserted instances of T. More...
 
 Array (size_type count, const T &value)
 Constructs an array with count copies of elements with value value. More...
 
 Array (const Array< T > &array)
 
template<class T2 >
 Array (const T2 *array, size_type n)
 Construct an array by copying data from a regular array. More...
 
 ~Array ()
 
void push_back (const T &element)
 Appends element to the end of the array. More...
 
void push_back (const Array< T > &array)
 
void pop_back ()
 Removes the last element of the array. More...
 
const T * data () const
 Returns a pointer to the underlying memory serving as element storage. More...
 
T * data ()
 Returns a pointer to the underlying memory serving as element storage. More...
 
T & front ()
 Returns a reference to the first element of the array. More...
 
const T & front () const
 Returns a reference to the first element of the array. More...
 
T & back ()
 Returns a reference to the last element of the array. More...
 
const T & back () const
 Returns a reference to the last element of the array. More...
 
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)
 Inserts element before pos. More...
 
remove_at (size_type idx)
 
T & operator[] (size_type idx)
 
const T & operator[] (size_type idx) const
 
Array< T > & operator= (const Array< T > &array)
 
size_type size () const
 
void clear ()
 
iterator erase (iterator pos)
 
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 assign (const_iterator first, const_iterator last)
 

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)
 Insert a range of elements coming from this or another array. More...
 

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 similar to a regular C++ array.

Accessing elements is performed in constant time (like with plain arrays). In addition, one can append, insert and remove entries (this is the 'dynamic' part). Doing that in general 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.

Definition at line 45 of file array.h.

Member Typedef Documentation

◆ const_iterator

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

Definition at line 48 of file array.h.

◆ iterator

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

Definition at line 47 of file array.h.

◆ size_type

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

Definition at line 52 of file array.h.

◆ value_type

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

Definition at line 50 of file array.h.

Constructor & Destructor Documentation

◆ Array() [1/5]

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

Definition at line 60 of file array.h.

◆ Array() [2/5]

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

Constructs an array with count default-inserted instances of T.

No copies are made.

Definition at line 66 of file array.h.

◆ Array() [3/5]

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

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

Definition at line 75 of file array.h.

◆ Array() [4/5]

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

Definition at line 80 of file array.h.

◆ Array() [5/5]

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.

Definition at line 91 of file array.h.

◆ ~Array()

template<class T>
Common::Array< T >::~Array ( )
inline

Definition at line 97 of file array.h.

Member Function Documentation

◆ allocCapacity()

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

Definition at line 306 of file array.h.

◆ assign()

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

Definition at line 289 of file array.h.

◆ back() [1/2]

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

Returns a reference to the last element of the array.

Definition at line 150 of file array.h.

◆ back() [2/2]

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

Returns a reference to the last element of the array.

Definition at line 156 of file array.h.

◆ begin() [1/2]

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

Definition at line 252 of file array.h.

◆ begin() [2/2]

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

Definition at line 260 of file array.h.

◆ clear()

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

Definition at line 217 of file array.h.

◆ data() [1/2]

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

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

Definition at line 128 of file array.h.

◆ data() [2/2]

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

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

Definition at line 133 of file array.h.

◆ empty()

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

Definition at line 232 of file array.h.

◆ end() [1/2]

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

Definition at line 256 of file array.h.

◆ end() [2/2]

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

Definition at line 264 of file array.h.

◆ erase()

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

Definition at line 224 of file array.h.

◆ freeStorage()

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

Definition at line 317 of file array.h.

◆ front() [1/2]

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

Returns a reference to the first element of the array.

Definition at line 138 of file array.h.

◆ front() [2/2]

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

Returns a reference to the first element of the array.

Definition at line 144 of file array.h.

◆ insert()

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

Inserts element before pos.

Definition at line 175 of file array.h.

◆ insert_at() [1/2]

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

Definition at line 162 of file array.h.

◆ insert_at() [2/2]

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

Definition at line 167 of file array.h.

◆ 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.

Definition at line 336 of file array.h.

◆ operator!=()

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

Definition at line 248 of file array.h.

◆ operator=()

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

Definition at line 201 of file array.h.

◆ operator==()

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

Definition at line 236 of file array.h.

◆ operator[]() [1/2]

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

Definition at line 191 of file array.h.

◆ operator[]() [2/2]

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

Definition at line 196 of file array.h.

◆ pop_back()

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

Removes the last element of the array.

Definition at line 120 of file array.h.

◆ push_back() [1/2]

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

Appends element to the end of the array.

Definition at line 104 of file array.h.

◆ push_back() [2/2]

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

Definition at line 111 of file array.h.

◆ remove_at()

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

Definition at line 179 of file array.h.

◆ reserve()

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

Definition at line 268 of file array.h.

◆ resize()

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

Definition at line 282 of file array.h.

◆ roundUpCapacity()

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

Definition at line 297 of file array.h.

◆ size()

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

Definition at line 213 of file array.h.

Member Data Documentation

◆ _capacity

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

Definition at line 55 of file array.h.

◆ _size

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

Definition at line 56 of file array.h.

◆ _storage

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

Definition at line 57 of file array.h.


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