Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TArrayStack.ipp
Go to the documentation of this file.
1#pragma once
2
4
5#include <Common/assertion.h>
6
7#include <utility>
8
9namespace ph
10{
11
12template<typename T, std::size_t N>
14 m_data{}, m_currentIndex(-1)
15{}
16
17template<typename T, std::size_t N>
18template<typename U>
19inline void TArrayStack<T, N>::push(U&& item)
21 PH_ASSERT_IN_RANGE(m_currentIndex + 1, Index(0), Index(N));
22
23 m_data[++m_currentIndex] = std::forward<U>(item);
24}
25
26template<typename T, std::size_t N>
28{
29 PH_ASSERT_IN_RANGE(m_currentIndex - 1, Index(-1), Index(N - 1));
30
31 --m_currentIndex;
32}
34template<typename T, std::size_t N>
37 PH_ASSERT_IN_RANGE(m_currentIndex, Index(0), Index(N));
38
39 return m_data[m_currentIndex];
41
42template<typename T, std::size_t N>
43inline const T& TArrayStack<T, N>::top() const
44{
45 PH_ASSERT_IN_RANGE(m_currentIndex, Index(0), Index(N));
46
47 return m_data[m_currentIndex];
48}
49
50template<typename T, std::size_t N>
51inline std::size_t TArrayStack<T, N>::height() const
52{
53 PH_ASSERT_GE(m_currentIndex + 1, Index(0));
54
55 return static_cast<std::size_t>(m_currentIndex + 1);
56}
57
58template<typename T, std::size_t N>
60{
61 m_currentIndex = -1;
62}
63
64template<typename T, std::size_t N>
65inline bool TArrayStack<T, N>::isEmpty() const
66{
67 return m_currentIndex == -1;
68}
69
70template<typename T, std::size_t N>
71inline T& TArrayStack<T, N>::operator [] (const std::size_t index)
72{
73 PH_ASSERT_IN_RANGE(index, 0, m_data.size());
74
75 return m_data[index];
76}
77
78template<typename T, std::size_t N>
79inline const T& TArrayStack<T, N>::operator [] (const std::size_t index) const
80{
81 PH_ASSERT_IN_RANGE(index, 0, m_data.size());
82
83 return m_data[index];
84}
85
86}// end namespace ph
void push(U &&item)
Adds an item to the stack. The item originally at the target index will be overwritten.
Definition TArrayStack.ipp:19
T & top()
Definition TArrayStack.ipp:35
std::size_t height() const
Definition TArrayStack.ipp:51
T & operator[](std::size_t index)
Definition TArrayStack.ipp:71
void clear()
Definition TArrayStack.ipp:59
bool isEmpty() const
Definition TArrayStack.ipp:65
TArrayStack()
Definition TArrayStack.ipp:13
void pop()
Removes the top item from the stack. The item originally at the target index is still alive after thi...
Definition TArrayStack.ipp:27
The root for all renderer implementations.
Definition EEngineProject.h:6