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, xDom) xaxis_t; \
81 typedef TABLE3D_TYPENAME_AXIS(size, yDom) 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 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(TABLE3D_TYPENAME_BASE(size, xDom, yDom) *pTable, table3d_axis_t y, table3d_axis_t x) \
96 { \
97 return get3DTableValue( &pTable->get_value_cache, \
98 TABLE3D_TYPENAME_BASE(size, xDom, yDom)::value_t::row_size, \
99 pTable->values.values, \
100 pTable->axisX.axis, \
101 pTable->axisY.axis, \
102 y, x); \
103 }
104TABLE3D_GENERATOR(TABLE3D_GEN_GET_TABLE_VALUE)
105
106// =============================== Table function calls =========================
107
108// With no templates or inheritance we need some way to call functions
109// for the various distinct table types. CONCRETE_TABLE_ACTION dispatches
110// to a caller defined function overloaded by the type of the table.
111#define CONCRETE_TABLE_ACTION_INNER(size, xDomain, yDomain, action, ...) \
112 case TO_TYPE_KEY(size, xDomain, yDomain): action(size, xDomain, yDomain, ##__VA_ARGS__);
113#define CONCRETE_TABLE_ACTION(testKey, action, defaultAction, ...) \
114 switch ((table_type_t)testKey) { \
115 TABLE3D_GENERATOR(CONCRETE_TABLE_ACTION_INNER, action, ##__VA_ARGS__ ) \
116 default: defaultAction; }
117
118// =============================== Table function calls =========================
119
121
123
125
127
Iterate over table axis elements.
Definition table3d_axes.h:28
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:349
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_axis_iterator y_rbegin(void *pTable, table_type_t key)
Definition table3d.cpp:45
table_type_t key
Definition table3d.h:120
@ table_type_None
Definition table3d.h:70
table_value_iterator rows_begin(const page_iterator_t &it)
Definition pages.cpp:458
3D table axis types and iterators
3D table value structs and iterators