From e1229e05aba7554363b2aa9874bd383b5923ee8b Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Mon, 25 Mar 2024 23:28:26 +0100 Subject: Basic console API & API registry implementation --- deimos/core/api_registry.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'deimos/core/api_registry.cpp') diff --git a/deimos/core/api_registry.cpp b/deimos/core/api_registry.cpp index 873d72d..1489484 100644 --- a/deimos/core/api_registry.cpp +++ b/deimos/core/api_registry.cpp @@ -7,6 +7,7 @@ namespace deimos { AllocatorApi* BootstrapAllocatorApi(); +void RegisterOsApi(ApiRegistry*); struct ApiEntry { @@ -22,6 +23,7 @@ struct ApiEntry class ApiRegistryImpl: public ApiRegistry { Allocator* m_allocator; + const ApiEntry* m_head{}; public: explicit ApiRegistryImpl(Allocator* allocator) : @@ -30,9 +32,17 @@ public: void Set(const IdName& name, void* impl) final { - (void)name; - (void)impl; - (void)m_allocator; + auto* entry = m_allocator->New(name, impl); + entry->next = std::exchange(m_head, entry); + } + + void* Get(const IdName& name) final + { + for (const ApiEntry* it = m_head; it != nullptr; it = it->next) + { + if (it->name == name) { return it->impl; } + } + return nullptr; } }; @@ -45,6 +55,8 @@ ApiRegistry* InitializeGlobalApiRegistry() api_registry->Set(g_allocator_api); + RegisterOsApi(api_registry); + return api_registry; } -- cgit