42 #define DECLARE_FSTR_MAP(name, KeyType, ContentType) DECLARE_FSTR_OBJECT(name, DECL((FSTR::Map<KeyType, ContentType>)))
52 #define DEFINE_FSTR_MAP(name, KeyType, ContentType, ...) \
53 static DEFINE_FSTR_MAP_DATA(FSTR_DATA_NAME(name), KeyType, ContentType, __VA_ARGS__); \
54 DEFINE_FSTR_REF_NAMED(name, DECL((FSTR::Map<KeyType, ContentType>)));
59 #define DEFINE_FSTR_MAP_LOCAL(name, KeyType, ContentType, ...) \
60 static DEFINE_FSTR_MAP_DATA(FSTR_DATA_NAME(name), KeyType, ContentType, __VA_ARGS__); \
61 static FSTR_CONSTEXPR DEFINE_FSTR_REF_NAMED(name, DECL((FSTR::Map<KeyType, ContentType>)));
71 #define DEFINE_FSTR_MAP_SIZED(name, KeyType, ContentType, size, ...) \
72 static DEFINE_FSTR_MAP_DATA_SIZED(FSTR_DATA_NAME(name), KeyType, ContentType, size, __VA_ARGS__); \
73 DEFINE_FSTR_REF_NAMED(name, DECL((FSTR::Map<KeyType, ContentType>)));
78 #define DEFINE_FSTR_MAP_SIZED_LOCAL(name, KeyType, ContentType, size, ...) \
79 static DEFINE_FSTR_MAP_DATA_SIZED(FSTR_DATA_NAME(name), KeyType, ContentType, size, __VA_ARGS__); \
80 static FSTR_CONSTEXPR DEFINE_FSTR_REF_NAMED(name, DECL((FSTR::Map<KeyType, ContentType>)));
90 #define DEFINE_FSTR_MAP_DATA(name, KeyType, ContentType, ...) \
91 DEFINE_FSTR_MAP_DATA_SIZED(name, KeyType, ContentType, \
92 FSTR_VA_NARGS(DECL((FSTR::MapPair<KeyType, ContentType>)), __VA_ARGS__), __VA_ARGS__)
102 #define DEFINE_FSTR_MAP_DATA_SIZED(name, KeyType, ContentType, size, ...) \
103 FSTR_CONSTEXPR const struct { \
104 FSTR::ObjectBase object; \
105 FSTR::MapPair<KeyType, ContentType> data[size]; \
106 } FSTR_PACKED FSTR_ALIGNED name PROGMEM = {{sizeof(name.data)}, {__VA_ARGS__}}; \
107 FSTR_CHECK_STRUCT(name);
116 template <
typename KeyType,
class ContentType,
class Pair = MapPair<KeyType, ContentType>>
117 class Map :
public Object<Map<KeyType, ContentType>, Pair>
126 if(index >= this->
length()) {
127 return Pair::empty();
130 static_assert(offsetof(Pair, content_) ==
sizeof(uint32_t),
"Misaligned MapPair");
132 auto ptr = this->
data() + index;
141 template <
typename TRefKey,
typename T = KeyType>
142 typename std::enable_if<!std::is_class<T>::value,
int>::type
indexOf(
const TRefKey&
key)
const
144 auto p = this->
data();
145 auto len = this->
length();
146 for(
unsigned i = 0; i < len; ++i, ++p) {
147 if(p->key() ==
key) {
161 template <
typename TRefKey,
typename T = KeyType>
162 typename std::enable_if<std::is_same<T, String>::value,
int>::type
indexOf(
const TRefKey&
key,
163 bool ignoreCase =
true)
const
165 auto p = this->
data();
166 auto len = this->
length();
167 for(
unsigned i = 0; i < len; ++i, ++p) {
169 if(p->key().equalsIgnoreCase(
key)) {
172 }
else if(p->key() ==
key) {
void size_t const void * key
Definition: blake2s.h:33
Class template to provide a simple way to print the contents of a Map.
Definition: MapPrinter.hpp:31
Class template to access an associative map.
Definition: Map.hpp:118
std::enable_if< std::is_same< T, String >::value, int >::type indexOf(const TRefKey &key, bool ignoreCase=true) const
Lookup a String key and return the index.
Definition: Map.hpp:162
const Pair operator[](const TRefKey &key) const
Lookup a key and return the entry, if found.
Definition: Map.hpp:185
const Pair valueAt(unsigned index) const
Get a map entry by index, if it exists.
Definition: Map.hpp:124
MapPrinter< Map > printer() const
Returns a printer object for this array.
Definition: Map.hpp:196
size_t printTo(Print &p) const
Definition: Map.hpp:201
std::enable_if<!std::is_class< T >::value, int >::type indexOf(const TRefKey &key) const
Lookup an integral key and return the index.
Definition: Map.hpp:142
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
Provides formatted output to stream.
Definition: Print.h:37
Definition: Array.hpp:108
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:126