Base Framework
Classes | Public Types | Public Member Functions | Related Functions | List of all members
Array< TYPE > Class Template Reference

Array collection. More...

#include <base/collection/Array.h>

Inherits Collection.

Classes

class  Element
 

Public Types

typedef TYPE Value
 
typedef Allocator< TYPE >::Iterator Iterator
 
typedef Allocator< TYPE >::ReadIterator ReadIterator
 
typedef Allocator< TYPE >::Enumerator Enumerator
 
typedef Allocator< TYPE >::ReadEnumerator ReadEnumerator
 

Public Member Functions

void setSize (MemorySize size)
 
void setSize (MemorySize size, const TYPE &value)
 
void ensureCapacity (MemorySize capacity)
 
MemorySize getCapacity () const noexcept
 
ValuegetElements ()
 
const ValuegetElements () const noexcept
 
 Array ()
 
 Array (MemorySize size)
 
 Array (MemorySize size, const Value &value)
 
 Array (std::initializer_list< Value > l)
 
 Array (const Array &copy) noexcept
 
 Array (Array &&move) noexcept
 
Arrayoperator= (const Array &copy) noexcept
 
Arrayoperator= (Array &&move) noexcept
 
MemorySize getSize () const noexcept
 
bool isEmpty () const noexcept
 
TYPE * getFirstReference () noexcept
 
const TYPE * getFirstReference () const noexcept
 
TYPE & getFirst ()
 
const TYPE & getFirst () const
 
TYPE & getLast ()
 
const TYPE & getLast () const
 
Iterator getBeginIterator () noexcept
 
Iterator getEndIterator () noexcept
 
ReadIterator getBeginReadIterator () const noexcept
 
ReadIterator getEndReadIterator () const noexcept
 
ReadIterator begin () const noexcept
 
ReadIterator end () const noexcept
 
ReadIterator cbegin () const noexcept
 
ReadIterator cend () const noexcept
 
Iterator begin () noexcept
 
Iterator end () noexcept
 
 operator RandomAccessIterable< Iterator > () noexcept
 
Enumerator getEnumerator () noexcept
 
ReadEnumerator getReadEnumerator () const noexcept
 
void append (const Value &value)
 
void append (Value &&value)
 
void append (std::initializer_list< Value > l)
 
void prepend (const Value &value)
 
void prepend (Value &&value)
 
void prepend (std::initializer_list< Value > l)
 
void insert (MemorySize index, const Value &value)
 
void insert (MemorySize index, Value &&value)
 
void insert (const Iterator &it, const Value &value)
 
void insert (const Iterator &it, Value &&value)
 
void remove (MemorySize index)
 
void remove (const Iterator &it)
 
void remove (MemorySize _begin, MemorySize _end)
 
void remove (const Iterator &_begin, const Iterator &_end)
 
void removeAll ()
 
Array slice (MemorySize _begin, MemorySize _end) const
 
Array slice (const Iterator &_begin, const Iterator &_end) const
 
ValuegetAt (MemorySize index)
 
const ValuegetAt (MemorySize index) const
 
void setAt (MemorySize index, const Value &value)
 
void setAt (MemorySize index, Value &&value)
 
TYPE & operator[] (MemorySize index)
 
const Valueoperator[] (MemorySize index) const
 
bool operator== (const Array &compare) const
 
bool operator!= (const Array &compare) const
 
bool operator< (const Array &compare) const
 
bool operator>= (const Array &compare) const
 
 operator bool () const noexcept
 
void shuffle ()
 
MemoryDiff indexOf (const TYPE &value) const
 
MemoryDiff lastIndexOf (const TYPE &value) const
 
const TYPE * find (const TYPE &value) const
 
void sort ()
 
template<class PREDICATE >
void sort (PREDICATE predicate)
 
Array head (MemorySize n) const
 
Array tail (MemorySize n) const
 
Arrayoperator<< (const TYPE &value)
 
Arrayoperator<< (TYPE &&value)
 

Related Functions

(Note that these are not member functions.)

template<class TYPE >
FormatOutputStreamoperator<< (FormatOutputStream &stream, const Array< TYPE > &value)
 

Detailed Description

template<class TYPE>
class Array< TYPE >

Array collection.

The Array collection is a container for an ordered sequence of elements which provides random access to the individual elements. Elements must have a default constructor.

Version
1.0
Examples
testsuite/Array.cpp, testsuite/digest.cpp, testsuite/du.cpp, testsuite/echod.cpp, testsuite/eval.cpp, testsuite/IEEE1394.cpp, testsuite/ls.cpp, testsuite/ping.cpp, testsuite/rm.cpp, and testsuite/sax.cpp.

