From 14ba9531d118fab87b360db4aae765807fca3cec Mon Sep 17 00:00:00 2001 From: hop311 Date: Wed, 24 Jan 2024 23:28:09 +0000 Subject: Added StringMapCase and case insensitive expect_dictionary_keys --- .../types/IdentifierRegistry.hpp | 55 ++++++++-------------- 1 file changed, 19 insertions(+), 36 deletions(-) (limited to 'src/openvic-simulation/types/IdentifierRegistry.hpp') diff --git a/src/openvic-simulation/types/IdentifierRegistry.hpp b/src/openvic-simulation/types/IdentifierRegistry.hpp index 4d002e7..7e6fdb3 100644 --- a/src/openvic-simulation/types/IdentifierRegistry.hpp +++ b/src/openvic-simulation/types/IdentifierRegistry.hpp @@ -142,26 +142,11 @@ namespace OpenVic { } }; - /* Registry Identifier Map Info - how unique identifier strings are compared when looking up entries. */ - template - concept RegistryIdentifierMapInfo = requires(std::string_view identifier) { - { typename IdentifierMapInfo::hash {}(identifier) } -> std::same_as; - { typename IdentifierMapInfo::equal {}(identifier, identifier) } -> std::same_as; - }; - struct RegistryIdentifierMapInfoCaseSensitive { - using hash = container_hash; - using equal = std::equal_to<>; - }; - struct RegistryIdentifierMapInfoCaseInsensitive { - using hash = case_insensitive_string_hash; - using equal = case_insensitive_string_equal; - }; - template< RegistryValueInfo ValueInfo, /* The type that is being registered and that has unique string identifiers */ template typename _ItemInfo, /* How the type is being stored, usually either by value or std::unique_ptr */ template typename _StorageInfo = RegistryStorageInfoVector, /* How items are stored, including indexing type */ - RegistryIdentifierMapInfo IdentifierMapInfo = RegistryIdentifierMapInfoCaseSensitive /* Identifier map parameters */ + StringMapCase Case = StringMapCaseSensitive /* Identifier map parameters */ > requires( RegistryItemInfo<_ItemInfo, typename ValueInfo::internal_value_type> && @@ -177,8 +162,7 @@ namespace OpenVic { private: using StorageInfo = _StorageInfo; using index_type = typename StorageInfo::index_type; - using identifier_index_map_t = - string_map_t; + using identifier_index_map_t = template_string_map_t; public: using storage_type = typename StorageInfo::storage_type; @@ -440,50 +424,49 @@ namespace OpenVic { /* Item Specialisations */ template< RegistryValueInfo ValueInfo, template typename StorageInfo = RegistryStorageInfoVector, - RegistryIdentifierMapInfo IdentifierMapInfo = RegistryIdentifierMapInfoCaseSensitive + StringMapCase Case = StringMapCaseSensitive > - requires RegistryStorageInfo::item_type> - using ValueRegistry = UniqueKeyRegistry; + requires + RegistryStorageInfo::item_type> + using ValueRegistry = UniqueKeyRegistry; template< RegistryValueInfo ValueInfo, template typename StorageInfo = RegistryStorageInfoVector, - RegistryIdentifierMapInfo IdentifierMapInfo = RegistryIdentifierMapInfoCaseSensitive + StringMapCase Case = StringMapCaseSensitive > - requires RegistryStorageInfo::item_type> - using InstanceRegistry = UniqueKeyRegistry; + requires + RegistryStorageInfo::item_type> + using InstanceRegistry = UniqueKeyRegistry; /* HasIdentifier Specialisations */ template< std::derived_from Value, template typename StorageInfo = RegistryStorageInfoVector, - RegistryIdentifierMapInfo IdentifierMapInfo = RegistryIdentifierMapInfoCaseSensitive + StringMapCase Case = StringMapCaseSensitive > - using IdentifierRegistry = ValueRegistry, StorageInfo, IdentifierMapInfo>; + using IdentifierRegistry = ValueRegistry, StorageInfo, Case>; template< std::derived_from Value, template typename StorageInfo = RegistryStorageInfoVector, - RegistryIdentifierMapInfo IdentifierMapInfo = RegistryIdentifierMapInfoCaseSensitive + StringMapCase Case = StringMapCaseSensitive > using IdentifierPointerRegistry = - ValueRegistry>, StorageInfo, IdentifierMapInfo>; + ValueRegistry>, StorageInfo, Case>; template< std::derived_from Value, template typename StorageInfo = RegistryStorageInfoVector, - RegistryIdentifierMapInfo IdentifierMapInfo = RegistryIdentifierMapInfoCaseSensitive + StringMapCase Case = StringMapCaseSensitive > - using IdentifierInstanceRegistry = InstanceRegistry, StorageInfo, IdentifierMapInfo>; + using IdentifierInstanceRegistry = InstanceRegistry, StorageInfo, Case>; /* Case-Insensitive HasIdentifier Specialisations */ template Value, template typename StorageInfo = RegistryStorageInfoVector> - using CaseInsensitiveIdentifierRegistry = - IdentifierRegistry; + using CaseInsensitiveIdentifierRegistry = IdentifierRegistry; template Value, template typename StorageInfo = RegistryStorageInfoVector> - using CaseInsensitiveIdentifierPointerRegistry = - IdentifierPointerRegistry; + using CaseInsensitiveIdentifierPointerRegistry = IdentifierPointerRegistry; template Value, template typename StorageInfo = RegistryStorageInfoVector> - using CaseInsensitiveIdentifierInstanceRegistry = - IdentifierInstanceRegistry; + using CaseInsensitiveIdentifierInstanceRegistry = IdentifierInstanceRegistry; /* Macros to generate declaration and constant accessor methods for a UniqueKeyRegistry member variable. */ -- cgit v1.2.3-56-ga3b1