22static const char *
const TAG =
"mapping";
24template<
typename K,
typename V>
class Mapping {
29 using key_t =
const std::conditional_t<std::is_same_v<K, std::string>,
32 using value_t = std::conditional_t<std::is_same_v<V, std::string>,
36 void set(
const K &key,
const V &value) { this->
map_[
key_t{key}] = value; }
38 V
get(
const K &key)
const {
40 if (it != this->
map_.end()) {
43 if constexpr (std::is_pointer_v<K>) {
44 esph_log_e(TAG,
"Key '%p' not found in mapping", key);
45 }
else if constexpr (std::is_same_v<K, std::string>) {
46 esph_log_e(TAG,
"Key '%s' not found in mapping", key.c_str());
47 }
else if constexpr (std::is_integral_v<K>) {
49 if constexpr (std::is_unsigned_v<K>) {
50 buf_append_printf(buf,
sizeof(buf), 0,
"%" PRIu64,
static_cast<uint64_t
>(key));
52 buf_append_printf(buf,
sizeof(buf), 0,
"%" PRId64,
static_cast<int64_t
>(key));
54 esph_log_e(TAG,
"Key '%s' not found in mapping", buf);
57 static_assert(
sizeof(K) == 0,
"Unsupported key type for Mapping error logging");
66 template<
typename T = V, std::enable_if_t<std::is_same_v<T, std::
string>,
int> = 0>
69 if (it != this->
map_.end()) {
70 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