Member Typedef Documentation

◆ Value

template<class TYPE >
typedef TYPE Array< TYPE >::Value

The type of the values.

Constructor & Destructor Documentation

◆ Array() [1/6]

template<class TYPE >
Array< TYPE >::Array ( )
inline

Initializes an empty array.

◆ Array() [2/6]

template<class TYPE >
Array< TYPE >::Array ( MemorySize  size)
inlineexplicit

Initializes an array with the specified size.

Parameters
sizeThe size of the array.

◆ Array() [3/6]

template<class TYPE >
Array< TYPE >::Array ( MemorySize  size,
const Value value 
)
inline

Initializes array with the specified number of elements.

Parameters
sizeThe initial number of elements in the array.
valueThe value used to initialize the elements.

◆ Array() [4/6]

template<class TYPE >
Array< TYPE >::Array ( std::initializer_list< Value l)
inline

Initializes array from initializer list.

◆ Array() [5/6]

template<class TYPE >
Array< TYPE >::Array ( const Array< TYPE > &  copy)
inlinenoexcept

Initializes array from other array.

◆ Array() [6/6]

template<class TYPE >
Array< TYPE >::Array ( Array< TYPE > &&  move)
inlinenoexcept

Initializes array from other array.

Member Function Documentation

◆ append() [1/3]

template<class TYPE >
void Array< TYPE >::append ( const Value value)
inline

Appends the value to this array.

Parameters
valueThe value to be appended.

◆ append() [2/3]

template<class TYPE >
void Array< TYPE >::append ( std::initializer_list< Value l)
inline

Append from initializer list.

◆ append() [3/3]

template<class TYPE >
void Array< TYPE >::append ( Value &&  value)
inline

Appends the value to this array.

Parameters
valueThe value to be appended.

◆ begin() [1/2]

template<class TYPE >
ReadIterator Array< TYPE >::begin ( ) const
inlinenoexcept

Returns the first element of the allocator as a non-modifying array.

◆ begin() [2/2]

template<class TYPE >
Iterator Array< TYPE >::begin ( )
inlinenoexcept

Returns the first element of the allocator as a modifying array.

◆ cbegin()

template<class TYPE >
ReadIterator Array< TYPE >::cbegin ( ) const
inlinenoexcept

Returns the first element of the allocator as a non-modifying array.

◆ cend()

template<class TYPE >
ReadIterator Array< TYPE >::cend ( ) const
inlinenoexcept

Returns the end of the allocator as a non-modifying array.

◆ end() [1/2]

template<class TYPE >
ReadIterator Array< TYPE >::end ( ) const
inlinenoexcept

Returns the end of the allocator as a non-modifying array.

◆ end() [2/2]

template<class TYPE >
Iterator Array< TYPE >::end ( )
inlinenoexcept

Returns the end of the allocator as a modifying array.

◆ ensureCapacity()

template<class TYPE >
void Array< TYPE >::ensureCapacity ( MemorySize  capacity)
inline

Ensure capacity.

◆ find()

template<class TYPE >
const TYPE* Array< TYPE >::find ( const TYPE &  value) const
inline

Returns reference to the item if found by the given value.

◆ getAt() [1/2]

template<class TYPE >
Value& Array< TYPE >::getAt ( MemorySize  index)
inline

Returns the element at the specified index. Raises OutOfRange if the index is invalid.

Parameters
indexThe index of the element.

◆ getAt() [2/2]

template<class TYPE >
const Value& Array< TYPE >::getAt ( MemorySize  index) const
inline

Returns the element at the specified index. Raises OutOfRange if the index is invalid.

Parameters
indexThe index of the element.

◆ getBeginIterator()

template<class TYPE >
Iterator Array< TYPE >::getBeginIterator ( )
inlinenoexcept

Returns the first element of the allocator as a modifying array.

◆ getBeginReadIterator()

template<class TYPE >
ReadIterator Array< TYPE >::getBeginReadIterator ( ) const
inlinenoexcept

Returns the first element of the allocator as a non-modifying array.

◆ getCapacity()

template<class TYPE >
MemorySize Array< TYPE >::getCapacity ( ) const
inlinenoexcept

Returns the capacity.

◆ getElements() [1/2]

template<class TYPE >
Value* Array< TYPE >::getElements ( )
inline

Returns the elements of the array for modifying access.

◆ getElements() [2/2]

template<class TYPE >
const Value* Array< TYPE >::getElements ( ) const
inlinenoexcept

Returns the elements of the array for non-modifying access.

