Ponca  7d8ac87a7de01d881c9fde3c42e397b44bffb901
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{
17
24 template <class T, int N>
25 class Stack
26 {
27 public:
29 using ValueType = T;
30
31 PONCA_MULTIARCH inline Stack();
32
34 PONCA_MULTIARCH inline const T& top() const;
36 PONCA_MULTIARCH inline T& top();
37
39 PONCA_MULTIARCH inline bool empty() const;
41 PONCA_MULTIARCH inline int size() const;
42
45 PONCA_MULTIARCH inline void push(const T& value);
46
48 PONCA_MULTIARCH inline void push();
52 PONCA_MULTIARCH inline void pop();
55 PONCA_MULTIARCH inline void clear();
56
57 protected:
59 int m_size;
61 std::array<T, N> m_data;
62 };
63
67
68 template <class T, int N>
69 Stack<T, N>::Stack() : m_size(0), m_data()
70 {
71 }
72
73 template <class T, int N>
74 const T& Stack<T, N>::top() const
75 {
76 return STD_SAFE_AT(m_data, m_size - 1);
77 }
78
79 template <class T, int N>
81 {
82 return STD_SAFE_AT(m_data, m_size - 1);
83 }
84
85 template <class T, int N>
86 bool Stack<T, N>::empty() const
87 {
88 return m_size == 0;
89 }
90
91 template <class T, int N>
93 {
94 return m_size;
95 }
96
97 template <class T, int N>
98 void Stack<T, N>::push(const T& value)
99 {
100 STD_SAFE_AT(m_data, m_size) = value;
101 ++m_size;
102 }
103
104 template <class T, int N>
106 {
107 ++m_size;
108 }
109
110 template <class T, int N>
112 {
113 --m_size;
114 }
115
116 template <class T, int N>
118 {
119 m_size = 0;
120 }
121
122} // namespace Ponca
123
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:318
Stack with fixed-size storage.
Definition stack.h:26
void clear()
Clear the stack content.
Definition stack.h:117
std::array< T, N > m_data
Fixed-size data buffer.
Definition stack.h:61
void pop()
Pop the last element of the Stack.
Definition stack.h:111
int size() const
Get the number of elements in the Stack.
Definition stack.h:92
T ValueType
Type of value stored in the Stack.
Definition stack.h:29
void push(const T &value)
Add an element on top of the stack.
Definition stack.h:98
void push()
Add an element with default initialization.
Definition stack.h:105
int m_size
Number of elements in the Stack.
Definition stack.h:59
T & top()
Write access to the top element of the Stack.
Definition stack.h:80
bool empty() const
Is the stack empty.
Definition stack.h:86
const T & top() const
Read access to the top element of the Stack.
Definition stack.h:74
This Source Code Form is subject to the terms of the Mozilla Public License, v.