39 #define DECLARE_FSTR_VECTOR(name, ObjectType) DECLARE_FSTR_OBJECT(name, FSTR::Vector<ObjectType>)
48 #define DEFINE_FSTR_VECTOR(name, ObjectType, ...) \
49 static DEFINE_FSTR_VECTOR_DATA(FSTR_DATA_NAME(name), ObjectType, __VA_ARGS__); \
50 DEFINE_FSTR_REF_NAMED(name, FSTR::Vector<ObjectType>);
55 #define DEFINE_FSTR_VECTOR_LOCAL(name, ObjectType, ...) \
56 static DEFINE_FSTR_VECTOR_DATA(FSTR_DATA_NAME(name), ObjectType, __VA_ARGS__); \
57 static FSTR_CONSTEXPR DEFINE_FSTR_REF_NAMED(name, FSTR::Vector<ObjectType>);
67 #define DEFINE_FSTR_VECTOR_SIZED(name, ObjectType, size, ...) \
68 static DEFINE_FSTR_VECTOR_DATA_SIZED(FSTR_DATA_NAME(name), ObjectType, size, __VA_ARGS__); \
69 DEFINE_FSTR_REF_NAMED(name, FSTR::Vector<ObjectType>);
74 #define DEFINE_FSTR_VECTOR_SIZED_LOCAL(name, ObjectType, size, ...) \
75 static DEFINE_FSTR_VECTOR_DATA_SIZED(FSTR_DATA_NAME(name), ObjectType, size, __VA_ARGS__); \
76 static FSTR_CONSTEXPR DEFINE_FSTR_REF_NAMED(name, FSTR::Vector<ObjectType>);
85 #define DEFINE_FSTR_VECTOR_DATA(name, ObjectType, ...) \
86 DEFINE_FSTR_VECTOR_DATA_SIZED(name, ObjectType, FSTR_VA_NARGS(ObjectType*, __VA_ARGS__), __VA_ARGS__)
96 #define DEFINE_FSTR_VECTOR_DATA_SIZED(name, ObjectType, size, ...) \
97 FSTR_CONSTEXPR const struct { \
98 FSTR::ObjectBase object; \
99 const ObjectType* data[size]; \
100 } name PROGMEM = {{sizeof(name.data)}, {__VA_ARGS__}}; \
101 FSTR_CHECK_STRUCT(name);
109 template <
class ObjectType>
class Vector :
public Object<Vector<ObjectType>, const ObjectType*>
114 template <
typename ValueType,
typename T = ObjectType>
115 typename std::enable_if<!std::is_same<T, String>::value,
int>::type
indexOf(
const ValueType& value)
const
120 template <
typename T = ObjectType>
121 typename std::enable_if<std::is_same<T, String>::value,
int>::type
indexOf(
const char* value,
122 bool ignoreCase =
true)
const
124 auto dataptr = this->
data();
125 auto len = this->
length();
126 auto clen = strlen(value);
127 for(
unsigned i = 0; i < len; ++i) {
128 if(
unsafeValueAt(dataptr, i).equals(value, clen, ignoreCase)) {
136 template <
typename ValueType,
typename T = ObjectType>
137 typename std::enable_if<std::is_same<T, String>::value,
int>::type
indexOf(
const ValueType& value,
138 bool ignoreCase =
true)
const
140 auto dataptr = this->
data();
141 auto len = this->
length();
142 for(
unsigned i = 0; i < len; ++i) {
175 auto ptr = dataptr[index];
176 return ptr ? *ptr : ObjectType::empty();
Class template to provide a simple way to print the contents of an array.
Definition: ArrayPrinter.hpp:40
Base class template for all types.
Definition: Object.hpp:125
constexpr const size_t length() const
Get the length of the content in elements.
Definition: Object.hpp:180
DataPtrType data() const
Definition: Object.hpp:217
Class to access a Vector of objects stored in flash.
Definition: Vector.hpp:110
std::enable_if< std::is_same< T, String >::value, int >::type indexOf(const ValueType &value, bool ignoreCase=true) const
Definition: Vector.hpp:137
size_t printTo(Print &p) const
Definition: Vector.hpp:168
const ObjectType & operator[](unsigned index) const
Definition: Vector.hpp:156
std::enable_if<!std::is_same< T, String >::value, int >::type indexOf(const ValueType &value) const
Definition: Vector.hpp:115
std::enable_if< std::is_same< T, String >::value, int >::type indexOf(const char *value, bool ignoreCase=true) const
Definition: Vector.hpp:121
const ObjectType *const * DataPtrType
Definition: Vector.hpp:112
ArrayPrinter< Vector > printer() const
Definition: Vector.hpp:163
const ObjectType & valueAt(unsigned index) const
Definition: Vector.hpp:151
static const ObjectType & unsafeValueAt(const DataPtrType dataptr, unsigned index)
Definition: Vector.hpp:173
Provides formatted output to stream.
Definition: Print.h:37
#define FSTR_INLINE
Definition: config.hpp:28
Definition: Array.hpp:108
ObjectType
Definition: Libraries/jerryscript/src/include/Jerryscript/Types.h:34