Arrays¶
Introduction¶
Supports arrays of simple types, such as char, int, double, or POD structures (i.e. basic C structures).
FSTR::Array
is a class template, so requires an additional ElementType
parameter:
#include <FlashString/Array.hpp>
DEFINE_FSTR_ARRAY(myDoubleArray, double,
PI, 53.0, 100, 1e8, 47
);
Serial.print("My double array: ");
myDoubleArray.printTo(Serial);
Serial.println();
Note
Objects do not inherit from Printable because it is a virtual base class.
Therefore, statements like Serial.println(myDoubleArray)
are not supported.
This also avoids ambiguity between implicit WString conversions.
There are some Print helper functions in the library you can use:
FSTR::println(Serial, myDoubleArray);
These are templated so will handle both simple data types and Objects.
You can share Arrays between translation units by declaring it in a header:
DECLARE_FSTR_ARRAY(table);
Macros¶
-
DECLARE_FSTR_ARRAY
(name, ElementType)¶ Declare a global Array& reference.
- Note
Use
DEFINE_FSTR_ARRAY
to instantiate the global Object- Parameters
name
:ElementType
:
-
DEFINE_FSTR_ARRAY
(name, ElementType, ...)¶ Define an Array Object with global reference.
- Note
Unlike String, array is not NUL-terminated
- Parameters
name
: Name of Array& reference to defineElementType
:...
: List of ElementType items
-
DEFINE_FSTR_ARRAY_LOCAL
(name, ElementType, ...)¶ Like DEFINE_FSTR_ARRAY except reference is declared static constexpr.
-
DEFINE_FSTR_ARRAY_DATA
(name, ElementType, ...)¶ Define an Array data structure.
- Parameters
name
: Name of data structureElementType
:...
: List of ElementType items
-
LOAD_FSTR_ARRAY
(name, array)¶ Load an Array object into a named local (stack) buffer.
- Note
Example:
DEFINE_FSTR_ARRAY(fsArray, double, 5.33, PI) ... LOAD_FSTR_ARRAY(arr, fsArray) printf("arr[0] = %f, %u elements, buffer is %u bytes\n", arr[0], fsArray.length(), sizeof(arr));
-
FSTR_ARRAY_ARRAY
(name, ElementType, ...)¶ Define an Array and load it into a named buffer on the stack.
- Note
Equivalent to
ElementType name[] = {a, b, c}
except the buffer is word-aligned
-
IMPORT_FSTR_ARRAY
(name, ElementType, file)¶ Define an Array containing data from an external file.
- See
See also
IMPORT_FSTR_DATA
- Parameters
name
: Name for the Array objectElementType
: Array element typefile
: Absolute path to the file containing the content
-
IMPORT_FSTR_ARRAY_LOCAL
(name, ElementType, file)¶ Like IMPORT_FSTR_ARRAY except reference is declared static constexpr.
Classes¶
-
template<typename
ElementType
>
classArray
: public FSTR::Object<Array<ElementType>, ElementType>¶ Class to access an array of integral values stored in flash.
- Template Parameters
ElementType
:
Public Functions
-
ArrayPrinter<Array>
printer
() const¶ Returns a printer object for this array.
- Note
ElementType must be supported by Print