Logo Search packages:      
Sourcecode: scummvm version File versions  Download package

Common::Array< T > Class Template Reference

#include <array.h>

Inheritance diagram for Common::Array< T >:


List of all members.

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. The most important one is that std::vector has a far more sophisticated (and complicated) memory management scheme. There, only elements that 'live' are actually constructed (i.e., have their constructor called), and objects that are removed are immediately destructed (have their destructor called). With Common::Array, this is not the case; instead, it simply uses new[] and delete[] to allocate whole blocks of objects, possibly more than are currently 'alive'. This simplifies memory management, but may have undesirable side effects when one wants to use an Array of complex data types.

Improve the storage management of this class. In particular, don't use new[] and delete[], but rather construct/destruct objects manually. This way, we can ensure that storage which is not currently used does not correspond to a live active object. (This is only of interest for array of non-POD objects).

Definition at line 61 of file array.h.

Public Types

typedef const T * const_iterator
typedef T * iterator
typedef T value_type

Public Member Functions

template<class T2>
 Array (const T2 *data, int n)
 Array (const Array< T > &array)
const T & back () const
T & back ()
const_iterator begin () const
iterator begin ()
void clear ()
bool empty () const
const_iterator end () const
iterator end ()
const T & front () const
T & front ()
void insert_at (int idx, const T &element)
Array< T > & operator= (const Array< T > &array)
const T & operator[] (int idx) const
T & operator[] (int idx)
void pop_back ()
void push_back (const Array< T > &array)
void push_back (const T &element)
remove_at (int idx)
void reserve (uint newCapacity)
void resize (uint newSize)
uint size () const

Protected Member Functions

iterator insert_aux (iterator pos, const_iterator first, const_iterator last)

Static Protected Member Functions

static uint roundUpCapacity (uint capacity)

Protected Attributes

uint _capacity
uint _size
T * _storage

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

Generated by  Doxygen 1.6.0   Back to index