41 #define DECLARE_FSTR_OBJECT(name, ObjectType) extern const ObjectType& name; 49 #define DEFINE_FSTR_REF(name, ObjectType, object) const ObjectType& name PROGMEM = object.template as<ObjectType>(); 51 #define DEFINE_FSTR_REF_NAMED(name, ObjectType) DEFINE_FSTR_REF(name, ObjectType, FSTR_DATA_NAME(name).object); 56 #define FSTR_DATA_NAME(name) __fstr__##name 82 #define FSTR_PTR(objref) static_cast<std::remove_reference<decltype(objref)>::type*>(&FSTR_DATA_NAME(objref).object) 87 #define FSTR_CHECK_STRUCT(name) \ 88 static_assert(std::is_pod<decltype(name)>::value, "FSTR structure not POD"); \ 89 static_assert(offsetof(decltype(name), data) == sizeof(uint32_t), "FSTR structure alignment error"); 99 #define IMPORT_FSTR_OBJECT(name, ObjectType, file) \ 100 IMPORT_FSTR_DATA(FSTR_DATA_NAME(name), file) \ 101 extern "C" __attribute__((visibility("hidden"))) const FSTR::ObjectBase FSTR_DATA_NAME(name); \ 102 DEFINE_FSTR_REF(name, ObjectType, FSTR_DATA_NAME(name)); 107 #define IMPORT_FSTR_OBJECT_LOCAL(name, ObjectType, file) \ 108 IMPORT_FSTR_DATA(FSTR_DATA_NAME(name), file) \ 109 extern "C" __attribute__((visibility("hidden"))) const FSTR::ObjectBase FSTR_DATA_NAME(name); \ 110 static constexpr DEFINE_FSTR_REF(name, ObjectType, FSTR_DATA_NAME(name)); 145 return Iterator(as<ObjectType>(), 0);
169 template <
typename ValueType>
int indexOf(
const ValueType& value)
const 172 for(
unsigned i = 0; i < len; ++i) {
173 if(as<ObjectType>().
valueAt(i) == value) {
186 return ElementType{0};
200 return sizeof(ElementType);
215 size_t read(
size_t index, ElementType* buffer,
size_t count)
const 217 auto offset = index *
sizeof(ElementType);
218 count *=
sizeof(ElementType);
229 size_t readFlash(
size_t index, ElementType* buffer,
size_t count)
const 231 auto offset = index *
sizeof(ElementType);
232 count *=
sizeof(ElementType);
size_t readFlash(size_t offset, void *buffer, size_t count) const
Read contents of a String into RAM, using flashread()
size_t readFlash(size_t index, ElementType *buffer, size_t count) const
Read content into RAM,using flashmem_read()
Definition: Object.hpp:229
Used when defining data structures.
Definition: ObjectBase.hpp:32
const uint8_t * data() const
Get a pointer to the flash data.
ObjectIterator< ObjectType, ElementType > Iterator
Definition: Object.hpp:123
ElementType valueAt(unsigned index) const
Definition: Object.hpp:181
size_t length() const
Get the length of the content in elements.
Definition: Object.hpp:164
#define FSTR_INLINE
Definition: config.hpp:26
Base class template for all types.
Definition: Object.hpp:120
std::enable_if< sizeof(T)==1, T >::type readValue(const T *ptr)
Read a typed value from flash memory ensuring correct alignment of access.
Definition: Utility.hpp:123
Object()
Creates a null object.
Definition: Object.hpp:128
Iterator begin() const
Definition: Object.hpp:143
size_t read(size_t index, ElementType *buffer, size_t count) const
Read content into RAM.
Definition: Object.hpp:215
void copy(const ObjectBase &obj)
Definition: ObjectBase.hpp:130
size_t read(size_t offset, void *buffer, size_t count) const
Read contents of a String into RAM.
Definition: ObjectBase.hpp:72
Definition: ObjectIterator.hpp:29
static const ObjectBase empty_
Definition: ObjectBase.hpp:120
size_t length() const
Get the length of the object data in bytes.
static const ObjectType & empty()
Return an empty object which evaluates to null.
Definition: Object.hpp:156
Definition: Array.hpp:107
int indexOf(const ValueType &value) const
Definition: Object.hpp:169
Iterator end() const
Definition: Object.hpp:148
ElementType operator[](unsigned index) const
Array operator[].
Definition: Object.hpp:193
constexpr const ObjectType & as() const
Cast to a different object type.
Definition: ObjectBase.hpp:55
Object(const Object &obj)
Copy constructor.
Definition: Object.hpp:138
const ElementType * data() const
Definition: Object.hpp:203
size_t elementSize() const
Definition: Object.hpp:198