41 #define DECLARE_FSTR_OBJECT(name, ObjectType) extern const ObjectType& name;
47 #define DEFINE_FSTR_OBJREF(name, object) const decltype(object)& name PROGMEM = object;
48 #define DEFINE_FSTR_REF(name) DEFINE_FSTR_OBJREF(name, FSTR_DATA_NAME(name).object)
49 #define DEFINE_FSTR_REF_LOCAL(name) static constexpr DEFINE_FSTR_REF(name)
55 #define FSTR_DATA_NAME(name) __fstr__##name
62 #define FSTR_PTR(objref) (&objref)
67 #define FSTR_CHECK_STRUCT(name) \
68 static_assert(std::is_standard_layout<decltype(name)>::value, "FSTR structure not Standard Layout"); \
69 static_assert(offsetof(decltype(name), data) == sizeof(uint32_t), "FSTR structure alignment error");
79 #define IMPORT_FSTR_OBJECT(name, ObjectType, file) \
80 IMPORT_FSTR_DATA(FSTR_DATA_NAME(name), file) \
81 extern "C" __attribute__((visibility("hidden"))) const ObjectType FSTR_DATA_NAME(name); \
82 DEFINE_FSTR_OBJREF(name, FSTR_DATA_NAME(name))
87 #define IMPORT_FSTR_OBJECT_LOCAL(name, ObjectType, file) \
88 IMPORT_FSTR_DATA(FSTR_DATA_NAME(name), file) \
89 extern "C" __attribute__((visibility("hidden"))) const ObjectType FSTR_DATA_NAME(name); \
90 static constexpr DEFINE_FSTR_OBJREF(name, FSTR_DATA_NAME(name))
109 #if __cplusplus <= 201703L
118 return Iterator(as<ObjectType>(), 0);
142 template <
typename ValueType>
int indexOf(
const ValueType& value)
const
144 auto&
self = as<ObjectType>();
145 auto dataptr =
self.data();
146 auto len =
self.length();
147 for(
unsigned i = 0; i < len; ++i) {
171 return sizeof(ElementType);
186 size_t read(
size_t index, ElementType* buffer,
size_t count)
const
188 auto offset = index *
sizeof(ElementType);
189 count *=
sizeof(ElementType);
200 size_t readFlash(
size_t index, ElementType* buffer,
size_t count)
const
202 auto offset = index *
sizeof(ElementType);
203 count *=
sizeof(ElementType);
Used when defining data structures.
Definition: ObjectBase.hpp:33
size_t read(size_t offset, void *buffer, size_t count) const
Read contents of a String into RAM.
constexpr const ObjectType & as() const
Cast to a different object type.
Definition: ObjectBase.hpp:60
constexpr size_t length() const
Get the length of the object data in bytes.
Definition: ObjectBase.hpp:38
const uint8_t * data() const
Get a pointer to the flash data.
static const ObjectBase empty_
Definition: ObjectBase.hpp:110
size_t readFlash(size_t offset, void *buffer, size_t count) const
Read contents of a String into RAM, using flashread()
Definition: ObjectIterator.hpp:29
Base class template for all types.
Definition: Object.hpp:101
Iterator begin() const
Definition: Object.hpp:116
size_t readFlash(size_t index, ElementType *buffer, size_t count) const
Read content into RAM,using flashmem_read()
Definition: Object.hpp:200
const ElementType * DataPtrType
Definition: Object.hpp:103
size_t read(size_t index, ElementType *buffer, size_t count) const
Read content into RAM.
Definition: Object.hpp:186
Object & operator=(const Object &&)=delete
size_t elementSize() const
Definition: Object.hpp:169
ElementType operator[](unsigned index) const
Array operator[].
Definition: Object.hpp:164
Object(const Object &&)=delete
constexpr size_t length() const
Get the length of the content in elements.
Definition: Object.hpp:137
ElementType valueAt(unsigned index) const
Definition: Object.hpp:156
DataPtrType data() const
Definition: Object.hpp:174
ObjectIterator< ObjectType, ElementType > Iterator
Definition: Object.hpp:104
Iterator end() const
Definition: Object.hpp:121
ElementType unsafeValueAt(const DataPtrType dataptr, unsigned index) const
Definition: Object.hpp:207
int indexOf(const ValueType &value) const
Definition: Object.hpp:142
Object(const Object &)=delete
static constexpr const ObjectType & empty()
Return an empty object which evaluates to null.
Definition: Object.hpp:129
Object & operator=(const Object &)=delete
#define FSTR_INLINE
Definition: config.hpp:28
ObjectType
Definition: ObjectInfo.h:32
Definition: Array.hpp:118
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:134