Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TArrayVector.ipp
Go to the documentation of this file.
1#pragma once
2
4
5#include <Common/assertion.h>
6#include <Common/config.h>
7
8#include <utility>
9#include <type_traits>
10
11namespace ph
12{
13
14template<typename T, std::size_t N>
16
17#if PH_DEBUG
18 // Request value-initialization: set to zeros for primitive types
19 m_data{},
20#else
21 // Intentionally left empty: default-initialize array members
22#endif
23
24 m_size(0)
25{}
26
27template<typename T, std::size_t N>
28template<typename U>
29inline void TArrayVector<T, N>::pushBack(U&& item)
30{
31 // TODO: static assert for U == T, amy require ref and ptr removal
33 PH_ASSERT_LT(m_size, m_data.size());
35 // FIXME: what if assignment throw? need increment m_size later only if assignment succeeded;
36 // perhaps check if op is no-throw?
37 m_data[m_size++] = std::forward<U>(item);
39
40template<typename T, std::size_t N>
42{
43 PH_ASSERT_GT(m_size, 0);
45 --m_size;
46}
47
48template<typename T, std::size_t N>
49inline std::size_t TArrayVector<T, N>::size() const
50{
51 PH_ASSERT_LE(m_size, N);
53 return m_size;
55
56template<typename T, std::size_t N>
58{
59 m_size = 0;
60}
61
62template<typename T, std::size_t N>
63inline bool TArrayVector<T, N>::isEmpty() const
64{
65 return m_size == 0;
66}
67
68template<typename T, std::size_t N>
69inline bool TArrayVector<T, N>::isFull() const
70{
71 return m_size == N;
72}
73
74template<typename T, std::size_t N>
75inline T* TArrayVector<T, N>::get(const std::size_t index)
76{
77 return index < m_size ? &(m_data[index]) : nullptr;
78}
79
80template<typename T, std::size_t N>
81inline const T* TArrayVector<T, N>::get(const std::size_t index) const
82{
83 return index < m_size ? &(m_data[index]) : nullptr;
84}
85
86template<typename T, std::size_t N>
87inline T& TArrayVector<T, N>::operator [] (const std::size_t index)
88{
89 PH_ASSERT_LT(index, m_size);
90
91 return m_data[index];
92}
93
94template<typename T, std::size_t N>
95inline const T& TArrayVector<T, N>::operator [] (const std::size_t index) const
96{
97 PH_ASSERT_LT(index, m_size);
98
99 return m_data[index];
100}
101
102template<typename T, std::size_t N>
104{
105 PH_ASSERT_GT(m_size, 0);
106
107 return (*this)[0];
108}
109
110template<typename T, std::size_t N>
111inline const T& TArrayVector<T, N>::front() const
112{
113 PH_ASSERT_GT(m_size, 0);
114
115 return (*this)[0];
116}
117
118template<typename T, std::size_t N>
120{
121 PH_ASSERT_GT(m_size, 0);
122
123 return (*this)[m_size - 1];
124}
125
126template<typename T, std::size_t N>
127inline const T& TArrayVector<T, N>::back() const
128{
129 PH_ASSERT_GT(m_size, 0);
130
131 return (*this)[m_size - 1];
132}
133
134template<typename T, std::size_t N>
135typename std::array<T, N>::iterator TArrayVector<T, N>::begin() noexcept
136{
137 return m_data.begin();
138}
139
140template<typename T, std::size_t N>
141typename std::array<T, N>::const_iterator TArrayVector<T, N>::begin() const noexcept
142{
143 return m_data.begin();
144}
145
146template<typename T, std::size_t N>
147typename std::array<T, N>::iterator TArrayVector<T, N>::end() noexcept
148{
149 // Not using std::advance() as we expect it to be randomly accessible
150 // (no permissive code)
151 return m_data.begin() + m_size;
152}
153
154template<typename T, std::size_t N>
155typename std::array<T, N>::const_iterator TArrayVector<T, N>::end() const noexcept
156{
157 // Not using std::advance() as we expect it to be randomly accessible
158 // (no permissive code)
159 return m_data.begin() + m_size;
160}
161
162}// end namespace ph
else if(BATCH_SIZE==8)
Definition TBvhSimdComputingContext.h:505
std::array< T, N >::iterator begin() noexcept
Definition TArrayVector.ipp:135
T & back()
Definition TArrayVector.ipp:119
void pushBack(U &&item)
Add an item to the back of the vector. The item originally at the target index will be overwritten.
Definition TArrayVector.ipp:29
T & operator[](std::size_t index)
Definition TArrayVector.ipp:87
bool isEmpty() const
Definition TArrayVector.ipp:63
std::size_t size() const
Definition TArrayVector.ipp:49
TArrayVector()
Definition TArrayVector.ipp:15
void clear()
Definition TArrayVector.ipp:57
void popBack()
Removes an item from the back of the vector. The item originally at the target index is still alive a...
Definition TArrayVector.ipp:41
std::array< T, N >::iterator end() noexcept
Definition TArrayVector.ipp:147
bool isFull() const
Definition TArrayVector.ipp:69
T * get(std::size_t index)
Definition TArrayVector.ipp:75
T & front()
Definition TArrayVector.ipp:103
The root for all renderer implementations.
Definition EEngineProject.h:6