PST SDK 7.0.0.0-ebe6e713
Loading...
Searching...
No Matches
PstArray.h
Go to the documentation of this file.
1// Copyright PS-Tech B.V. All Rights Reserved.
2
3#pragma once
4
5#include "TrackerExceptions.h"
6
7#include <cstddef>
8#include <cassert>
9#include <string>
10
11namespace PSTech
12{
13namespace Utils
14{
19 template<typename T, size_t Size>
21 {
22 public:
23 typedef T value_type;
24 typedef size_t size_type;
25 typedef T* pointer;
26 typedef const T* const_pointer;
27 typedef T& reference;
28 typedef const T& const_reference;
29 typedef T* iterator;
30 typedef const T* const_iterator;
31
35 constexpr size_type size() const
36 {
37 return Size;
38 }
39
41 constexpr bool empty() const
42 {
43 return Size == 0;
44 }
45
48 {
49 return _array;
50 }
51
54 {
55 return _array;
56 }
57
64 {
65 check_bounds(index);
66 return _array[index];
67 }
68
75 {
76 check_bounds(index);
77 return _array[index];
78 }
79
82 {
83 assert(Size > 0);
84 return _array[0];
85 }
86
89 {
90 assert(Size > 0);
91 return _array[0];
92 }
93
96 {
97 assert(Size > 0);
98 return _array[Size - 1];
99 }
100
103 {
104 assert(Size > 0);
105 return _array[Size - 1];
106 }
107
110 {
111 return _array;
112 }
113
116 {
117 return _array;
118 }
119
122 {
123 return _array;
124 }
125
128 {
129 return _array + Size;
130 }
131
134 {
135 return _array + Size;
136 }
137
140 {
141 return _array + Size;
142 }
143
145 const_reference operator [] (size_type index) const
146 {
147 assert(index < Size);
148 return _array[index];
149 }
150
152 reference operator [] (size_type index)
153 {
154 assert(index < Size);
155 return _array[index];
156 }
157
159 bool operator==(const PstArray<T, Size>& array) const
160 {
161 for (size_t index = 0; index < Size; ++index)
162 {
163 if (_array[index] != array[index])
164 {
165 return false;
166 }
167 }
168 return true;
169 }
170
172 bool operator!=(const PstArray<T, Size>& array) const
173 {
174 return !(*this == array);
175 }
176
179
180 private:
182 {
183 if (index >= Size)
184 {
185 throw OutOfRangeException(("Requested index out of range: " + std::to_string(index) + " >= " + std::to_string(Size)).c_str());
186 }
187 }
188 };
189}
190}
Definition TrackerExceptions.h:59
Definition PstArray.h:21
void check_bounds(size_type index)
Definition PstArray.h:181
const_reference front() const
Definition PstArray.h:81
T value_type
Definition PstArray.h:23
const_iterator begin() const
Definition PstArray.h:115
const T * const_iterator
Definition PstArray.h:30
constexpr size_type size() const
Definition PstArray.h:35
const_pointer data() const
Definition PstArray.h:47
T * iterator
Definition PstArray.h:29
pointer data()
Definition PstArray.h:53
const_iterator cbegin() const
Definition PstArray.h:109
size_t size_type
Definition PstArray.h:24
const T * const_pointer
Definition PstArray.h:26
const_reference back() const
Definition PstArray.h:95
T * pointer
Definition PstArray.h:25
reference front()
Definition PstArray.h:88
const_reference at(size_type index) const
Definition PstArray.h:63
const_iterator cend() const
Definition PstArray.h:127
T & reference
Definition PstArray.h:27
value_type _array[Size]
Definition PstArray.h:178
reference at(size_type index)
Definition PstArray.h:74
iterator end()
Definition PstArray.h:139
const_iterator end() const
Definition PstArray.h:133
iterator begin()
Definition PstArray.h:121
reference back()
Definition PstArray.h:102
const T & const_reference
Definition PstArray.h:28
constexpr bool empty() const
Definition PstArray.h:41
Definition PstArray.h:14
Definition ExportedTypeConversions.h:9