Speeduino
Loading...
Searching...
No Matches
table3d.h
Go to the documentation of this file.
1
46#pragma once
47
48#include "table3d_interpolate.h"
49#include "table3d_axes.h"
50#include "table3d_values.h"
51
52#define TO_TYPE_KEY(size, xDom, yDom) table3d ## size ## xDom ## yDom ## _key
53
71 #define TABLE3D_GEN_TYPEKEY(size, xDom, yDom) TO_TYPE_KEY(size, xDom, yDom),
72 TABLE3D_GENERATOR(TABLE3D_GEN_TYPEKEY)
73};
74
75// Generate the 3D table types
76#define TABLE3D_GEN_TYPE(size, xDom, yDom) \
77 \
78 struct TABLE3D_TYPENAME_BASE(size, xDom, yDom) \
79 { \
80 typedef TABLE3D_TYPENAME_AXIS(size) xaxis_t; \
81 typedef TABLE3D_TYPENAME_AXIS(size) yaxis_t; \
82 typedef TABLE3D_TYPENAME_VALUE(size, xDom, yDom) value_t; \
83 /* This will take up zero space unless we take the address somewhere */ \
84 static constexpr table_type_t type_key = TO_TYPE_KEY(size, xDom, yDom); \
85 \
86 mutable table3DGetValueCache get_value_cache; \
87 value_t values; \
88 xaxis_t axisX; \
89 yaxis_t axisY; \
90 };
91TABLE3D_GENERATOR(TABLE3D_GEN_TYPE)
92
93// Generate get3DTableValue() functions
94#define TABLE3D_GEN_GET_TABLE_VALUE(size, xDom, yDom) \
95 static inline table3d_value_t get3DTableValue(const TABLE3D_TYPENAME_BASE(size, xDom, yDom) *pTable, const uint16_t y, const uint16_t x) \
96 { \
97 constexpr uint16_t xFactor = axis_domain_to_factor(axis_domain_ ## xDom); \
98 constexpr uint16_t yFactor = axis_domain_to_factor(axis_domain_ ## yDom); \
99 return get3DTableValue<xFactor, yFactor>( &pTable->get_value_cache, \
100 TABLE3D_TYPENAME_BASE(size, xDom, yDom)::value_t::row_size, \
101 pTable->values.values, \
102 pTable->axisX.axis, \
103 pTable->axisY.axis, \
104 { x, y }); \
105 }
106TABLE3D_GENERATOR(TABLE3D_GEN_GET_TABLE_VALUE)
107
108// =============================== Table function calls =========================
109
110// With no templates or inheritance we need some way to call functions
111// for the various distinct table types. CONCRETE_TABLE_ACTION dispatches
112// to a caller defined function overloaded by the type of the table.
113#define CONCRETE_TABLE_ACTION_INNER(size, xDomain, yDomain, action, ...) \
114 case TO_TYPE_KEY(size, xDomain, yDomain): action(size, xDomain, yDomain, ##__VA_ARGS__);
115#define CONCRETE_TABLE_ACTION(testKey, action, defaultAction, ...) \
116 switch ((table_type_t)testKey) { \
117 TABLE3D_GENERATOR(CONCRETE_TABLE_ACTION_INNER, action, ##__VA_ARGS__ ) \
118 default: defaultAction; }
119
120// =============================== Table function calls =========================
121
123
125
127
129
Iterate over table axis elements.
Definition table3d_axes.h:31
Iterate through a tables values, row by row.
Definition table3d_values.h:82
static uint32_t rshift(uint32_t a)
Bitwise right shift - generic, unoptimized, case.
Definition bit_shifts.h:348
table_type_t
Table type identifiers. Limited compile time RTTI.
Definition table3d.h:69
table_axis_iterator x_rbegin(void *pTable, table_type_t key)
Definition table3d.cpp:26
table_axis_iterator y_begin(void *pTable, table_type_t key)
Definition table3d.cpp:37
table_axis_iterator x_begin(void *pTable, table_type_t key)
Definition table3d.cpp:18
table_value_iterator rows_begin(void *pTable, table_type_t key)
Definition table3d.cpp:6
table_axis_iterator y_rbegin(void *pTable, table_type_t key)
Definition table3d.cpp:45
@ table_type_None
Definition table3d.h:70
3D table axis types and iterators
Functions for interpolating values from 3D tables.
3D table value structs and iterators