Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
Array< T > Class Template Reference

#include <elm/data/Array.h>

+ Inheritance diagram for Array< T >:

Classes

class  BackIter
 
class  BackMutIter
 
class  BackPreIter
 
class  Iter
 
class  MutIter
 
class  PreIter
 

Public Types

typedef T t
 
typedef Array< T > self_t
 

Public Member Functions

 Array (void)
 
 Array (int count, T *buffer)
 
const T * buffer (void) const
 
T * buffer (void)
 
int size (void) const
 
void set (int count, T *buffer)
 
void set (const Array< T > &t)
 
void copy (const Array &t)
 
void fill (const T &val)
 
const T * operator() (void) const
 
T * operator() (void)
 
Array< T > & operator= (const Array< T > &t)
 
Iter items (void) const
 
Iter operator* (void) const
 
Iter begin (void) const
 
Iter end (void) const
 
Iterable< BackIterback () const
 
int count (void) const
 
bool contains (const T &item)
 
template<class C >
bool containsAll (const C &c)
 
bool isEmpty (void) const
 
 operator bool (void) const
 
bool equals (const Array< T > &a) const
 
bool operator== (const Array< T > &a) const
 
bool operator!= (const Array< T > &a) const
 
bool operator<= (const Array< T > &a) const
 
bool operator< (const Array< T > &a) const
 
bool operator>= (const Array< T > &a) const
 
bool operator> (const Array< T > &a) const
 
int length (void) const
 
const T & get (int idx) const
 
int indexOf (const T &v, int i=0) const
 
int lastIndexOf (const T &v, int i=-1) const
 
const T & operator[] (int idx) const
 
void set (int idx, const T &val)
 
void set (const MutIter &i, const T &val)
 
T & get (int idx)
 
T & operator[] (int idx)
 
MutIter begin (void)
 
MutIter end (void)
 
Iterable< BackMutIterback ()
 

Static Public Attributes

static const Array< T > null
 

Protected Attributes

int cnt
 
T * buf
 

Detailed Description

template<class T>
class elm::Array< T >

An array is a simple wrapper around the C array data type. It provides controlled methods to it (indexed accesses are protected with assertions) and implements the concept:: Collection concept and therefore can be used as any collection. Yet, it doesn't manage the memory of the array.

To shorten the construction of an Array, you can use the function _array().

Parameters
TType of elements stored in the array.
See also
AllocArray, _array()

Member Typedef Documentation

◆ self_t

typedef Array<T> self_t

◆ t

typedef T t

Constructor & Destructor Documentation

◆ Array() [1/2]

Array ( void  )
inline

Build an empty array.

◆ Array() [2/2]

Array ( int  count,
T *  buffer 
)
inline

Build an array using buffer as array and with size count. The Array will NOT be in charge of freeing this memory!

Parameters
countArray size.
bufferBuffer Array buffer.

Member Function Documentation

◆ back() [1/2]

Iterable<BackMutIter> back ( )
inline

References elm::subiter().

◆ back() [2/2]

Iterable<BackIter> back ( ) const
inline

References elm::subiter().

◆ begin() [1/2]

MutIter begin ( void  )
inline

◆ begin() [2/2]

Iter begin ( void  ) const
inline

References Array< T >::items().

Referenced by Array< T >::equals().

◆ buffer() [1/2]

T * buffer ( void  )
inline
Returns
Buffer of the array.

References Array< T >::buf.

◆ buffer() [2/2]

const T * buffer ( void  ) const
inline

◆ contains()

bool contains ( const T &  item)
inline

Referenced by Array< T >::containsAll().

◆ containsAll()

◆ copy()

void copy ( const Array< T > &  t)
inline

Copy the array t inside the current array. If the current array is smaller than t, only the first elements will be copied.

Parameters
tArray to copy.

References Array< T >::buf, Array< T >::cnt, elm::array::copy(), and elm::min().

Referenced by AllocArray< T >::AllocArray(), and AllocArray< T >::copy().

◆ count()

◆ end() [1/2]

MutIter end ( void  )
inline

◆ end() [2/2]

