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), //cppcheck-suppress misra-c2012-10.4
97 rowWidth(axisSize)
98 {
99 // Table values are laid out conventionally - rows are in order
100 // E.g. a 4x4 table with logical element [0][0] at the bottom left
101 // (normal cartesian coordinates) has this layout.
102 // 12 13 14 15
103 // 8 9 10 11
104 // 4 5 6 7
105 // 0 1 2 3
106 // So we start at row 0 (index 0 of the array) and iterate forward
107 }
108
113 {
114 _row = _row + rows;
115 return *this;
116 }
117
120 {
121 return advance(1U);
122 }
123
126 {
127 return table_row_iterator(pRowsStart + (_row*rowWidth), rowWidth);
128 }
131 {
132 return table_row_iterator(pRowsStart + (_row*rowWidth), rowWidth);
133 }
134
136 bool at_end(void) const
137 {
138 return _row == rowWidth;
139 }
140
141private:
142 const table3d_value_t *pRowsStart;
143 table3d_dim_t _row = 0;
144 table3d_dim_t rowWidth;
145};
146
147#define TABLE3D_TYPENAME_VALUE(size, xDom, yDom) CONCAT(TABLE3D_TYPENAME_BASE(size, xDom, yDom), _values)
148
149#define TABLE3D_GEN_VALUES(size, xDom, yDom) \
150 \
151 struct TABLE3D_TYPENAME_VALUE(size, xDom, yDom) { \
152 \
153 static constexpr table3d_dim_t row_size = (size); \
154 \
155 static constexpr table3d_dim_t num_rows = (size); \
156 \
157 table3d_value_t values[(uint16_t)row_size*num_rows]; \
158 \
159 \
160 table_value_iterator begin(void) \
161 { \
162 return table_value_iterator(values, row_size); \
163 } \
164 \
165 \
166 table3d_value_t& value_at(table3d_dim_t linear_index) \
167 { \
168 return values[linear_index]; \
169 } \
170 };
171TABLE3D_GENERATOR(TABLE3D_GEN_VALUES)
172
173
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:130
table_row_iterator operator*(void) const
Dereference the iterator to access a row of data.
Definition table3d_values.h:125
table_value_iterator & operator++(void)
Increment the iterator by one row.
Definition table3d_values.h:119
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:112
bool at_end(void) const
Test for end of iteration.
Definition table3d_values.h:136
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.