Tables¶
Introduction¶
Simple tables can be implemented using Arrays, like this:
struct TableRow {
float columns[3];
int operator[](size_t index) const
{
return columns[index];
}
};
DEFINE_FSTR_ARRAY(table, TableRow,
{0.1, 0.2, 0.3},
{0.6, 0.7, 0.8}
);
for(auto row: table) {
Serial.printf("%f, %f, %f\n", row[0], row[1], row[2]);
}
Each row is a fixed size. The FSTR::TableRow
class template is provided to simplify this:
#include <FlashString/Table.hpp>
using FloatRow = FSTR::TableRow<float, 3>;
DEFINE_FSTR_ARRAY(table, FloatRow,
{0.1, 0.2, 0.3},
{0.6, 0.7, 0.8}
);
table.printTo(Serial);
table.println();
If you want to create a table with rows of different sizes or types, use a Vector.
Class Template¶
-
template <typename ElementType, size_t Columns>
classTableRow
¶ Class template to define the row of a table.
Use with an
Array Object to construct simple tables. Methods provide Object-like access.- Template Parameters
ElementType
:Columns
: Number of columns in the table
Public Functions
-
ElementType
operator[]
(size_t index) const¶ Array operator.
- Parameters
index
:
- Return Value
ElementType
:
-
size_t
length
() const¶ Get number of columns.
- Return Value
size_t
:
Public Members
-
template<>
ElementTypevalues
[Columns
]¶