Lodestone.Conversion
Loading...
Searching...
No Matches
SimpleRegistry.tpp
Go to the documentation of this file.
1//
2// Created by DexrnZacAttack on 2/14/26 using zPc-i2.
3//
4#ifndef LODESTONE_SIMPLEREGISTRY_TPP
5#define LODESTONE_SIMPLEREGISTRY_TPP
6
7template <const common::registry::Identifier *Identifier, typename Type, typename Stored>
8void SimpleRegistry<Identifier, Type, Stored>::put(const common::registry::Identifier &id, Stored io) {
9 if (this->m_registry.contains(id))
10 throw std::runtime_error(
11 std::format("{} '{}' is already registered", Identifier->getString(), id));
12
13 this->m_registry[id] = std::move(io);
14
15 // LOG_DEBUG("Registered " << Identifier->getString() << " '" << id << "'");
16 objectRegisteredEvent.notify(id);
17}
18
19template <const common::registry::Identifier *Identifier, typename Type, typename Stored>
20const Type *SimpleRegistry<Identifier, Type, Stored>::get(common::registry::Identifier id) const {
21 if (const auto it = m_registry.find(id);
22 it != m_registry.end())
23 return it->second.get();
24
25 LOG_DEBUG("Attempted to get value from nonexistent key '" << Identifier->getString() << "'");
26 return nullptr;
27}
28
29template <const common::registry::Identifier *Identifier, typename Type, typename Stored>
30template<typename R>
31requires std::is_base_of_v<Type, R>
32const R *SimpleRegistry<Identifier, Type, Stored>::getAs(const common::registry::Identifier id) const {
33 return dynamic_cast<R *>(this->get(id));
34}
35
36template <const common::registry::Identifier *Identifier, typename Type, typename Stored>
37template<typename R> requires std::is_base_of_v<Type, R>
38 && std::is_base_of_v<common::registry::IIdentifiable, R>
39const R * SimpleRegistry<Identifier, Type, Stored>::getOfType() const {
40 return this->getAs<R>(*R::getIdentifier());
41}
42
43#endif // LODESTONE_SIMPLEREGISTRY_TPP