Lodestone.Conversion
Loading...
Searching...
No Matches
RegistryRelations.h
Go to the documentation of this file.
1//
2// Created by DexrnZacAttack on 2/14/26 using zPc-i2.
3//
4#ifndef LODESTONE_IORELATIONS_H
5#define LODESTONE_IORELATIONS_H
8
9#include <type_traits>
10
12
19 template<const common::registry::Identifier *_InternalIdentifier, typename _Type, const common::registry::Identifier *_RegistryIdentifier, typename _Registry>
21 static constexpr const common::registry::Identifier *InternalIdentifier = _InternalIdentifier; // NOLINT
22 static constexpr const common::registry::Identifier *RegistryIdentifier = _RegistryIdentifier; // NOLINT
23 using Type = _Type;
24 using Registry = _Registry;
25 };
26
27 template <typename... C>
29 public:
30 template<typename T>
31 T* getAsByRelation(const common::registry::Identifier *identifier) const requires (std::is_base_of_v<io::IObjectIO, typename C::Type> && ...) {
32 static_assert((std::is_same_v<T, typename C::Type> || ...), "Given type was never registered in this relation");
33
34 return (C::Registry::getInstance().template getAs<T>(*identifier), ...);
35 }
36
37 template<typename T, const common::registry::Identifier *_InternalIdentifier>
38 T* getAsByRelation() const requires (std::is_base_of_v<io::IObjectIO, typename C::Type> && ...) {
39 static_assert(((_InternalIdentifier == C::InternalIdentifier) || ...), "Given identifier was never registered in this relation");
40 static_assert((std::is_same_v<T, typename C::Type> || ...), "Given type was never registered in this relation");
41
42 return getInternal<T, _InternalIdentifier, C...>();
43 }
44
45 template<const common::registry::Identifier *_InternalIdentifier>
46 io::IObjectIO* getByRelation() const requires (std::is_base_of_v<io::IObjectIO, typename C::Type> && ...) {
47 static_assert(((_InternalIdentifier == C::InternalIdentifier) || ...), "Given identifier was never registered in this relation");
48
49 return (C::Registry::getInstance().get(*C::RegistryIdentifier), ...);
50 }
51
52 io::IObjectIO* getByRelation(const common::registry::Identifier *identifier) const requires (std::is_base_of_v<io::IObjectIO, typename C::Type> && ...) {
53 return this->template getByRelation<identifier>();
54 }
55 private:
56 template<typename T, const common::registry::Identifier* _InternalIdentifier, typename Current, typename... Rest>
57 T* getInternal() const {
58 // array from temu
59 if constexpr (_InternalIdentifier == Current::InternalIdentifier) {
60 static_assert(std::is_same_v<T, typename Current::Type>, "Wrong type for given identifier");
61
62 //we have our id
63 return Current::Registry::getInstance().template getAs<T>(*Current::RegistryIdentifier);
64 } else {
65 if constexpr (sizeof...(Rest) <= 0) {
66 //we hit the end of the array
67 static_assert(sizeof...(Rest) > 0, "Given identifier was never registered in this relation");
68 return nullptr;
69 }
70
71 // continue onto next value
72 return getInternal<T, _InternalIdentifier, Rest...>();
73 }
74 }
75 };
76}
77
78#endif // LODESTONE_IORELATIONS_H
T * getAsByRelation() const
Definition RegistryRelations.h:38
T * getAsByRelation(const common::registry::Identifier *identifier) const
Definition RegistryRelations.h:31
T * getInternal() const
Definition RegistryRelations.h:57
io::IObjectIO * getByRelation(const common::registry::Identifier *identifier) const
Definition RegistryRelations.h:52
io::IObjectIO * getByRelation() const
Definition RegistryRelations.h:46
Definition AbstractObjectIo.h:20
Definition Registries.cpp:14
STL namespace.
Definition IObjectIo.h:10
_Registry Registry
Definition RegistryRelations.h:24
static constexpr const common::registry::Identifier * RegistryIdentifier
Definition RegistryRelations.h:22
static constexpr const common::registry::Identifier * InternalIdentifier
Definition RegistryRelations.h:21