36#ifndef _UTILS_NODEHANDLERMAP_HXX_
37#define _UTILS_NODEHANDLERMAP_HXX_
47#if UINTPTR_MAX > UINT32_MAX
48#define NODEHANDLER_USE_PAIR
64#ifdef NODEHANDLER_USE_PAIR
66 typedef std::pair<void*, uint32_t>
key_type;
91 void insert(
void* node, uint32_t
id,
void* value)
102 void erase(
void *node, uint32_t
id,
void *value)
106 if (it->second == value) {
151#ifdef NODEHANDLER_USE_PAIR
154 uint32_t
id = key & 0xFFFFFFFFU;
155 uint32_t n = key >> 32;
156 return std::make_pair(
reinterpret_cast<void *
>(n),
id);
164#ifdef NODEHANDLER_USE_PAIR
165 return std::make_pair(node,
id);
167 uint64_t key =
reinterpret_cast<uint32_t
>(node);
180template <
class Node,
class Handler>
244 std::pair<std::pair<Node*, uint32_t>, Handler*>
operator*() {
246 return std::make_pair(std::make_pair((
Node*) p.first, p.second),
247 (Handler*)
impl_->second);
A map that allows registration and lookup or per-node handler of a particular message ID.
key_type make_key(void *node, uint32_t id)
Combines the node pointer and the message ID into a lookup key.
uint64_t key_type
Compacted payload type.
void insert(void *node, uint32_t id, void *value)
Inserts a handler into the map.
static pair< void *, uint32_t > read_key(key_type key)
Decodes a compact key into a pair.
NodeHandlerMapBase(size_t entries)
Creates a map with.
void * value_type
Generic handler type that we'll keep.
StlMap< key_type, value_type > map_type
Type of the storage object.
void erase(void *node, uint32_t id, void *value)
Removes a handlerfrom this map.
map_type::Iterator iterator
Iterator type.
void * lookup(void *node, uint32_t id)
Finds a handler for a particular node and particular messageID.
map_type entries_
The actual storage object.
Though at the surface, this may seem like an unnecessary abstraction of std::map, it has the purpose ...
std::map< key_type, value_type >::iterator Iterator
Short hand for the iterator type of a given instance.
Iterator end()
Get an iterator index pointing one past the last element in mapping.
size_t erase(Key key)
Remove an element from the tree.
Iterator begin()
Get an iterator index pointing one past the last element in mapping.
Iterator find(const Key &key)
Find an element matching the given key.
Type-safe iterator for NodeHandlerMap.
NodeHandlerMapBase::iterator impl_
untyped iterator
bool operator!=(const iterator &o)
iterator(NodeHandlerMapBase::iterator i)
std::pair< std::pair< Node *, uint32_t >, Handler * > operator*()
Dereference.
A type-safe map that allows registration and lookup or per-node handler of a particular message ID.
void insert(Node *node, uint32_t id, Handler *handler)
Inserts a handler into the map.
TypedNodeHandlerMap(size_t entries)
void erase(Node *node, uint32_t id, Handler *handler)
Removes a handler from the map.
Handler * lookup(Node *node, uint32_t id)
Finds a handler for a particular node and particular messageID.