◆ getEndIterator()

template<class TYPE >
Iterator Array< TYPE >::getEndIterator ( )
inlinenoexcept

Returns the end of the allocator as a modifying array.

◆ getEndReadIterator()

template<class TYPE >
ReadIterator Array< TYPE >::getEndReadIterator ( ) const
inlinenoexcept

Returns the end of the allocator as a non-modifying array.

◆ getEnumerator()

template<class TYPE >
Enumerator Array< TYPE >::getEnumerator ( )
inlinenoexcept

Returns a modifying enumerator of the array.

◆ getFirst() [1/2]

template<class TYPE >
TYPE& Array< TYPE >::getFirst ( )
inline

Returns the first element.

◆ getFirst() [2/2]

template<class TYPE >
const TYPE& Array< TYPE >::getFirst ( ) const
inline

Returns the first element.

◆ getFirstReference() [1/2]

template<class TYPE >
const TYPE* Array< TYPE >::getFirstReference ( ) const
inlinenoexcept

Returns the pointer to the first item or nullptr if empty.

◆ getFirstReference() [2/2]

template<class TYPE >
TYPE* Array< TYPE >::getFirstReference ( )
inlinenoexcept

Returns the pointer to the first item or nullptr if empty.

◆ getLast() [1/2]

template<class TYPE >
TYPE& Array< TYPE >::getLast ( )
inline

Returns the last element.

◆ getLast() [2/2]

template<class TYPE >
const TYPE& Array< TYPE >::getLast ( ) const
inline

Returns the last element.

◆ getReadEnumerator()

template<class TYPE >
ReadEnumerator Array< TYPE >::getReadEnumerator ( ) const
inlinenoexcept

Returns a non-modifying enumerator of the array.

Examples
testsuite/sax.cpp.

◆ getSize()

template<class TYPE >
MemorySize Array< TYPE >::getSize ( ) const
inlinenoexcept

Returns the number fo elements in the array.

◆ head()

template<class TYPE >
Array Array< TYPE >::head ( MemorySize  n) const
inline

Returns the first n items.

◆ indexOf()

template<class TYPE >
MemoryDiff Array< TYPE >::indexOf ( const TYPE &  value) const
inline

Returns the index of the first found value. Returns -1 if not found.

◆ insert() [1/4]

template<class TYPE >
void Array< TYPE >::insert ( const Iterator it,
const Value value 
)
inline

Inserts values at the given position.

◆ insert() [2/4]

template<class TYPE >
void Array< TYPE >::insert ( const Iterator it,
Value &&  value 
)
inline

Inserts values at the given position.

◆ insert() [3/4]

template<class TYPE >
void Array< TYPE >::insert ( MemorySize  index,
const Value value 
)
inline

Inserts the value at the specified position. Raises OutOfRange if the specified index is invalid.

Parameters
indexSpecifies the insert position.
valueThe value to be inserted.

◆ insert() [4/4]

template<class TYPE >
void Array< TYPE >::insert ( MemorySize  index,
Value &&  value 
)
inline

Inserts the value at the specified position. Raises OutOfRange if the specified index is invalid.

Parameters
indexSpecifies the insert position.
valueThe value to be inserted.

◆ isEmpty()

template<class TYPE >
bool Array< TYPE >::isEmpty ( ) const
inlinenoexcept

Returns true if the array is empty.

◆ lastIndexOf()

template<class TYPE >
MemoryDiff Array< TYPE >::lastIndexOf ( const TYPE &  value) const
inline

Returns the index of the last found value. Returns -1 if not found.

◆ operator bool()

template<class TYPE >
Array< TYPE >::operator bool ( ) const
inlinenoexcept

Returns true if not empty.

◆ operator RandomAccessIterable< Iterator >()

template<class TYPE >
Array< TYPE >::operator RandomAccessIterable< Iterator > ( )
inlinenoexcept

Returns random access iterators.

◆ operator!=()

template<class TYPE >
bool Array< TYPE >::operator!= ( const Array< TYPE > &  compare) const
inline

Returns true if not equal.

◆ operator<()

template<class TYPE >
bool Array< TYPE >::operator< ( const Array< TYPE > &  compare) const
inline

Returns true if less than.

◆ operator<<() [1/2]

template<class TYPE >
Array& Array< TYPE >::operator<< ( const TYPE &  value)
inline

Appends value.

◆ operator<<() [2/2]

template<class TYPE >
Array& Array< TYPE >::operator<< ( TYPE &&  value)
inline

Appends value.

◆ operator=() [1/2]

template<class TYPE >
Array& Array< TYPE >::operator= ( Array< TYPE > &&  move)
inlinenoexcept

