Speeduino
Loading...
Searching...
No Matches
table3d_values.h
Go to the documentation of this file.
1
10#pragma once
11
12#include "table3d_typedefs.h"
13
14// ========================= INTRA-ROW ITERATION =========================
15
21public:
22
29 : pValue(pRowStart), pEnd(pRowStart+rowWidth) //cppcheck-suppress misra-c2012-10.4
30 {
31 }
32
33 // LCOV_EXCL_START
35 const table3d_value_t* end(void) const { return pEnd; }
37 table3d_value_t* end(void) { return const_cast<table3d_value_t *>(pEnd); }
38 // LCOV_EXCL_STOP
39
44 {
45 pValue = pValue + steps;
46 return *this;
47 }
48
51 {
52 return advance(1);
53 }
54
56 bool at_end(void) const
57 {
58 return pValue == pEnd;
59 }
60
61 // LCOV_EXCL_START
63 const table3d_value_t& operator*(void) const
64 {
65 return *pValue;
66 }
69 {
70 return *const_cast<table3d_value_t *>(pValue);
71 }
72 // LCOV_EXCL_STOP
73
75 table3d_dim_t size(void) const { return pEnd-pValue; }
76
77private:
78 const table3d_value_t *pValue;
79 const table3d_value_t *pEnd;
80};
81
82// ========================= INTER-ROW ITERATION =========================
83
86{
87public:
88
95 : pRowsStart(pValues + (axisSize*(axisSize-1U))), //cppcheck-suppress misra-c2012-10.4
96 pRowsEnd(pValues - axisSize),
97 rowWidth(axisSize)
98 {
99 // Table values are not linear in memory - rows are in reverse order
100 // E.g. a 4x4 table with logical element [0][0] at the bottom left
101 // (normal cartesian coordinates) has this layout.
102 // 0 1 2 3
103 // 4 5 6 7
104 // 8 9 10 11
105 // 12 13 14 15
106 // So we start at row 3 (index 12 of the array) and iterate towards
107 // the start of the array
108 //
109 // This all supports fast 3d interpolation.
110 }
111
116 {
117 pRowsStart = pRowsStart - (rowWidth * rows);
118 return *this;
119 }
120
123 {
124 return advance(1U);
125 }
126
129 {
130 return table_row_iterator(pRowsStart, rowWidth);
131 }
134 {
135 return table_row_iterator(pRowsStart, rowWidth);
136 }
137
139 bool at_end(void) const
140 {
141 return pRowsStart == pRowsEnd;
142 }
143
144private:
145 const table3d_value_t *pRowsStart;
146 const table3d_value_t *pRowsEnd;
147 table3d_dim_t rowWidth;
148};
149
150#define TABLE3D_TYPENAME_VALUE(size, xDom, yDom) CONCAT(TABLE3D_TYPENAME_BASE(size, xDom, yDom), _values)
151
152#define TABLE3D_GEN_VALUES(size, xDom, yDom) \
153 \
154 struct TABLE3D_TYPENAME_VALUE(size, xDom, yDom) { \
155 \
156 static constexpr table3d_dim_t row_size = (size); \
157 \
158 static constexpr table3d_dim_t num_rows = (size); \
159 \
166 table3d_value_t values[(uint16_t)row_size*num_rows]; \
167 \
168 \
169 table_value_iterator begin(void) \
170 { \
171 return table_value_iterator(values, row_size); \
172 } \
173 \
174 \
192 table3d_value_t& value_at(table3d_dim_t linear_index) \
193 { \
194 static_assert(row_size<17U, "Table is too big"); \
195 static_assert(num_rows<17U, "Table is too big"); \
196 /* Zero length will mess up unsigned calcs */ \
197 static_assert(row_size>0U, "No zero length rows"); \
198 static_assert(num_rows>0U, "No empty tables"); \
199 constexpr table3d_dim_t first_index = row_size*(table3d_dim_t)(num_rows-1U); \
200 const table3d_dim_t index = (table3d_dim_t)(first_index + (table3d_dim_t)(2U*(linear_index % row_size)) - linear_index); \
201 return values[index]; \
202 } \
203 };
204TABLE3D_GENERATOR(TABLE3D_GEN_VALUES)
205
206
Iterate through a table row. I.e. constant Y, changing X.
Definition table3d_values.h:20
const table3d_value_t * end(void) const
Pointer to the end of the row.
Definition table3d_values.h:35
table_row_iterator & operator++(void)
Increment the iterator by one element.
Definition table3d_values.h:50
table_row_iterator(const table3d_value_t *pRowStart, table3d_dim_t rowWidth)
Construct.
Definition table3d_values.h:28
table3d_value_t * end(void)
Pointer to the end of the row.
Definition table3d_values.h:37
table3d_dim_t size(void) const
Number of elements available.
Definition table3d_values.h:75
table_row_iterator & advance(table3d_dim_t steps)
Advance the iterator.
Definition table3d_values.h:43
table3d_value_t & operator*(void)
Dereference the iterator.
Definition table3d_values.h:68
const table3d_value_t & operator*(void) const
Dereference the iterator.
Definition table3d_values.h:63
bool at_end(void) const
Test for end of iteration.
Definition table3d_values.h:56
Iterate through a tables values, row by row.
Definition table3d_values.h:86
table_row_iterator operator*(void)
Dereference the iterator to access a row of data.
Definition table3d_values.h:133
const table_row_iterator operator*(void) const
Dereference the iterator to access a row of data.
Definition table3d_values.h:128
table_value_iterator & operator++(void)
Increment the iterator by one row.
Definition table3d_values.h:122
table_value_iterator(const table3d_value_t *pValues, table3d_dim_t axisSize)
Construct.
Definition table3d_values.h:94
table_value_iterator & advance(table3d_dim_t rows)
Advance the iterator.
Definition table3d_values.h:115
bool at_end(void) const
Test for end of iteration.
Definition table3d_values.h:139
static TIntegral readSerialIntegralTimeout(void)
Reads an integral type, timing out if necessary.
Definition comms.cpp:175
uint8_t table3d_value_t
The type of each table value.
Definition table3d_typedefs.h:25
uint8_t table3d_dim_t
Encodes the length of the axes.
Definition table3d_typedefs.h:22
Typedefs for primitive 3D table elements.