Skip to content

Commit 273d453

Browse files
committed
Permit private mutable registry functions
Add InventionManager as afriend of TechnologyManager Remove const_cast from `InventionManager::generate_invention_links` Remove non-const accessor registry function macros
1 parent e539ed7 commit 273d453

4 files changed

Lines changed: 9 additions & 18 deletions

File tree

src/openvic-simulation/map/MapDefinition.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ namespace OpenVic {
7676
return pos.x + pos.y * dims.x;
7777
}
7878

79-
IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS(province_definition);
8079
ProvinceDefinition* get_province_definition_from_number(
8180
const ProvinceDefinition::province_number_t province_number
8281
);

src/openvic-simulation/research/Invention.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ bool InventionManager::generate_invention_links(TechnologyManager& tech_manager)
146146

147147
for (Invention& invention : inventions.get_items()) {
148148
for (const memory::string& tech_id : invention.raw_associated_tech_identifiers) {
149-
Technology const* tech = tech_manager.get_technology_by_identifier(tech_id);
150-
if (tech) {
151-
auto* mutable_tech = const_cast<Technology*>(tech);
152-
mutable_tech->add_invention(&invention);
149+
Technology* tech = tech_manager.get_technology_by_identifier(tech_id);
150+
if (tech == nullptr) {
151+
continue;
153152
}
153+
tech->add_invention(&invention);
154154
}
155155

156156
invention.raw_associated_tech_identifiers.clear();

src/openvic-simulation/research/Technology.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ namespace OpenVic {
9696
};
9797

9898
struct TechnologyManager {
99+
friend struct InventionManager;
100+
99101
IdentifierRegistry<TechnologyFolder> IDENTIFIER_REGISTRY(technology_folder);
100102
IdentifierRegistry<TechnologyArea> IDENTIFIER_REGISTRY(technology_area);
101103
IdentifierRegistry<Technology> IDENTIFIER_REGISTRY_CUSTOM_PLURAL(technology, technologies);
@@ -132,4 +134,4 @@ namespace OpenVic {
132134

133135
bool parse_scripts(DefinitionManager const& definition_manager);
134136
};
135-
}
137+
}

src/openvic-simulation/types/IdentifierRegistry.hpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ namespace OpenVic {
245245
emplace_identifier_index();
246246
return true;
247247
}
248-
248+
249249
constexpr bool emplace_via_copy(item_type const& item_to_copy) {
250250
return emplace_item(
251251
ValueInfo::get_identifier(ItemInfo::get_value(item_to_copy)),
@@ -659,17 +659,7 @@ public: \
659659
return registry.expect_item_decimal_map(callback, fixed_point_functor); \
660660
} \
661661
IDENTIFIER_REGISTRY_INTERNAL_SHARED(singular, plural, registry, const) \
662-
private:
663-
664-
/* Macros to generate non-constant accessor methods for a UniqueKeyRegistry member variable. */
665-
666-
#define IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS(name) \
667-
IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS_CUSTOM_PLURAL(name, name##s)
668-
669-
#define IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS_CUSTOM_PLURAL(singular, plural) \
670-
IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS_FULL_CUSTOM(singular, plural, plural, plural)
671-
672-
#define IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS_FULL_CUSTOM(singular, plural, registry, debug_name) \
662+
private: \
673663
IDENTIFIER_REGISTRY_INTERNAL_SHARED(singular, plural, registry,)
674664

675665
#define IDENTIFIER_REGISTRY_INTERNAL_SHARED(singular, plural, registry, const_kw) \

0 commit comments

Comments
 (0)