5#include <unordered_map>
27std::unordered_map<std::string, Slot>& slots() {
28 static std::unordered_map<std::string, Slot> table;
40 if (!
name)
return nullptr;
41 auto& table = slots();
42 auto it = table.find(
name);
43 return it == table.end() ?
nullptr :
it->second.service;
48 auto& table = slots();
49 auto it = table.find(
name);
52 if (
it != table.end() &&
it->second.service ==
impl)
it->second.service =
nullptr;
57 auto& list = slots()[
name].listeners;
58 for (
const auto&
l : list)
59 if (
l.impl ==
impl)
return;
62 std::stable_sort(list.begin(), list.end(),
63 [](
const Listener&
a,
const Listener&
b) { return a.priority < b.priority; });
68 auto& table = slots();
69 auto it = table.find(
name);
70 if (
it == table.end())
return;
71 auto& list =
it->second.listeners;
72 list.erase(std::remove_if(list.begin(), list.end(),
73 [
impl](
const Listener&
l) { return l.impl == impl; }),
79 auto& table = slots();
80 auto it = table.find(
name);
81 return it == table.end() ? 0 :
it->second.listeners.size();
85 if (!
name)
return nullptr;
86 auto& table = slots();
87 auto it = table.find(
name);
88 if (
it == table.end() || index >=
it->second.listeners.size())
return nullptr;
89 return it->second.listeners[index].impl;
std::vector< Listener > listeners
void addListenerRaw(const char *name, void *impl, int priority)
void provideRaw(const char *name, void *impl)
void * queryRaw(const char *name)
void * listenerAtRaw(const char *name, size_t index)
void revokeRaw(const char *name, void *impl)
size_t listenerCountRaw(const char *name)
void removeListenerRaw(const char *name, void *impl)