From 3f9911dd1cbfca513c8615d778a8295906d8b7d5 Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Thu, 4 Jan 2024 20:48:46 -0500 Subject: Add skeleton CountryRelationManager Change `DiplomaticAction::Argument` to refer to `CountryInstance*` instead of `Country*` Add `GameManager&` argument to `DiplomaticActionManager::setup_diplomatic_actions` Add some ErrorMacros, likely and unlikely macros and stringization macros (based on Godot's macros) Implement `increase_relations` DiplomaticAction commit function Implement `decrease_relations` DiplomaticAction commit function Fix include StringUtils.hpp errors --- src/openvic-simulation/utility/ErrorMacros.hpp | 68 ++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/openvic-simulation/utility/ErrorMacros.hpp (limited to 'src/openvic-simulation/utility/ErrorMacros.hpp') diff --git a/src/openvic-simulation/utility/ErrorMacros.hpp b/src/openvic-simulation/utility/ErrorMacros.hpp new file mode 100644 index 0000000..47b73d5 --- /dev/null +++ b/src/openvic-simulation/utility/ErrorMacros.hpp @@ -0,0 +1,68 @@ +#pragma once + +#include "openvic-simulation/utility/Logger.hpp" // IWYU pragma: keep +#include "openvic-simulation/utility/Utility.hpp" + +/** + * Try using `ERR_FAIL_COND_MSG`. + * Only use this macro if there is no sensible error message. + * If checking for null use ERR_FAIL_NULL_MSG instead. + * If checking index bounds use ERR_FAIL_INDEX_MSG instead. + * + * Ensures `m_cond` is false. + * If `m_cond` is true, the current function returns. + */ +#define OV_ERR_FAIL_COND(m_cond) \ + if (OV_unlikely(m_cond)) { \ + ::OpenVic::Logger::error("Condition \"" _OV_STR(m_cond) "\" is true."); \ + return; \ + } else \ + ((void)0) + +/** + * Ensures `m_cond` is false. + * If `m_cond` is true, prints `m_msg` and the current function returns. + * + * If checking for null use ERR_FAIL_NULL_MSG instead. + * If checking index bounds use ERR_FAIL_INDEX_MSG instead. + */ +#define OV_ERR_FAIL_COND_MSG(m_cond, m_msg) \ + if (OV_unlikely(m_cond)) { \ + ::OpenVic::Logger::error("Condition \"" _OV_STR(m_cond) "\" is true.", m_msg); \ + return; \ + } else \ + ((void)0) + +/** + * Try using `ERR_FAIL_COND_V_MSG`. + * Only use this macro if there is no sensible error message. + * If checking for null use ERR_FAIL_NULL_V_MSG instead. + * If checking index bounds use ERR_FAIL_INDEX_V_MSG instead. + * + * Ensures `m_cond` is false. + * If `m_cond` is true, the current function returns `m_retval`. + */ +#define OV_ERR_FAIL_COND_V(m_cond, m_retval) \ + if (OV_unlikely(m_cond)) { \ + ::OpenVic::Logger::error( \ + "Condition \"" _OV_STR(m_cond) "\" is true. Returning: " _OV_STR(m_retval) \ + ); \ + return m_retval; \ + } else \ + ((void)0) + +/** + * Ensures `m_cond` is false. + * If `m_cond` is true, prints `m_msg` and the current function returns `m_retval`. + * + * If checking for null use ERR_FAIL_NULL_V_MSG instead. + * If checking index bounds use ERR_FAIL_INDEX_V_MSG instead. + */ +#define OV_ERR_FAIL_COND_V_MSG(m_cond, m_retval, m_msg) \ + if (OV_unlikely(m_cond)) { \ + ::OpenVic::Logger::error( \ + "Condition \"" _OV_STR(m_cond) "\" is true. Returning: " _OV_STR(m_retval), m_msg \ + ); \ + return m_retval; \ + } else \ + ((void)0) -- cgit v1.2.3-56-ga3b1