Ponca  aa50bfdf187919869239c5b44b748842569114c1
Point Cloud Analysis library
Loading...
Searching...
No Matches
stack.h
1
9#pragma once
10
11#include <array>
12
13#include "../defines.h" //STD_SAFE_AT
14
15namespace Ponca {
16
23template<class T, int N>
24class Stack
25{
26public:
28 using ValueType = T;
29
30 inline Stack();
31
33 inline const T& top() const;
35 inline T& top();
36
38 inline bool empty() const;
40 inline int size() const;
41
44 inline void push(const T& value);
45
47 inline void push();
51 inline void pop();
54 inline void clear();
55
56protected:
58 int m_size;
60 std::array<T,N> m_data;
61};
62
66
67template<class T, int N>
69 m_size(0),
70 m_data()
71{
72}
73
74template<class T, int N>
75const T& Stack<T,N>::top() const
76{
77 return STD_SAFE_AT(m_data,m_size-1);
78}
79
80template<class T, int N>
82{
83 return STD_SAFE_AT(m_data,m_size-1);
84}
85
86template<class T, int N>
88{
89 return m_size==0;
90}
91
92template<class T, int N>
94{
95 return m_size;
96}
97
98template<class T, int N>
99void Stack<T,N>::push(const T& value)
100{
101 STD_SAFE_AT(m_data,m_size) = value;
102 ++m_size;
103}
104
105template<class T, int N>
107{
108 ++m_size;
109}
110
111template<class T, int N>
113{
114 --m_size;
115}
116
117template<class T, int N>
119{
120 m_size = 0;
121}
122
123} // namespace Ponca
124
Stack with fixed-size storage.
Definition: stack.h:25
void clear()
Clear the stack content.
Definition: stack.h:118
void pop()
Pop the last element of the Stack.
Definition: stack.h:112
int size() const
Get the number of elements in the Stack.
Definition: stack.h:93
std::array< T, N > m_data
Fixed-size data buffer.
Definition: stack.h:60
T ValueType
Type of value stored in the Stack.
Definition: stack.h:28
void push(const T &value)
Add an element on top of the stack.
Definition: stack.h:99
void push()
Add an element with default initialization.
Definition: stack.h:106
int m_size
Number of elements in the Stack.
Definition: stack.h:58
T & top()
Write access to the top element of the Stack.
Definition: stack.h:81
bool empty() const
Is the stack empty.
Definition: stack.h:87
const T & top() const
Read access to the top element of the Stack.
Definition: stack.h:75
This Source Code Form is subject to the terms of the Mozilla Public License, v.