Iter end ( void  ) const
inline

◆ equals()

◆ fill()

void fill ( const T &  val)
inline

Fill the array with the gien value.

Parameters
valValue to copy in the array elements.

References Array< T >::buf, Array< T >::cnt, and elm::array::set().

Referenced by AllocArray< T >::AllocArray().

◆ get() [1/2]

T & get ( int  idx)
inline

Get a reference on an element by index. Raise an assertion failure if idx is out of array bounds.

Parameters
idxIndex of element to get.
Returns
Reference on element at index idx.

References Array< T >::buf, and Array< T >::cnt.

◆ get() [2/2]

const T & get ( int  idx) const
inline

Get an element by index. Raise an assertion failure if idx is out of array bounds.

Parameters
idxIndex of element to get.
Returns
Element at index idx.

References Array< T >::buf, and Array< T >::cnt.

Referenced by Array< T >::indexOf(), Array< T >::lastIndexOf(), and Array< T >::operator[]().

◆ indexOf()

int indexOf ( const T &  v,
int  i = 0 
) const
inline

◆ isEmpty()

bool isEmpty ( void  ) const
inline

References Array< T >::cnt.

Referenced by Array< T >::operator bool().

◆ items()

Array::Iter items ( void  ) const
inline
Returns
iterator on the items of the array.

Referenced by Array< T >::begin(), and Array< T >::operator*().

◆ lastIndexOf()

int lastIndexOf ( const T &  v,
int  i = -1 
) const
inline

◆ length()

int length ( void  ) const
inline

References Array< T >::count().

◆ operator bool()

operator bool ( void  ) const
inline

References Array< T >::isEmpty().

◆ operator!=()

bool operator!= ( const Array< T > &  a) const
inline

References Array< T >::equals().

◆ operator()() [1/2]

T * operator() ( void  )
inline

Same as buffer().

References Array< T >::buffer().

◆ operator()() [2/2]

const T * operator() ( void  ) const
inline

Same as buffer().

References Array< T >::buffer().

◆ operator*()

Array::Iter operator* ( void  ) const
inline

Same as items().

References Array< T >::items().

◆ operator<()

bool operator< ( const Array< T > &  a) const
inline

◆ operator<=()

bool operator<= ( const Array< T > &  a) const
inline

◆ operator=()

Array< T > & operator= ( const Array< T > &  t)
inline

Same as set().

References Array< T >::set().

◆ operator==()

bool operator== ( const Array< T > &  a) const
inline

References Array< T >::equals().

◆ operator>()

bool operator> ( const Array< T > &  a) const
inline

◆ operator>=()

bool operator>= ( const Array< T > &  a) const
inline

◆ operator[]() [1/2]

T & operator[] ( int  idx)
inline

Same as get().

References Array< T >::get().

◆ operator[]() [2/2]

const T & operator[] ( int  idx) const
inline

Same as get().

References Array< T >::get().

◆ set() [1/4]

void set ( const Array< T > &  t)
inline

Assign the given array t to the current array.

Parameters
tArray to assign.

References Array< T >::buf, and Array< T >::cnt.

◆ set() [2/4]

void set ( const MutIter i,
const T &  val 
)
inline

◆ set() [3/4]

void set ( int  count,
T *  buffer 
)
inline

Change the buffer of the array. The Array will NOT be in charge of freeing this buffer.

Parameters
countArray count.
bufferArray buffer.

References Array< T >::buf, Array< T >::buffer(), Array< T >::cnt, and Array< T >::count().

Referenced by AllocArray< T >::copy(), Array< T >::operator=(), and AllocArray< T >::tie().

◆ set() [4/4]

void set ( int  idx,
const T &  val 
)
inline

Set an array element according to index idx. If the index is out of bound, an assertion failure is raised.

Parameters
idxIndex of the element to assign.
valValue to assign.

References Array< T >::buf, and Array< T >::cnt.

◆ size()

int size ( void  ) const
inline

References Array< T >::count().

Member Data Documentation

◆ buf

◆ cnt

◆ null

const Array< T > null
static

Singleton representing an empty array.


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