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
25
28{
29public:
30
33 : _stride(pEnd>pStart ? stride_inc : stride_dec)
34 , _pStart(pStart)
35 , _pEnd(pEnd + _stride)
36 , _domain(domain) //cppcheck-suppress misra-c2012-10.4
37 {
38 }
39
40 axis_domain get_domain(void) const { return _domain; }
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 const axis_domain _domain;
82};
83
84#define TABLE3D_TYPENAME_AXIS(size, domain) table3d ## size ## domain ## _axis
85
86#define TABLE3D_GEN_AXIS(size, dom) \
87 \
88 struct TABLE3D_TYPENAME_AXIS(size, dom) { \
89 \
90 static constexpr table3d_dim_t length = (size); \
91 \
92 static constexpr axis_domain domain = axis_domain_ ## dom; \
93 \
96 table3d_axis_t axis[(size)]; \
97 \
98 \
99 table_axis_iterator begin(void) \
100 { \
101 return table_axis_iterator(axis+(size)-1, axis, domain); \
102 } \
103 \
104 table_axis_iterator rbegin(void) \
105 { \
106 return table_axis_iterator(axis, axis+(size)-1, domain); \
107 } \
108 };
109
110// This generates the axis types for the following sizes & domains:
111TABLE3D_GEN_AXIS(6, Rpm)
112TABLE3D_GEN_AXIS(6, Load)
113TABLE3D_GEN_AXIS(4, Rpm)
114TABLE3D_GEN_AXIS(4, Load)
115TABLE3D_GEN_AXIS(8, Rpm)
116TABLE3D_GEN_AXIS(8, Load)
117TABLE3D_GEN_AXIS(8, Tps)
118TABLE3D_GEN_AXIS(16, Rpm)
119TABLE3D_GEN_AXIS(16, Load)
120
121
Iterate over table axis elements.
Definition table3d_axes.h:28
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 & 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
axis_domain get_domain(void) const
Definition table3d_axes.h:40
const table3d_axis_t & operator*(void) const
Dereference the iterator.
Definition table3d_axes.h:69
table_axis_iterator(table3d_axis_t *pStart, const table3d_axis_t *pEnd, axis_domain domain)
Construct.
Definition table3d_axes.h:32
static uint32_t rshift(uint32_t a)
Bitwise right shift - generic, unoptimized, case.
Definition bit_shifts.h:349
Tps
Definition table3d.h:104
int16_t table3d_axis_t
The type of each axis value.
Definition table3d_typedefs.h:28
Rpm
Definition table3d.h:104
axis_domain
Encodes the real world measurement that a table axis captures.
Definition table3d_axes.h:17
Load
Definition table3d.h:104
@ axis_domain_Rpm
Definition table3d_axes.h:19
@ axis_domain_Tps
Definition table3d_axes.h:23
@ axis_domain_Load
Definition table3d_axes.h:21
Typedefs for primitive 3D table elements.