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 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 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 (sizeof((const FSTR::MapPair<KeyType, ContentType>[]){__VA_ARGS__}) / \ 93 sizeof(FSTR::MapPair<KeyType, ContentType>)), \ 104 #define DEFINE_FSTR_MAP_DATA_SIZED(name, KeyType, ContentType, size, ...) \ 105 constexpr const struct { \ 106 FSTR::ObjectBase object; \ 107 FSTR::MapPair<KeyType, ContentType> data[size]; \ 108 } FSTR_PACKED FSTR_ALIGNED name PROGMEM = {{sizeof(name.data)}, {__VA_ARGS__}}; \ 109 FSTR_CHECK_STRUCT(name); 118 template <
typename KeyType,
class ContentType,
class Pair = MapPair<KeyType, ContentType>>
119 class Map :
public Object<Map<KeyType, ContentType>, Pair>
128 if(index >= this->
length()) {
129 return Pair::empty();
132 static_assert(offsetof(Pair, content_) ==
sizeof(uint32_t),
"Misaligned MapPair");
134 auto ptr = this->
data() + index;
143 template <
typename TRefKey,
typename T = KeyType>
144 typename std::enable_if<!std::is_class<T>::value,
int>::type
indexOf(
const TRefKey&
key)
const 146 auto p = this->
data();
147 auto len = this->
length();
148 for(
unsigned i = 0; i < len; ++i, ++p) {
149 if(p->key() ==
key) {
163 template <
typename TRefKey,
typename T = KeyType>
164 typename std::enable_if<std::is_same<T, String>::value,
int>::type
indexOf(
const TRefKey&
key,
165 bool ignoreCase =
true)
const 167 auto p = this->
data();
168 auto len = this->
length();
169 for(
unsigned i = 0; i < len; ++i, ++p) {
171 if(p->key().equalsIgnoreCase(key)) {
174 }
else if(p->key() ==
key) {
size_t printTo(Print &p) const
Definition: Map.hpp:203
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:164
MapPrinter< Map > printer() const
Returns a printer object for this array.
Definition: Map.hpp:198
size_t length() const
Get the length of the content in elements.
Definition: Object.hpp:164
Class template to access an associative map.
Definition: Map.hpp:119
Provides formatted output to stream.
Definition: Print.h:36
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
void size_t const void * key
Definition: blake2s.h:33
const Pair valueAt(unsigned index) const
Get a map entry by index, if it exists.
Definition: Map.hpp:126
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:144
const Pair operator[](const TRefKey &key) const
Lookup a key and return the entry, if found.
Definition: Map.hpp:187
Class template to provide a simple way to print the contents of a Map.
Definition: MapPrinter.hpp:30
Definition: Array.hpp:107
const Pair * data() const
Definition: Object.hpp:203