Lodestar
An integrated real-time control package in C++
ls::aux::ArrayStack< TType, TSize > Struct Template Reference

A statically sized stack with full member access. More...

#include <ArrayStack.hpp>

Public Types

using type = ArrayStack< TType, TSize >
 
using arrayType = std::array< TType, TSize >
 

Public Member Functions

size_t size () const noexcept
 Gives current stack size. More...
 
constexpr size_t max_size () const noexcept
 Gives maximum stack size. More...
 
void clear () noexcept
 Clears the stack. More...
 
TType & operator[] (size_t idx)
 Returns a reference to the element at idx. More...
 
const TType & operator[] (size_t idx) const
 Returns a const reference to the element at idx. More...
 
void fill (const TType &value)
 Fills the stack to full capacity with value. More...
 
bool empty () const noexcept
 Returns true if stack is empty. More...
 
void push (const TType &value)
 Pushes value to front of ArrayStack. More...
 
void pop_front ()
 Pops first element. More...
 
void pop_back ()
 Pops last element.
 
TType & front ()
 Returns a reference to the front value in the stack. More...
 
const TType & front () const
 Returns a const reference to the front value in the stack. More...
 
TType & back ()
 Returns a reference to the rear value in the stack. More...
 
const TType & back () const
 Returns a const reference to the rear value in the stack. More...
 
arrayType::iterator begin () noexcept
 Returns an iterator the beginning of the stack. More...
 
arrayType::const_iterator begin () const noexcept
 Returns a const iterator the beginning of the stack. More...
 
arrayType::iterator end () noexcept
 Returns an iterator the end of the stack. More...
 
arrayType::const_iterator end () const noexcept
 Returns a const iterator the end of the stack. More...
 
const arrayType & array () const noexcept
 

Static Public Member Functions

static type zero ()
 Construct a stack filled with the default values of TType. More...
 

Protected Attributes

arrayType array_
 
size_t size_
 

Detailed Description

template<typename TType, size_t TSize>
struct ls::aux::ArrayStack< TType, TSize >

A statically sized stack with full member access.

Template Parameters
TTypeType of element.
TSizeMaximum size of stack.

Member Function Documentation

◆ back() [1/2]

template<typename TType , size_t TSize>
TType& ls::aux::ArrayStack< TType, TSize >::back ( )
inline

Returns a reference to the rear value in the stack.

Raises out_of_range exception if the current stack size is 0.

Returns
Reference to rear value.

◆ back() [2/2]

template<typename TType , size_t TSize>
const TType& ls::aux::ArrayStack< TType, TSize >::back ( ) const
inline

Returns a const reference to the rear value in the stack.

Raises out_of_range exception if the current stack size is 0.

Returns
Const reference to rear value.

◆ begin() [1/2]

template<typename TType , size_t TSize>
arrayType::const_iterator ls::aux::ArrayStack< TType, TSize >::begin ( ) const
inlinenoexcept

Returns a const iterator the beginning of the stack.

Returns
Const iterator the beginning of the stack.

◆ begin() [2/2]

template<typename TType , size_t TSize>
arrayType::iterator ls::aux::ArrayStack< TType, TSize >::begin ( )
inlinenoexcept

Returns an iterator the beginning of the stack.

Returns
Iterator the beginning of the stack.

◆ clear()

template<typename TType , size_t TSize>
void ls::aux::ArrayStack< TType, TSize >::clear ( )
inlinenoexcept

Clears the stack.

Note that this function simply changes the size of the stack to 0, allowing internally stored elements to be overwritten.

◆ empty()

template<typename TType , size_t TSize>
bool ls::aux::ArrayStack< TType, TSize >::empty ( ) const
inlinenoexcept

Returns true if stack is empty.

An empty stack is simply one for which size() == 0.

Returns
True if stack is empty.

◆ end() [1/2]

template<typename TType , size_t TSize>
arrayType::const_iterator ls::aux::ArrayStack< TType, TSize >::end ( ) const
inlinenoexcept

Returns a const iterator the end of the stack.

Returns
Const iterator the end of the stack.

◆ end() [2/2]

template<typename TType , size_t TSize>
arrayType::iterator ls::aux::ArrayStack< TType, TSize >::end ( )
inlinenoexcept

Returns an iterator the end of the stack.

Returns
Iterator the end of the stack.

◆ fill()

template<typename TType , size_t TSize>
void ls::aux::ArrayStack< TType, TSize >::fill ( const TType &  value)
inline

Fills the stack to full capacity with value.

Parameters
valueValue to fill stack with.

◆ front() [1/2]

template<typename TType , size_t TSize>
TType& ls::aux::ArrayStack< TType, TSize >::front ( )
inline

Returns a reference to the front value in the stack.

Raises out_of_range exception if the current stack size is 0.

Returns
Reference to front value.

◆ front() [2/2]

template<typename TType , size_t TSize>
const TType& ls::aux::ArrayStack< TType, TSize >::front ( ) const
inline

Returns a const reference to the front value in the stack.

Raises out_of_range exception if the current stack size is 0.

Returns
Const reference to front value.

◆ max_size()

template<typename TType , size_t TSize>
constexpr size_t ls::aux::ArrayStack< TType, TSize >::max_size ( ) const
inlineconstexprnoexcept

Gives maximum stack size.

Returns
Maximum stack size.

◆ operator[]() [1/2]

template<typename TType , size_t TSize>
TType& ls::aux::ArrayStack< TType, TSize >::operator[] ( size_t  idx)
inline

Returns a reference to the element at idx.

This function throws an out_of_range exception for illegal idx value (negative, or greater than size).

Parameters
idxElement index.
Returns
Reference to element at idx.

◆ operator[]() [2/2]

template<typename TType , size_t TSize>
const TType& ls::aux::ArrayStack< TType, TSize >::operator[] ( size_t  idx) const
inline

Returns a const reference to the element at idx.

This function throws an out_of_range exception for illegal idx value (negative, or greater than size).

Parameters
idxElement index.
Returns
Const reference to element at idx.

◆ pop_front()

template<typename TType , size_t TSize>
void ls::aux::ArrayStack< TType, TSize >::pop_front ( )
inline

Pops first element.

All subsequent values are shifted to the left, and the size is decremented by 1.

◆ push()

template<typename TType , size_t TSize>
void ls::aux::ArrayStack< TType, TSize >::push ( const TType &  value)
inline

Pushes value to front of ArrayStack.

By pushing a value to the front, all other elements are shifted right. If the new size would have been greater than the maximum size, the last element is popped.

Parameters
valueValue to push to front.

◆ size()

template<typename TType , size_t TSize>
size_t ls::aux::ArrayStack< TType, TSize >::size ( ) const
inlinenoexcept

Gives current stack size.

Returns
Current stack size.

◆ zero()

template<typename TType , size_t TSize>
static type ls::aux::ArrayStack< TType, TSize >::zero ( )
inlinestatic

Construct a stack filled with the default values of TType.

Returns
Stack filled with default constructed value of TType.

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