diff options
author | Hop311 <Hop3114@gmail.com> | 2024-04-15 21:00:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-15 21:00:34 +0200 |
commit | a5695934109559c57eae807a581cdc7f754764c1 (patch) | |
tree | 64f5ad5e2042dd0e2ebb4995b2e78de28af9f54e /src/openvic-simulation/types/IdentifierRegistry.hpp | |
parent | 8f97145e9570a9b728010a818137cb31a51fd5f6 (diff) | |
parent | b358fc0d4250178fbb44fc6b00cf4e39aa870064 (diff) |
Merge pull request #156 from OpenVicProject/gfx-actor
GFX::Actor rework + default GraphicalCultureType + default unit colours
Diffstat (limited to 'src/openvic-simulation/types/IdentifierRegistry.hpp')
-rw-r--r-- | src/openvic-simulation/types/IdentifierRegistry.hpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/openvic-simulation/types/IdentifierRegistry.hpp b/src/openvic-simulation/types/IdentifierRegistry.hpp index c1fef9d..533273a 100644 --- a/src/openvic-simulation/types/IdentifierRegistry.hpp +++ b/src/openvic-simulation/types/IdentifierRegistry.hpp @@ -269,6 +269,23 @@ namespace OpenVic { } \ return nullptr; \ } \ + template<std::derived_from<external_value_type> T> \ + requires requires(external_value_type const& value) { \ + { value.get_type() } -> std::same_as<std::string_view>; \ + { T::get_type_static() } -> std::same_as<std::string_view>; \ + } \ + constexpr T CONST* get_cast_item_by_identifier(std::string_view identifier) CONST { \ + external_value_type CONST* item = get_item_by_identifier(identifier); \ + if (item != nullptr) { \ + if (item->get_type() == T::get_type_static()) { \ + return reinterpret_cast<T CONST*>(item); \ + } \ + Logger::error( \ + "Invalid type for item \"", identifier, "\": ", item->get_type(), " (expected ", T::get_type_static(), ")" \ + ); \ + } \ + return nullptr; \ + } \ constexpr external_value_type CONST* get_item_by_index(std::size_t index) CONST { \ if (index < items.size()) { \ return std::addressof(ValueInfo::get_external_value(ItemInfo::get_value(items[index]))); \ @@ -565,6 +582,10 @@ private: constexpr decltype(registry)::external_value_type const_kw* get_##singular##_by_identifier(std::string_view identifier) const_kw { \ return registry.get_item_by_identifier(identifier); \ } \ + template<std::derived_from<decltype(registry)::external_value_type> T> \ + constexpr T const_kw* get_cast_##singular##_by_identifier(std::string_view identifier) const_kw { \ + return registry.get_cast_item_by_identifier<T>(identifier); \ + } \ constexpr decltype(registry)::external_value_type const_kw* get_##singular##_by_index(std::size_t index) const_kw { \ return index >= index_offset ? registry.get_item_by_index(index - index_offset) : nullptr; \ } \ |