Speeduino
Loading...
Searching...
No Matches
table3d_axes.h
Go to the documentation of this file.
1
10#pragma once
11
12#include "table3d_typedefs.h"
13
23
25{
26 return domain==axis_domain_Rpm ? 100U : 2U;
27}
28
31{
32public:
33
36 : _stride(pEnd>pStart ? stride_inc : stride_dec)
37 , _pStart(pStart)
38 , _pEnd(pEnd + _stride)
39 {
40 }
41
46 {
47 _pStart = _pStart + ((int16_t)_stride * steps);
48 return *this;
49 }
50
53 {
54 return advance(1);
55 }
56
58 bool at_end(void) const
59 {
60 return _pStart == _pEnd;
61 }
62
65 {
66 return *_pStart;
67 }
69 const table3d_axis_t& operator*(void) const
70 {
71 return *_pStart;
72 }
73
74private:
75
76 static constexpr int8_t stride_inc = 1;
77 static constexpr int8_t stride_dec = -1;
78 int8_t _stride;
79 table3d_axis_t *_pStart;
80 const table3d_axis_t *_pEnd;
81};
82
83#define TABLE3D_TYPENAME_AXIS(size) table3d ## size ## _axis
84
85#define TABLE3D_GEN_AXIS(size) \
86 \
87 struct TABLE3D_TYPENAME_AXIS(size) { \
88 \
89 static constexpr table3d_dim_t length = (size); \
90 \
93 table3d_axis_t axis[(size)]; \
94 \
95 \
96 table_axis_iterator begin(void) \
97 { \
98 return table_axis_iterator(axis+(size)-1, axis); \
99 } \
100 \
101 table_axis_iterator rbegin(void) \
102 { \
103 return table_axis_iterator(axis, axis+(size)-1); \
104 } \
105 };
106
107// This generates the axis types for the following sizes & domains:
108TABLE3D_GEN_AXIS(4)
109TABLE3D_GEN_AXIS(6)
110TABLE3D_GEN_AXIS(8)
111TABLE3D_GEN_AXIS(16)
112
Iterate over table axis elements.
Definition table3d_axes.h:31
bool at_end(void) const
Test for end of iteration.
Definition table3d_axes.h:58
table3d_axis_t & operator*(void)
Dereference the iterator.
Definition table3d_axes.h:64
table_axis_iterator(table3d_axis_t *pStart, const table3d_axis_t *pEnd)
Construct.
Definition table3d_axes.h:35
table_axis_iterator & operator++(void)
Increment the iterator by one element.
Definition table3d_axes.h:52
table_axis_iterator & advance(int8_t steps)
Advance the iterator.
Definition table3d_axes.h:45
const table3d_axis_t & operator*(void) const
Dereference the iterator.
Definition table3d_axes.h:69
static uint32_t rshift(uint32_t a)
Bitwise right shift - generic, unoptimized, case.
Definition bit_shifts.h:348
static constexpr uint16_t axis_domain_to_factor(axis_domain domain)
Definition table3d_axes.h:24
uint8_t table3d_axis_t
The type of each axis value.
Definition table3d_typedefs.h:28
axis_domain
Encodes the real world measurement that a table axis captures.
Definition table3d_axes.h:17
@ axis_domain_Rpm
Definition table3d_axes.h:19
@ axis_domain_Load
Definition table3d_axes.h:21
Typedefs for primitive 3D table elements.