Assignment of array to array.

◆ operator=() [2/2]

template<class TYPE >
Array& Array< TYPE >::operator= ( const Array< TYPE > &  copy)
inlinenoexcept

Assignment of array to array.

◆ operator==()

template<class TYPE >
bool Array< TYPE >::operator== ( const Array< TYPE > &  compare) const
inline

Returns true if equal.

◆ operator>=()

template<class TYPE >
bool Array< TYPE >::operator>= ( const Array< TYPE > &  compare) const
inline

Returns true if greater than or equal.

◆ operator[]() [1/2]

template<class TYPE >
TYPE& Array< TYPE >::operator[] ( MemorySize  index)
inline

Returns a reference to the element at the specified index. Raises OutOfRange if the index is invalid.

Parameters
indexThe index of the element.

◆ operator[]() [2/2]

template<class TYPE >
const Value& Array< TYPE >::operator[] ( MemorySize  index) const
inline

Returns the element at the specified index. Raises OutOfRange if the index is invalid.

Parameters
indexThe index of the element.

◆ prepend() [1/3]

template<class TYPE >
void Array< TYPE >::prepend ( const Value value)
inline

Prepends the value to this array.

Parameters
valueThe value to be prepended.

◆ prepend() [2/3]

template<class TYPE >
void Array< TYPE >::prepend ( std::initializer_list< Value l)
inline

Prepends from initializer list.

◆ prepend() [3/3]

template<class TYPE >
void Array< TYPE >::prepend ( Value &&  value)
inline

Prepends the value to this array.

Parameters
valueThe value to be prepended.

◆ remove() [1/4]

template<class TYPE >
void Array< TYPE >::remove ( const Iterator _begin,
const Iterator _end 
)
inline

Removes the elements within the given positions.

◆ remove() [2/4]

template<class TYPE >
void Array< TYPE >::remove ( const Iterator it)
inline

Removes the element at the given position.

◆ remove() [3/4]

template<class TYPE >
void Array< TYPE >::remove ( MemorySize  _begin,
MemorySize  _end 
)
inline

Removes the elements within the given positions.

◆ remove() [4/4]

template<class TYPE >
void Array< TYPE >::remove ( MemorySize  index)
inline

Remove the element specified by the index. Raises OutOfRange if the index is invalid.

Parameters
indexThe index of the element to be removed.

◆ removeAll()

template<class TYPE >
void Array< TYPE >::removeAll ( )
inline

Removes all the elements from this array.

◆ setAt() [1/2]

template<class TYPE >
void Array< TYPE >::setAt ( MemorySize  index,
const Value value 
)
inline

Sets the element at the specified index. Raises OutOfRange if the index is invalid.

Parameters
indexThe index of the element.
valueThe desired value.

◆ setAt() [2/2]

template<class TYPE >
void Array< TYPE >::setAt ( MemorySize  index,
Value &&  value 
)
inline

Sets the element at the specified index. Raises OutOfRange if the index is invalid.

Parameters
indexThe index of the element.
valueThe desired value.

◆ setSize() [1/2]

template<class TYPE >
void Array< TYPE >::setSize ( MemorySize  size)
inline

Sets the size of the array.

◆ setSize() [2/2]

template<class TYPE >
void Array< TYPE >::setSize ( MemorySize  size,
const TYPE &  value 
)
inline

Sets the size of the array by filling with the given value.

◆ shuffle()

template<class TYPE >
void Array< TYPE >::shuffle ( )
inline

Shuffles the elements.

◆ slice() [1/2]

template<class TYPE >
Array Array< TYPE >::slice ( const Iterator _begin,
const Iterator _end 
) const
inline

Returns a new Array for the given elements.

◆ slice() [2/2]

template<class TYPE >
Array Array< TYPE >::slice ( MemorySize  _begin,
MemorySize  _end 
) const
inline

Returns a new Array for the given elements.

◆ sort() [1/2]

template<class TYPE >
void Array< TYPE >::sort ( )
inline

Sorts the array.

◆ sort() [2/2]

template<class TYPE >
template<class PREDICATE >
void Array< TYPE >::sort ( PREDICATE  predicate)
inline

Sorts the array.

◆ tail()

template<class TYPE >
Array Array< TYPE >::tail ( MemorySize  n) const
inline

Returns the last n items.

Friends And Related Function Documentation

◆ operator<<()

template<class TYPE >
FormatOutputStream & operator<< ( FormatOutputStream stream,
const Array< TYPE > &  value 
)
related

Writes a string representation of an array to a format stream.