|
MetroCollect
2.3.4
|
A circular array container. More...
#include <CircularArray.h>
Public Types | |
| using | ValueType = T |
| Type of stored elements in the container. More... | |
Public Member Functions | |
| CircularArray () | |
| Construct a new Circular Array object. More... | |
| CircularArray (size_t n) | |
| Construct a new Circular Array object. More... | |
| CircularArray (size_t n, const T &value) | |
| Construct a new Circular Array object. More... | |
| size_t | capacity () const noexcept |
| Returns the number of elements that can be held in currently allocated storage. More... | |
| size_t | size () const noexcept |
| Returns the number of elements currently used in the container. More... | |
| T & | at (ptrdiff_t index) |
| Access specified element. More... | |
| const T & | at (ptrdiff_t index) const |
| Access specified element. More... | |
| T & | operator[] (ptrdiff_t index) |
| Access specified element. More... | |
| const T & | operator[] (ptrdiff_t index) const |
| Access specified element. More... | |
| size_t | absoluteIndex (ptrdiff_t index) const noexcept |
| Returns the corresponding index in the underlying storage. More... | |
| T & | atAbsoluteIndex (size_t index) |
| Access specified element in underlying storage. More... | |
| const T & | atAbsoluteIndex (size_t index) const |
| Access specified element in underlying storage. More... | |
| bool | absoluteIndexIsInBounds (size_t index) const noexcept |
| Checks wether absolute index is in the currently used circular range. More... | |
| T & | front () |
| Access the first element. More... | |
| const T & | front () const |
| Access the first element. More... | |
| T & | back () |
| Access the last element. More... | |
| const T & | back () const |
| Access the last element. More... | |
| void | moveBegin (ptrdiff_t indexes) noexcept |
| Moves the beginning of the circular array. More... | |
| void | moveEnd (ptrdiff_t indexes) noexcept |
| Moves the end of the circular array. More... | |
| void | reset () noexcept |
| Resets beginning and end indexes. More... | |
| void | reset (size_t capacity) noexcept |
| Resets beginning and end indexes and resizes the container. More... | |
| void | reset (size_t capacity, const T &value) noexcept |
| Resets beginning and end indexes and resizes the container. More... | |
| void | reset (const T &value) noexcept |
| Resets beginning and end indexes and the container's elements. More... | |
Protected Attributes | |
| std::vector< T > | data_ |
| Underlying data storage. More... | |
| size_t | capacity_ |
| Number of elements that can be held in currently allocated storage. More... | |
| size_t | begin_ |
| First index in internal storage. More... | |
| size_t | size_ |
| Number of elements currently stored. More... | |
A circular array container.
A circular array is a container which maintains a range of active elements. The active range is defined by a starting index in the underlying container and a size. It may grow or shrink from both ends and users can access its elements. However, the active range size is limited by the underlying container capacity, in case of overflow elements at the beginning are replaced by elemnts added at the end.
For a more thorough overview of circular buffers, refer to boost::circular_buffer's documentation.
In this implementation, elements may be accessed from the beginning of the active range in the usual way, but also from the beginning of the underlying container to maintain a consistent access.
| T | Type of stored elements in the container |
Definition at line 42 of file CircularArray.h.
| using CircularArray::CircularArray< T >::ValueType = T |
Type of stored elements in the container.
Definition at line 50 of file CircularArray.h.
| CircularArray::CircularArray< T >::CircularArray | ( | ) |
Construct a new Circular Array object.
Definition at line 31 of file CircularArray.cc.
| CircularArray::CircularArray< T >::CircularArray | ( | size_t | n | ) |
Construct a new Circular Array object.
| n | size of the container |
Definition at line 34 of file CircularArray.cc.
| CircularArray::CircularArray< T >::CircularArray | ( | size_t | n, |
| const T & | value | ||
| ) |
Construct a new Circular Array object.
| n | size of the container |
| value | value to initialize each element with |
Definition at line 37 of file CircularArray.cc.
|
noexcept |
Returns the corresponding index in the underlying storage.
| index | position of the element |
Definition at line 73 of file CircularArray.cc.
|
noexcept |
Checks wether absolute index is in the currently used circular range.
| index | absolute index position to check |
Definition at line 88 of file CircularArray.cc.
| T & CircularArray::CircularArray< T >::at | ( | ptrdiff_t | index | ) |
Access specified element.
| index | position of the element to return |
Definition at line 52 of file CircularArray.cc.

| const T & CircularArray::CircularArray< T >::at | ( | ptrdiff_t | index | ) | const |
Access specified element.
| index | position of the element to return |
Definition at line 57 of file CircularArray.cc.
| T & CircularArray::CircularArray< T >::atAbsoluteIndex | ( | size_t | index | ) |
Access specified element in underlying storage.
| index | absolute index position of the element to return |
Definition at line 78 of file CircularArray.cc.
| const T & CircularArray::CircularArray< T >::atAbsoluteIndex | ( | size_t | index | ) | const |
Access specified element in underlying storage.
| index | absolute index position of the element to return |
Definition at line 83 of file CircularArray.cc.
| T & CircularArray::CircularArray< T >::back | ( | ) |
Access the last element.
Definition at line 107 of file CircularArray.cc.
| const T & CircularArray::CircularArray< T >::back | ( | ) | const |
Access the last element.
Definition at line 112 of file CircularArray.cc.
|
noexcept |
Returns the number of elements that can be held in currently allocated storage.
Definition at line 41 of file CircularArray.cc.
| T & CircularArray::CircularArray< T >::front | ( | ) |
Access the first element.
Definition at line 97 of file CircularArray.cc.
| const T & CircularArray::CircularArray< T >::front | ( | ) | const |
Access the first element.
Definition at line 102 of file CircularArray.cc.
|
noexcept |
Moves the beginning of the circular array.
| indexes | the number of indexes to add to the current beginning |
Definition at line 118 of file CircularArray.cc.
|
noexcept |
Moves the end of the circular array.
| indexes | the number of indexes to add to the current end |
Definition at line 129 of file CircularArray.cc.
| T & CircularArray::CircularArray< T >::operator[] | ( | ptrdiff_t | index | ) |
Access specified element.
| index | position of the element to return |
Definition at line 62 of file CircularArray.cc.
| const T & CircularArray::CircularArray< T >::operator[] | ( | ptrdiff_t | index | ) | const |
Access specified element.
| index | position of the element to return |
Definition at line 67 of file CircularArray.cc.
|
noexcept |
Resets beginning and end indexes.
Definition at line 142 of file CircularArray.cc.
|
noexcept |
Resets beginning and end indexes and resizes the container.
| capacity | new size of the container |
Definition at line 148 of file CircularArray.cc.
|
noexcept |
Resets beginning and end indexes and resizes the container.
| capacity | new size of the container |
| value | value to re-initialize all elements with |
Definition at line 155 of file CircularArray.cc.
|
noexcept |
Resets beginning and end indexes and the container's elements.
| value | value to re-initialize all elements with |
Definition at line 163 of file CircularArray.cc.
|
noexcept |
Returns the number of elements currently used in the container.
Definition at line 46 of file CircularArray.cc.
|
protected |
First index in internal storage.
Definition at line 46 of file CircularArray.h.
|
protected |
Number of elements that can be held in currently allocated storage.
Definition at line 45 of file CircularArray.h.
|
protected |
Underlying data storage.
Definition at line 44 of file CircularArray.h.
|
protected |
Number of elements currently stored.
Definition at line 47 of file CircularArray.h.