Skip to content

Commit a4e9a8f

Browse files
committed
Make TechnologyManager technology accessors privately mutable
Add InventionManager as a friend of TechnologyManager Remove const_cast from `InventionManager::generate_invention_links`
1 parent e539ed7 commit a4e9a8f

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,15 @@ 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);
102104
IdentifierRegistry<TechnologySchool> IDENTIFIER_REGISTRY(technology_school);
103105

106+
IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS_CUSTOM_PLURAL(technology, technologies);
107+
104108
public:
105109
bool add_technology_folder(std::string_view identifier);
106110

@@ -132,4 +136,4 @@ namespace OpenVic {
132136

133137
bool parse_scripts(DefinitionManager const& definition_manager);
134138
};
135-
}
139+
}

0 commit comments

Comments
 (0)