#pragma once #include #include #include #include #include #include class ConnectionRegistry { public: using connection = std::shared_ptr>; ConnectionRegistry() = default; ~ConnectionRegistry() = default; void setId(connection c, const std::string& id); // used via RegistryGuard void addConnection(connection c); void delConnection(connection c); // map connection to id std::unordered_map m_connections; // map id to list of related connections, used for iteration over connections to notify about changes std::unordered_map> m_ids; std::unordered_set::iterator begin(const std::string& id); std::unordered_set::iterator end(const std::string& id); void dump() const; class RegistryGuard { public: RegistryGuard(ConnectionRegistry& registry, connection c); ~RegistryGuard(); private: ConnectionRegistry& m_registry; connection m_connection; }; };