ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

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

Collaboration diagram for Common::Array< T >:

List of all members.

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.
 Array (size_type count, const T &value)
 Constructs an array with `count` copies of elements with value `value`.
 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.
 ~Array ()
void push_back (const T &element)
 Appends element to the end of the array.
void push_back (const Array< T > &array)
void pop_back ()
 Removes the last element of the array.
const T * data () const
 Returns a pointer to the underlying memory serving as element storage.
T * data ()
 Returns a pointer to the underlying memory serving as element storage.
T & front ()
 Returns a reference to the first element of the array.
const T & front () const
 Returns a reference to the first element of the array.
T & back ()
 Returns a reference to the last element of the array.
const T & back () const
 Returns a reference to the last element of the array.
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.
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.

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

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

Definition at line 48 of file array.h.

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

Reimplemented in Common::SortedArray< T >.

Definition at line 47 of file array.h.

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

Reimplemented in Common::SortedArray< T >.

Definition at line 52 of file array.h.

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

Definition at line 50 of file array.h.


Constructor & Destructor Documentation

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

Definition at line 60 of file array.h.

template<class T>
Common::Array< T >::Array ( size_type  count  )  [inline, explicit]

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

No copies are made.

Definition at line 66 of file array.h.

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.

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

Definition at line 80 of file array.h.

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.

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

Definition at line 97 of file array.h.


Member Function Documentation

template<class T>
void Common::Array< T >::allocCapacity ( size_type  capacity  )  [inline, protected]

Definition at line 306 of file array.h.

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

Definition at line 289 of file array.h.

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.

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.

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

Definition at line 252 of file array.h.

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

Definition at line 260 of file array.h.

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

Definition at line 217 of file array.h.

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.

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.

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

Definition at line 232 of file array.h.

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

Definition at line 256 of file array.h.

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

Definition at line 264 of file array.h.

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

Definition at line 224 of file array.h.

template<class T>
void Common::Array< T >::freeStorage ( T *  storage,
const size_type  elements 
) [inline, protected]

Definition at line 317 of file array.h.

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.

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.

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

Inserts element before pos.

Reimplemented in Common::SortedArray< T >.

Definition at line 175 of file array.h.

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

Reimplemented in Common::SortedArray< T >.

Definition at line 162 of file array.h.

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

Reimplemented in Common::SortedArray< T >.

Definition at line 167 of file array.h.

template<class T>
iterator Common::Array< T >::insert_aux ( iterator  pos,
const_iterator  first,
const_iterator  last 
) [inline, protected]

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.

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

Definition at line 248 of file array.h.

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

Definition at line 201 of file array.h.

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

Definition at line 236 of file array.h.

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

Reimplemented in Common::SortedArray< T >.

Definition at line 191 of file array.h.

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

Definition at line 196 of file array.h.

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.

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

Appends element to the end of the array.

Reimplemented in Common::SortedArray< T >.

Definition at line 104 of file array.h.

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

Reimplemented in Common::SortedArray< T >.

Definition at line 111 of file array.h.

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

Definition at line 179 of file array.h.

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

Definition at line 268 of file array.h.

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

Definition at line 282 of file array.h.

template<class T>
static size_type Common::Array< T >::roundUpCapacity ( size_type  capacity  )  [inline, static, protected]

Definition at line 297 of file array.h.

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

Definition at line 213 of file array.h.


Member Data Documentation

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

Definition at line 55 of file array.h.

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

Definition at line 56 of file array.h.

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:


Generated on Sat Mar 23 2019 05:06:53 for ResidualVM by doxygen 1.7.1
curved edge   curved edge