diff options
author | zaaarf <me@zaaarf.foo> | 2023-12-10 23:15:41 +0100 |
---|---|---|
committer | zaaarf <me@zaaarf.foo> | 2023-12-10 23:15:41 +0100 |
commit | 4ef33d4df6198e613b0f27406d49978c8ea2fb97 (patch) | |
tree | 7f07835485b877f3c01c52c188892499e5812f9b /src/openvic-simulation/misc | |
parent | 1eb28bd4fb959b69a30013f6438f0257a2ee7b03 (diff) |
feat: improved identifier registry macro
Diffstat (limited to 'src/openvic-simulation/misc')
-rw-r--r-- | src/openvic-simulation/misc/Decision.cpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/misc/Decision.hpp | 5 | ||||
-rw-r--r-- | src/openvic-simulation/misc/Define.cpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/misc/Define.hpp | 5 | ||||
-rw-r--r-- | src/openvic-simulation/misc/Event.cpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/misc/Event.hpp | 5 | ||||
-rw-r--r-- | src/openvic-simulation/misc/Modifier.cpp | 4 | ||||
-rw-r--r-- | src/openvic-simulation/misc/Modifier.hpp | 14 |
8 files changed, 7 insertions, 32 deletions
diff --git a/src/openvic-simulation/misc/Decision.cpp b/src/openvic-simulation/misc/Decision.cpp index 861a584..9200688 100644 --- a/src/openvic-simulation/misc/Decision.cpp +++ b/src/openvic-simulation/misc/Decision.cpp @@ -12,8 +12,6 @@ Decision::Decision( news_desc_long { new_news_desc_long }, news_desc_medium { new_news_desc_medium }, news_desc_short { new_news_desc_short }, picture { new_picture } {} -DecisionManager::DecisionManager() : decisions { "decisions" } {} - bool DecisionManager::add_decision( std::string_view identifier, bool alert, bool news, std::string_view news_title, std::string_view news_desc_long, std::string_view news_desc_medium, diff --git a/src/openvic-simulation/misc/Decision.hpp b/src/openvic-simulation/misc/Decision.hpp index e477f64..452512d 100644 --- a/src/openvic-simulation/misc/Decision.hpp +++ b/src/openvic-simulation/misc/Decision.hpp @@ -30,17 +30,14 @@ namespace OpenVic { struct DecisionManager { private: - IdentifierRegistry<Decision> decisions; + IdentifierRegistry<Decision> IDENTIFIER_REGISTRY(decision); public: - DecisionManager(); - bool add_decision( std::string_view identifier, bool alert, bool news, std::string_view news_title, std::string_view news_desc_long, std::string_view news_desc_medium, std::string_view news_desc_short, std::string_view picture ); - IDENTIFIER_REGISTRY_ACCESSORS(decision) bool load_decision_file(ast::NodeCPtr root); }; diff --git a/src/openvic-simulation/misc/Define.cpp b/src/openvic-simulation/misc/Define.cpp index 9e468d9..45584f7 100644 --- a/src/openvic-simulation/misc/Define.cpp +++ b/src/openvic-simulation/misc/Define.cpp @@ -29,8 +29,6 @@ uint64_t Define::get_value_as_uint() const { return std::strtoull(value.data(), nullptr, 10); } -DefineManager::DefineManager() : defines { "defines" } {} - bool DefineManager::add_define(std::string_view name, std::string&& value, Define::Type type) { return defines.add_item({ name, std::move(value), type }, duplicate_warning_callback); } diff --git a/src/openvic-simulation/misc/Define.hpp b/src/openvic-simulation/misc/Define.hpp index 46e4836..c3c7888 100644 --- a/src/openvic-simulation/misc/Define.hpp +++ b/src/openvic-simulation/misc/Define.hpp @@ -30,17 +30,14 @@ namespace OpenVic { struct DefineManager { private: - IdentifierRegistry<Define> defines; + IdentifierRegistry<Define> IDENTIFIER_REGISTRY(define); std::optional<Date> start_date; std::optional<Date> end_date; public: - DefineManager(); - bool add_define(std::string_view name, std::string&& value, Define::Type type); bool add_date_define(std::string_view name, Date date); - IDENTIFIER_REGISTRY_ACCESSORS(define) Date get_start_date() const; Date get_end_date() const; diff --git a/src/openvic-simulation/misc/Event.cpp b/src/openvic-simulation/misc/Event.cpp index 029336c..59b1f54 100644 --- a/src/openvic-simulation/misc/Event.cpp +++ b/src/openvic-simulation/misc/Event.cpp @@ -20,8 +20,6 @@ Event::Event( news_desc_long { new_news_desc_long }, news_desc_medium { new_news_desc_medium }, news_desc_short { new_news_desc_short }, election { new_election }, election_issue_group { new_election_issue_group }, options { std::move(new_options) } {} -EventManager::EventManager() : events { "events" } {} - bool EventManager::register_event( std::string_view identifier, std::string_view title, std::string_view description, std::string_view image, Event::event_type_t type, bool triggered_only, bool major, bool fire_only_once, bool allows_multiple_instances, bool news, diff --git a/src/openvic-simulation/misc/Event.hpp b/src/openvic-simulation/misc/Event.hpp index 6d0829e..d1f7963 100644 --- a/src/openvic-simulation/misc/Event.hpp +++ b/src/openvic-simulation/misc/Event.hpp @@ -65,11 +65,9 @@ namespace OpenVic { struct EventManager { private: - IdentifierRegistry<Event> events; + IdentifierRegistry<Event> IDENTIFIER_REGISTRY(event); public: - EventManager(); - bool register_event( std::string_view identifier, std::string_view title, std::string_view description, std::string_view image, Event::event_type_t type, bool triggered_only, bool major, bool fire_only_once, bool allows_multiple_instances, @@ -77,7 +75,6 @@ namespace OpenVic { std::string_view news_desc_short, bool election, IssueGroup const* election_issue_group, std::vector<Event::EventOption>&& options ); - IDENTIFIER_REGISTRY_ACCESSORS(event); bool load_event_file(IssueManager const& issue_manager, ast::NodeCPtr root); }; diff --git a/src/openvic-simulation/misc/Modifier.cpp b/src/openvic-simulation/misc/Modifier.cpp index 1b3e551..ac052c2 100644 --- a/src/openvic-simulation/misc/Modifier.cpp +++ b/src/openvic-simulation/misc/Modifier.cpp @@ -84,10 +84,6 @@ TriggeredModifier::TriggeredModifier(std::string_view new_identifier, ModifierVa ModifierInstance::ModifierInstance(Modifier const& modifier, Date expiry_date) : modifier { modifier }, expiry_date { expiry_date } {} -ModifierManager::ModifierManager() - : modifier_effects { "modifier effects" }, event_modifiers { "event modifiers" }, static_modifiers { "static modifiers" }, - triggered_modifiers { "triggered modifiers" } {} - bool ModifierManager::add_modifier_effect(std::string_view identifier, bool positive_good, ModifierEffect::format_t format) { if (identifier.empty()) { Logger::error("Invalid modifier effect identifier - empty!"); diff --git a/src/openvic-simulation/misc/Modifier.hpp b/src/openvic-simulation/misc/Modifier.hpp index 617159a..a176d6c 100644 --- a/src/openvic-simulation/misc/Modifier.hpp +++ b/src/openvic-simulation/misc/Modifier.hpp @@ -110,12 +110,12 @@ namespace OpenVic { * so instead we use an IdentifierInstanceRegistry (using std::unique_ptr's under the hood). */ private: - IdentifierInstanceRegistry<ModifierEffect> modifier_effects; + IdentifierInstanceRegistry<ModifierEffect> IDENTIFIER_REGISTRY(modifier_effect); string_set_t complex_modifiers; - IdentifierRegistry<Modifier> event_modifiers; - IdentifierRegistry<Modifier> static_modifiers; - IdentifierRegistry<TriggeredModifier> triggered_modifiers; + IdentifierRegistry<Modifier> IDENTIFIER_REGISTRY(event_modifier); + IdentifierRegistry<Modifier> IDENTIFIER_REGISTRY(static_modifier); + IdentifierRegistry<TriggeredModifier> IDENTIFIER_REGISTRY(triggered_modifier); /* effect_validator takes in ModifierEffect const& */ NodeTools::key_value_callback_t _modifier_effect_callback( @@ -124,28 +124,22 @@ namespace OpenVic { ) const; public: - ModifierManager(); - bool add_modifier_effect( std::string_view identifier, bool positive_good, ModifierEffect::format_t format = ModifierEffect::format_t::PROPORTION_DECIMAL ); - IDENTIFIER_REGISTRY_ACCESSORS(modifier_effect) void register_complex_modifier(std::string_view identifier); bool setup_modifier_effects(); bool add_event_modifier(std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon); - IDENTIFIER_REGISTRY_ACCESSORS(event_modifier) bool load_event_modifiers(ast::NodeCPtr root); bool add_static_modifier(std::string_view identifier, ModifierValue&& values); - IDENTIFIER_REGISTRY_ACCESSORS(static_modifier) bool load_static_modifiers(ast::NodeCPtr root); bool add_triggered_modifier(std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon); - IDENTIFIER_REGISTRY_ACCESSORS(triggered_modifier) bool load_triggered_modifiers(ast::NodeCPtr root); NodeTools::node_callback_t expect_validated_modifier_value_and_default( |