iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nrt::DynamicArray< T, Allocator > Class Template Reference

#include <nrt/Core/Memory/DynamicArray.H>

template<class T, class Allocator = std::allocator<T>>
class nrt::DynamicArray< T, Allocator >

A dynamic-length version of the Array class.

The data held by this DynamicArray is held by a copy-on-write policy, so that assignments are extremely fast - costing essentialy a pointer assignment and integer increment. Inspecting elements is also fast, so long as it is done through a constant access method. Access through a non const method may cause a deep copy of the underlying data if there are multiple references to it. Therefore, users should strive to use the const methods whenever possible.

Template Parameters
TThe underlying type to hold
AllocatorThe allocator to use for type T

Definition at line 57 of file DynamicArray.H.

Public Types

typedef VectorType::value_type value_type
 

Public Member Functions

 DynamicArray ()
 Default empty constructor.
 
 DynamicArray (size_t size)
 Construct a DynamicArray of a specific size, filling it with the default value for T.
 
 DynamicArray (size_t size, T value)
 Construct a DynamicArray of a specific size, and fill it with a value.
 
template<class InputIt >
 DynamicArray (InputIt first, InputIt last)
 Construct a DynamicArray from some range of existing elements.
 
 DynamicArray (DynamicArray const &other)
 Copy constructor. More...
 
 DynamicArray (DynamicArray &&other)
 Move constructor. More...
 
 DynamicArray (std::initializer_list< T > vals)
 Construct from an initializer list.
 
 ~DynamicArray ()
 Destructor. More...
 
DynamicArray< T, Allocator > & operator= (DynamicArray< T, Allocator > const &other)
 Assignment operator.
 
DynamicArray< T, Allocator > & operator= (DynamicArray< T, Allocator > &&other)
 Move Assignment operator. More...
 
DynamicArray< T, Allocator > & operator+= (const DynamicArray< T, Allocator > &other)
 Concatenate another array with this one.
 
const DynamicArray< T, Allocatoroperator+ (const DynamicArray< T, Allocator > &other) const
 Concatenate two arrays together.
 
void deepCopy ()
 Performs a deep copy of the underlying data if not a unique owner.
 
template<class InputIt >
auto insert (iterator pos, InputIt first, InputIt last) -> void
 
template<class InputIt >
auto insert (const_iterator pos, InputIt first, InputIt last) -> iterator
 
template<class... Args>
auto emplace (const_iterator pos, Args &&...args) -> iterator
 
Element Access
T & operator[] (size_t index)
 Individual element access - may incur a deep copy. More...
 
T const & operator[] (size_t index) const
 Individual element access.
 
T const & at (size_t index) const
 Constant access method.
 
T & front ()
 Gets a reference to the front element - may incur a deep copy.
 
T const & front () const
 Gets a constant reference to the front element.
 
T & back ()
 Gets a reference to the back element - may incur a deep copy.
 
T const & back () const
 Gets a constant reference to the back element.
 
T * data ()
 Gets a pointer to the underlying data - may incur a deep copy.
 
T const * data () const
 Gets a pointer to the constant underlying data.
 
Capacity
bool empty () const
 Checks whether the array is empty. More...
 
size_t size () const
 Returns the current number of elements stored.
 
void reserve (size_t n)
 Requests the capacity of the underlying storage to be at least enough to store n elements.
 
size_t capacity () const
 Returns the number of elements that can be held in currently allocated storage.
 
void shrink_to_fit ()
 Shrinks memory usage by freeing unused memory.
 
Modifiers
void clear ()
 Clears all data associated with this array. More...
 
iterator insert (iterator pos, T const &data)
 Insert immediately before some iterator position.
 
iterator insert (const_iterator pos, T const &data)
 Insert immediately before some iterator position.
 
iterator insert (const_iterator pos, T &&data)
 Insert immediately before some iterator position.
 
void insert (iterator pos, size_t count, T const &data)
 Insert count copies of data immediately before some iterator position.
 
iterator insert (const_iterator pos, size_t count, T const &data)
 Insert count copies of data immediately before some iterator position.
 
template<class InputIt >
void insert (iterator pos, InputIt first, InputIt last)
 Insert all values in the iterator range before some iterator position.
 
template<class InputIt >
iterator insert (const_iterator pos, InputIt first, InputIt last)
 Insert all values in the iterator range before some iterator position.
 
iterator insert (const_iterator pos, std::initializer_list< T > ilist)
 Insert the values of some initializer list before some iterator position.
 
template<class... Args>
iterator emplace (const_iterator pos, Args &&...args)
 Inserts a new element into the container directly before pos, constructing in place.
 
iterator erase (iterator pos)
 Remove an element at a position.
 
iterator erase (const_iterator pos)
 Remove an element at a position.
 
