diff options
author | hop311 <hop3114@gmail.com> | 2023-12-02 16:48:08 +0100 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2023-12-02 20:14:29 +0100 |
commit | 4a899c1a9e83ab9476b85522751081be434caa35 (patch) | |
tree | f1f6276c91beceecdfd9b09083d1c91ea8b41b60 /src/openvic-simulation/types/IdentifierRegistry.hpp | |
parent | cd6875d5e0ca5e2545fd0e1647678cd18a6c81c2 (diff) |
Crime+event modifier loading + misc UI backend
Diffstat (limited to 'src/openvic-simulation/types/IdentifierRegistry.hpp')
-rw-r--r-- | src/openvic-simulation/types/IdentifierRegistry.hpp | 86 |
1 files changed, 56 insertions, 30 deletions
diff --git a/src/openvic-simulation/types/IdentifierRegistry.hpp b/src/openvic-simulation/types/IdentifierRegistry.hpp index 072ab07..cfb4fed 100644 --- a/src/openvic-simulation/types/IdentifierRegistry.hpp +++ b/src/openvic-simulation/types/IdentifierRegistry.hpp @@ -197,7 +197,7 @@ namespace OpenVic { return nullptr; \ } \ value_type CONST* get_item_by_index(size_t index) CONST { \ - return index < items.size() ? &items[index] : nullptr; \ + return index < items.size() ? GetPointer(items[index]) : nullptr; \ } \ NodeTools::callback_t<std::string_view> expect_item_str( \ NodeTools::callback_t<value_type CONST&> callback, bool warn \ @@ -315,72 +315,98 @@ namespace OpenVic { template<std::derived_from<HasIdentifier> _Type> using IdentifierInstanceRegistry = InstanceRegistry<_Type, _get_identifier<_Type>>; +/* Member functions for const access to a UniqueKeyRegistry member variable. */ +#define IDENTIFIER_REGISTRY_ACCESSORS(name) \ + IDENTIFIER_REGISTRY_ACCESSORS_CUSTOM_PLURAL(name, name##s) + #define IDENTIFIER_REGISTRY_ACCESSORS_CUSTOM_PLURAL(singular, plural) \ + IDENTIFIER_REGISTRY_ACCESSORS_FULL_CUSTOM(singular, plural, plural, 0) + +#define IDENTIFIER_REGISTRY_ACCESSORS_CUSTOM_INDEX_OFFSET(name, index_offset) \ + IDENTIFIER_REGISTRY_ACCESSORS_FULL_CUSTOM(name, name##s, name##s, index_offset) + +#define IDENTIFIER_REGISTRY_ACCESSORS_FULL_CUSTOM(singular, plural, registry, index_offset) \ void lock_##plural() { \ - plural.lock(); \ + registry.lock(); \ } \ bool plural##_are_locked() const { \ - return plural.is_locked(); \ + return registry.is_locked(); \ } \ - decltype(plural)::value_type const* get_##singular##_by_identifier(std::string_view identifier) const { \ - return plural.get_item_by_identifier(identifier); \ + decltype(registry)::value_type const* get_##singular##_by_identifier(std::string_view identifier) const { \ + return registry.get_item_by_identifier(identifier); \ } \ bool has_##singular##_identifier(std::string_view identifier) const { \ - return plural.has_identifier(identifier); \ + return registry.has_identifier(identifier); \ + } \ + decltype(registry)::value_type const* get_##singular##_by_index(size_t index) const { \ + return index >= index_offset ? registry.get_item_by_index(index - index_offset) : nullptr; \ } \ size_t get_##singular##_count() const { \ - return plural.size(); \ + return registry.size(); \ } \ bool plural##_empty() const { \ - return plural.empty(); \ + return registry.empty(); \ } \ - std::vector<decltype(plural)::storage_type> const& get_##plural() const { \ - return plural.get_items(); \ + std::vector<decltype(registry)::storage_type> const& get_##plural() const { \ + return registry.get_items(); \ } \ std::vector<std::string_view> get_##singular##_identifiers() const { \ - return plural.get_item_identifiers(); \ + return registry.get_item_identifiers(); \ } \ NodeTools::callback_t<std::string_view> expect_##singular##_str( \ - NodeTools::callback_t<decltype(plural)::value_type const&> callback, bool warn = false \ + NodeTools::callback_t<decltype(registry)::value_type const&> callback, bool warn = false \ ) const { \ - return plural.expect_item_str(callback, warn); \ + return registry.expect_item_str(callback, warn); \ } \ NodeTools::node_callback_t expect_##singular##_identifier( \ - NodeTools::callback_t<decltype(plural)::value_type const&> callback, bool warn = false \ + NodeTools::callback_t<decltype(registry)::value_type const&> callback, bool warn = false \ ) const { \ - return plural.expect_item_identifier(callback, warn); \ + return registry.expect_item_identifier(callback, warn); \ } \ NodeTools::node_callback_t expect_##singular##_dictionary( \ - NodeTools::callback_t<decltype(plural)::value_type const&, ast::NodeCPtr> callback \ + NodeTools::callback_t<decltype(registry)::value_type const&, ast::NodeCPtr> callback \ ) const { \ - return plural.expect_item_dictionary(callback); \ + return registry.expect_item_dictionary(callback); \ } \ NodeTools::node_callback_t expect_##singular##_decimal_map( \ - NodeTools::callback_t<fixed_point_map_t<decltype(plural)::value_type const*>&&> callback \ + NodeTools::callback_t<fixed_point_map_t<decltype(registry)::value_type const*>&&> callback \ ) const { \ - return plural.expect_item_decimal_map(callback); \ + return registry.expect_item_decimal_map(callback); \ } +/* Member functions for non-const access to a UniqueKeyRegistry member variable. */ +#define IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS(name) \ + IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS_CUSTOM_PLURAL(name, name##s) + #define IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS_CUSTOM_PLURAL(singular, plural) \ - decltype(plural)::value_type* get_##singular##_by_identifier(std::string_view identifier) { \ - return plural.get_item_by_identifier(identifier); \ + IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS_FULL_CUSTOM(single, plural, plural, 0) + +#define IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS_CUSTOM_INDEX_OFFSET(name, index_offset) \ + IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS_FULL_CUSTOM(name, name##s, name##s, index_offset) + +#define IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS_FULL_CUSTOM(singular, plural, registry, index_offset) \ + decltype(registry)::value_type* get_##singular##_by_identifier(std::string_view identifier) { \ + return registry.get_item_by_identifier(identifier); \ + } \ + decltype(registry)::value_type* get_##singular##_by_index(size_t index) { \ + return index >= index_offset ? registry.get_item_by_index(index - index_offset) : nullptr; \ + } \ + std::vector<decltype(registry)::storage_type>& get_##plural() { \ + return registry.get_items(); \ } \ NodeTools::callback_t<std::string_view> expect_##singular##_str( \ - NodeTools::callback_t<decltype(plural)::value_type&> callback, bool warn = false \ + NodeTools::callback_t<decltype(registry)::value_type&> callback, bool warn = false \ ) { \ - return plural.expect_item_str(callback, warn); \ + return registry.expect_item_str(callback, warn); \ } \ NodeTools::node_callback_t expect_##singular##_identifier( \ - NodeTools::callback_t<decltype(plural)::value_type&> callback, bool warn = false \ + NodeTools::callback_t<decltype(registry)::value_type&> callback, bool warn = false \ ) { \ - return plural.expect_item_identifier(callback, warn); \ + return registry.expect_item_identifier(callback, warn); \ } \ NodeTools::node_callback_t expect_##singular##_dictionary( \ - NodeTools::callback_t<decltype(plural)::value_type&, ast::NodeCPtr> callback \ + NodeTools::callback_t<decltype(registry)::value_type&, ast::NodeCPtr> callback \ ) { \ - return plural.expect_item_dictionary(callback); \ + return registry.expect_item_dictionary(callback); \ } - -#define IDENTIFIER_REGISTRY_ACCESSORS(name) IDENTIFIER_REGISTRY_ACCESSORS_CUSTOM_PLURAL(name, name##s) -#define IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS(name) IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS_CUSTOM_PLURAL(name, name##s) } |