diff options
author | Hop311 <Hop3114@gmail.com> | 2023-12-27 21:40:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-27 21:40:01 +0100 |
commit | 0d9343e62575b5b7968beea2d36f15541e2351e2 (patch) | |
tree | 78e0431edc32edb50be206ad78064eb28879342a /src/openvic-simulation/map/Map.hpp | |
parent | cc808c115d8ec6c7b6e47db47f81395b4d52941f (diff) | |
parent | 86e558e69aa5c34395d5f3b17566cf5ad2731af5 (diff) |
Merge pull request #109 from OpenVicProject/const-province-set
Made ProvinceSet use Province const* and updated Region loading
Diffstat (limited to 'src/openvic-simulation/map/Map.hpp')
-rw-r--r-- | src/openvic-simulation/map/Map.hpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/openvic-simulation/map/Map.hpp b/src/openvic-simulation/map/Map.hpp index e477b38..523a8e7 100644 --- a/src/openvic-simulation/map/Map.hpp +++ b/src/openvic-simulation/map/Map.hpp @@ -87,6 +87,15 @@ namespace OpenVic { bool add_province(std::string_view identifier, colour_t colour); IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS_CUSTOM_INDEX_OFFSET(province, 1); + /* This provides a safe way to remove the const qualifier of a Province const*, via a non-const Map. + * It uses a const_cast (the fastest/simplest solution), but this could also be done without it by looking up the + * Province* using the Province const*'s index. Requiring a non-const Map ensures that this function can only be + * used where the Province* could already be accessed by other means, such as the index method, preventing + * misleading code, or in the worst case undefined behaviour. */ + constexpr Province* remove_province_const(Province const* province) { + return const_cast<Province*>(province); + } + bool set_water_province(std::string_view identifier); bool set_water_province_list(std::vector<std::string_view> const& list); void lock_water_provinces(); @@ -97,8 +106,7 @@ namespace OpenVic { Province* get_selected_province(); Province::index_t get_selected_province_index() const; - bool add_region(std::string_view identifier, std::vector<std::string_view> const& province_identifiers); - IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS(region) + bool add_region(std::string_view identifier, Region::provinces_t const& provinces); bool add_mapmode(std::string_view identifier, Mapmode::colour_func_t colour_func); |