Ponca  e26a0e88a45818354616c1a7180bcd203aecad3c
Point Cloud Analysis library
Loading...
Searching...
No Matches
Ponca::Stack< T, N > Class Template Reference

Stack with fixed-size storage. More...

#include <stack.h>

+ Inheritance diagram for Ponca::Stack< T, N >:
+ Collaboration diagram for Ponca::Stack< T, N >:

Public Types

using ValueType = T
 Type of value stored in the Stack.
 

Public Member Functions

const T & top () const
 Read access to the top element of the Stack.
 
T & top ()
 Write access to the top element of the Stack.
 
bool empty () const
 Is the stack empty.
 
int size () const
 Get the number of elements in the Stack.
 
void push (const T &value)
 Add an element on top of the stack.
 
void push ()
 Add an element with default initialization.
 
void pop ()
 Pop the last element of the Stack.
 
void clear ()
 Clear the stack content.
 

Protected Attributes

int m_size
 Number of elements in the Stack.
 
std::array< T, N > m_data
 Fixed-size data buffer.
 

Detailed Description

template<class T, int N>
class Ponca::Stack< T, N >

Stack with fixed-size storage.

Warning
This class does not destroy elements that are removed from the stack, but rather when they are overriden by another element (e.g. when running pop() and then push(). This makes it not appropriate to store smart pointers.

Definition at line 24 of file stack.h.

Member Typedef Documentation

◆ ValueType

template<class T , int N>
using Ponca::Stack< T, N >::ValueType = T

Type of value stored in the Stack.

Definition at line 28 of file stack.h.

Constructor & Destructor Documentation

◆ Stack()

template<class T , int N>
Ponca::Stack< T, N >::Stack
inline

Definition at line 68 of file stack.h.

Member Function Documentation

◆ clear()

template<class T , int N>
void Ponca::Stack< T, N >::clear
inline

Clear the stack content.

Note
Shares the same limitation than Stack::pop()

Definition at line 118 of file stack.h.

◆ empty()

template<class T , int N>
bool Ponca::Stack< T, N >::empty
inline

Is the stack empty.

Definition at line 87 of file stack.h.

◆ pop()

template<class T , int N>
void Ponca::Stack< T, N >::pop
inline

Pop the last element of the Stack.

Note
In practice the element is not destroyed, only the size of the Stack is reduced. This makes the Stack not appropriate to store shared_ptr: counters will not be decremented.

Definition at line 112 of file stack.h.

◆ push() [1/2]

template<class T , int N>
void Ponca::Stack< T, N >::push
inline

Add an element with default initialization.

Definition at line 106 of file stack.h.

◆ push() [2/2]

template<class T , int N>
void Ponca::Stack< T, N >::push ( const T &  value)
inline

Add an element on top of the stack.

Exceptions
std::out_of_rangewhen the Stack is full, only if compiled with PONCA_DEBUG

Definition at line 99 of file stack.h.

◆ size()

template<class T , int N>
int Ponca::Stack< T, N >::size
inline

Get the number of elements in the Stack.

Definition at line 93 of file stack.h.

◆ top() [1/2]

template<class T , int N>
T & Ponca::Stack< T, N >::top
inline

Write access to the top element of the Stack.

Definition at line 81 of file stack.h.

◆ top() [2/2]

template<class T , int N>
const T & Ponca::Stack< T, N >::top
inline

Read access to the top element of the Stack.

Definition at line 75 of file stack.h.

Member Data Documentation

◆ m_data

template<class T , int N>
std::array<T,N> Ponca::Stack< T, N >::m_data
protected

Fixed-size data buffer.

Definition at line 60 of file stack.h.

◆ m_size

template<class T , int N>
int Ponca::Stack< T, N >::m_size
protected

Number of elements in the Stack.

Definition at line 58 of file stack.h.