#pragma once #include "servers/base_server.hpp" #include namespace demonware { template class server_registry { static_assert(std::is_base_of::value, "Invalid server registry type"); public: template void create(Args&&... args) { static_assert(std::is_base_of::value, "Invalid server type"); auto server = std::make_unique(std::forward(args)...); const auto address = server->get_address(); servers_[address] = std::move(server); } void for_each(const std::function& callback) const { for (auto& server : servers_) { callback(*server.second); } } T* find(const std::string& name) { const auto address = utilities::cryptography::jenkins_one_at_a_time::compute(name); return find(address); } T* find(const uint32_t address) { const auto it = servers_.find(address); if (it == servers_.end()) { return nullptr; } return it->second.get(); } void frame() { for (auto& server : servers_) { server.second->frame(); } } private: std::unordered_map> servers_; }; }