21static const char *
const TAG =
"mapping";
23template<
typename K,
typename V>
class Mapping {
28 using key_t =
const std::conditional_t<std::is_same_v<K, std::string>,
31 using value_t = std::conditional_t<std::is_same_v<V, std::string>,
35 void set(
const K &key,
const V &value) { this->
map_[
key_t{key}] = value; }
37 V
get(
const K &key)
const {
39 if (it != this->
map_.end()) {
42 if constexpr (std::is_pointer_v<K>) {
43 esph_log_e(TAG,
"Key '%p' not found in mapping", key);
44 }
else if constexpr (std::is_same_v<K, std::string>) {
45 esph_log_e(TAG,
"Key '%s' not found in mapping", key.c_str());
47 esph_log_e(TAG,
"Key '%s' not found in mapping", to_string(key).c_str());
56 template<
typename T = V, std::enable_if_t<std::is_same_v<T, std::
string>,
int> = 0>
59 if (it != this->
map_.end()) {
60 return it->second.c_str();
An STL allocator that uses SPI or internal RAM.
const char * operator[](K key) const
void set(const K &key, const V &value)
std::conditional_t< std::is_same_v< V, std::string >, alloc_string_t, V > value_t
const std::conditional_t< std::is_same_v< K, std::string >, alloc_string_t, K > key_t
V get(const K &key) const
std::map< key_t, value_t, std::less< key_t >, RAMAllocator< std::pair< key_t, value_t > > > map_
std::basic_string< char, std::char_traits< char >, RAMAllocator< char > > alloc_string_t