iterator erase (iterator first, iterator last)
 Remove a range of elements.
 
iterator erase (const_iterator first, const_iterator last)
 Remove a range of elements.
 
void push_back (T const &data)
 Adds a new element to the back of the array.
 
void push_back (T &&data)
 Adds a new element to the back of the array.
 
template<class... Args>
void emplace_back (Args &&...args)
 Construct a new element in place at the back of the array.
 
void pop_back ()
 Removes the tail element in the array.
 
void remove (size_t index)
 Removes the item at the selected index (O(n) operation) More...
 
void quickRemove (size_t index)
 Remoes the item at the selected index (O(1), does not guarantee preserving ordering )
 
void resize (size_t n)
 Resizes the underlying storage to be exactly n elements, dropping anything > n.
 

Friends

class cereal::access
 

Iterators

typedef VectorType::iterator iterator
 The type for an iterator. More...
 
typedef VectorType::const_iterator const_iterator
 The type for a constant iterator.
 
typedef
VectorType::reverse_iterator 
reverse_iterator
 The type for a reverse iterator.
 
typedef
VectorType::const_reverse_iterator 
const_reverse_iterator
 The type for a constant reverse iterator.
 
iterator begin ()
 Gets an iterator to the beginning of data - may incur a deep copy.
 
const_iterator begin () const
 Gets a constant iterator to the beginning of data.
 
const_iterator const_begin () const
 Gets a constant iterator to the beginning of data.
 
iterator end ()
 Gets an iterator to the end of data - may incur a deep copy.
 
const_iterator end () const
 Gets a constant iterator to the end of data.
 
const_iterator const_end () const
 Gets a constant iterator to the end of data.
 
reverse_iterator rbegin ()
 Get a reverse iterator to the beginning.
 
const_reverse_iterator rbegin () const
 Get a reverse iterator to the beginning.
 
const_reverse_iterator const_rbegin () const
 Get a reverse iterator to the beginning.
 
reverse_iterator rend ()
 Get a reverse iterator to the end.
 
const_reverse_iterator rend () const
 Get a reverse iterator to the end.
 
const_reverse_iterator const_rend () const
 Get a reverse iterator to the end.
 

Member Typedef Documentation

template<class T, class Allocator = std::allocator<T>>
typedef VectorType::iterator nrt::DynamicArray< T, Allocator >::iterator

The type for an iterator.

Provides iterator level access to elements

Definition at line 142 of file DynamicArray.H.

Constructor & Destructor Documentation

template<class T, class Allocator >
nrt::DynamicArray< T, Allocator >::DynamicArray ( DynamicArray< T, Allocator > const &  other)
inline

Copy constructor.

This constructor performs a shallow copy, meaning that no deep-copy is performed and instead we simply increment reference counts

Definition at line 86 of file DynamicArrayImpl.H.

template<class T, class Allocator >
nrt::DynamicArray< T, Allocator >::DynamicArray ( DynamicArray< T, Allocator > &&  other)
inline

Move constructor.

Constructs a new DynamicArray, invalidating the older DynamicArray. The other array used to construct this should no longer be used; using it will result in undefined behavior.

Definition at line 91 of file DynamicArrayImpl.H.

template<class T , class Allocator >
nrt::DynamicArray< T, Allocator >::~DynamicArray ( )
inline

Destructor.

Decrements ref count and deletes data if we are the only owner

Definition at line 82 of file DynamicArrayImpl.H.

Member Function Documentation

template<class T, class Allocator = std::allocator<T>>
DynamicArray<T, Allocator>& nrt::DynamicArray< T, Allocator >::operator= ( DynamicArray< T, Allocator > &&  other)

Move Assignment operator.

The array move assigned to this one will become invalid after this operation; any use of an invalid array will result in undefined behavior

template<class T , class Allocator >
T & nrt::DynamicArray< T, Allocator >::operator[] ( size_t  index)
inline

Individual element access - may incur a deep copy.

Functions providing access to individual elements. Non const access will incur a deep copy if not the sole owner of the data.

Definition at line 115 of file DynamicArrayImpl.H.

template<class T , class Allocator >
bool nrt::DynamicArray< T, Allocator >::empty ( ) const
inline

Checks whether the array is empty.

Functionality for querying and adjusting capacity

Definition at line 257 of file DynamicArrayImpl.H.

template<class T , class Allocator >
void nrt::DynamicArray< T, Allocator >::clear ( )
inline

Clears all data associated with this array.

Functionality for modifying the data inside of the array

Definition at line 291 of file DynamicArrayImpl.H.

template<class T , class Allocator >
void nrt::DynamicArray< T, Allocator >::remove ( size_t  index)
inline

Removes the item at the selected index (O(n) operation)

Deprecated:
  • use erase instead

Definition at line 431 of file DynamicArrayImpl.H.


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