From f4f41b6c51ce7a1d719759128b2af92604df5182 Mon Sep 17 00:00:00 2001 From: Joel Machens Date: Sun, 15 Oct 2023 16:09:21 -0500 Subject: Add National Values Loading --- src/openvic-simulation/politics/NationalValue.cpp | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/openvic-simulation/politics/NationalValue.cpp (limited to 'src/openvic-simulation/politics/NationalValue.cpp') diff --git a/src/openvic-simulation/politics/NationalValue.cpp b/src/openvic-simulation/politics/NationalValue.cpp new file mode 100644 index 0000000..f1d8a3b --- /dev/null +++ b/src/openvic-simulation/politics/NationalValue.cpp @@ -0,0 +1,38 @@ +#include "NationalValue.hpp" + +using namespace OpenVic; +using namespace OpenVic::NodeTools; + +NationalValue::NationalValue(std::string_view new_identifier, ModifierValue&& new_modifiers) + : HasIdentifier { new_identifier }, modifiers { std::move(new_modifiers) } {} + +ModifierValue const& NationalValue::get_modifiers() const { + return modifiers; +} + +NationalValueManager::NationalValueManager() : national_values { "national values" } {} + +bool NationalValueManager::add_national_value(std::string_view identifier, ModifierValue&& modifiers) { + if (identifier.empty()) { + Logger::error("Invalid national value identifier - empty!"); + return false; + } + + return national_values.add_item({ identifier, std::move(modifiers) }); +} + +bool NationalValueManager::load_national_values_file(ModifierManager const& modifier_manager, ast::NodeCPtr root) { + bool ret = expect_dictionary( + [this, &modifier_manager](std::string_view national_value_identifier, ast::NodeCPtr value) -> bool { + ModifierValue modifiers; + + bool ret = modifier_manager.expect_modifier_value(move_variable_callback(modifiers))(value); + + ret &= add_national_value(national_value_identifier, std::move(modifiers)); + return ret; + } + )(root); + lock_national_values(); + + return ret; +} -- cgit v1.2.3-56-ga3b1