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