From 1683859e333f98fb63f1c72d926bb366a3b89f0b Mon Sep 17 00:00:00 2001 From: zaaarf Date: Wed, 22 Nov 2023 17:16:34 +0100 Subject: chore: use PROPERTY and its variants when possible --- src/openvic-simulation/history/Bookmark.cpp | 20 ------ src/openvic-simulation/history/Bookmark.hpp | 16 ++--- .../history/DiplomaticHistory.cpp | 72 ---------------------- .../history/DiplomaticHistory.hpp | 64 ++++++------------- 4 files changed, 23 insertions(+), 149 deletions(-) (limited to 'src/openvic-simulation/history') diff --git a/src/openvic-simulation/history/Bookmark.cpp b/src/openvic-simulation/history/Bookmark.cpp index 92d8de5..483b49b 100644 --- a/src/openvic-simulation/history/Bookmark.cpp +++ b/src/openvic-simulation/history/Bookmark.cpp @@ -17,26 +17,6 @@ Bookmark::Bookmark( ) : HasIdentifier { std::to_string(new_index) }, name { new_name }, description { new_description }, date { new_date }, initial_camera_x { new_initial_camera_x }, initial_camera_y { new_initial_camera_y } {} -std::string_view Bookmark::get_name() const { - return name; -} - -std::string_view Bookmark::get_description() const { - return description; -} - -Date Bookmark::get_date() const { - return date; -} - -uint32_t Bookmark::get_initial_camera_x() const { - return initial_camera_x; -} - -uint32_t Bookmark::get_initial_camera_y() const { - return initial_camera_y; -} - BookmarkManager::BookmarkManager() : bookmarks { "bookmarks" } {} bool BookmarkManager::add_bookmark( diff --git a/src/openvic-simulation/history/Bookmark.hpp b/src/openvic-simulation/history/Bookmark.hpp index d5253fe..18375fb 100644 --- a/src/openvic-simulation/history/Bookmark.hpp +++ b/src/openvic-simulation/history/Bookmark.hpp @@ -13,11 +13,11 @@ namespace OpenVic { friend struct BookmarkManager; private: - const std::string name; - const std::string description; - const Date date; - const uint32_t initial_camera_x; - const uint32_t initial_camera_y; + const std::string PROPERTY(name); + const std::string PROPERTY(description); + const Date PROPERTY(date); + const uint32_t PROPERTY(initial_camera_x); + const uint32_t PROPERTY(initial_camera_y); Bookmark( size_t new_index, std::string_view new_name, std::string_view new_description, Date new_date, @@ -26,12 +26,6 @@ namespace OpenVic { public: Bookmark(Bookmark&&) = default; - - std::string_view get_name() const; - std::string_view get_description() const; - Date get_date() const; - uint32_t get_initial_camera_x() const; - uint32_t get_initial_camera_y() const; }; struct BookmarkManager { diff --git a/src/openvic-simulation/history/DiplomaticHistory.cpp b/src/openvic-simulation/history/DiplomaticHistory.cpp index 5cbafe7..5c560ea 100644 --- a/src/openvic-simulation/history/DiplomaticHistory.cpp +++ b/src/openvic-simulation/history/DiplomaticHistory.cpp @@ -15,48 +15,12 @@ WarHistory::added_wargoal_t::added_wargoal_t( std::optional new_target ) : added { new_added }, actor { new_actor }, receiver { new_receiver }, wargoal { new_wargoal }, third_party { new_third_party }, target { new_target } {} -Country const* WarHistory::added_wargoal_t::get_actor() const { - return actor; -} - -Country const* WarHistory::added_wargoal_t::get_receiver() const { - return receiver; -} - -WargoalType const* WarHistory::added_wargoal_t::get_wargoal_type() const { - return wargoal; -} - -std::optional const& WarHistory::added_wargoal_t::get_third_party() const { - return third_party; -} - -std::optional const& WarHistory::added_wargoal_t::get_target() const { - return target; -} - -Date WarHistory::added_wargoal_t::get_date_added() const { - return added; -} - WarHistory::war_participant_t::war_participant_t( Country const* new_country, Date new_joined, std::optional new_exited ) : country { new_country }, joined { new_joined }, exited { new_exited } {} -Country const* WarHistory::war_participant_t::get_country() const { - return country; -} - -Date WarHistory::war_participant_t::get_date_joined() const { - return joined; -} - -std::optional WarHistory::war_participant_t::get_date_exited() const { - return exited; -} - WarHistory::WarHistory( std::string_view new_war_name, std::vector&& new_attackers, @@ -64,52 +28,16 @@ WarHistory::WarHistory( std::vector&& new_wargoals ) : war_name { new_war_name }, attackers { std::move(new_attackers) }, defenders { std::move(new_defenders) }, wargoals { std::move(new_wargoals) } {} -std::string_view WarHistory::get_war_name() const { - return war_name; -} - -std::vector const& WarHistory::get_attackers() const { - return attackers; -} - -std::vector const& WarHistory::get_defenders() const { - return defenders; -} - -std::vector const& WarHistory::get_wargoals() const { - return wargoals; -} - AllianceHistory::AllianceHistory( Country const* new_first, Country const* new_second, Date new_start, Date new_end ) : first { new_first }, second { new_second }, start { new_start }, end { new_end } {} -Country const* AllianceHistory::get_first() const { - return first; -} - -Country const* AllianceHistory::get_second() const { - return second; -} - SubjectHistory::SubjectHistory( Country const* new_overlord, Country const* new_subject, const type_t new_type, const Date new_start, const Date new_end ) : overlord { new_overlord }, subject { new_subject }, type { new_type }, start { new_start }, end { new_end } {} -Country const* SubjectHistory::get_overlord() const { - return overlord; -} - -Country const* SubjectHistory::get_subject() const { - return subject; -} - -const SubjectHistory::type_t SubjectHistory::get_subject_type() const { - return type; -} - void DiplomaticHistoryManager::lock_diplomatic_history() { Logger::info("Locked diplomacy history registry after registering ", alliances.size() + subjects.size() + wars.size(), " items"); locked = true; diff --git a/src/openvic-simulation/history/DiplomaticHistory.hpp b/src/openvic-simulation/history/DiplomaticHistory.hpp index 64529c2..3ed253f 100644 --- a/src/openvic-simulation/history/DiplomaticHistory.hpp +++ b/src/openvic-simulation/history/DiplomaticHistory.hpp @@ -19,69 +19,46 @@ namespace OpenVic { friend struct DiplomaticHistoryManager; private: - Date added; - Country const* actor; - Country const* receiver; - WargoalType const* wargoal; - std::optional third_party; - std::optional target; + Date PROPERTY_CUSTOM_NAME(added, get_date_added); + Country const* PROPERTY(actor); + Country const* PROPERTY(receiver); + WargoalType const* PROPERTY(wargoal); + std::optional PROPERTY(third_party); + std::optional PROPERTY(target); added_wargoal_t(Date new_added, Country const* new_actor, Country const* new_receiver, WargoalType const* new_wargoal, std::optional new_third_party, std::optional new_target); - - public: - Date get_date_added() const; - Country const* get_actor() const; - Country const* get_receiver() const; - WargoalType const* get_wargoal_type() const; - std::optional const& get_third_party() const; - std::optional const& get_target() const; }; struct war_participant_t { friend struct DiplomaticHistoryManager; private: - Country const* country; - Date joined; - std::optional exited; + Country const* PROPERTY(country); + Date PROPERTY_CUSTOM_NAME(joined, get_date_joined); + std::optional PROPERTY_CUSTOM_NAME(exited, get_date_exited); war_participant_t(Country const* new_country, Date new_joined, std::optional new_exited); - - public: - Country const* get_country() const; - Date get_date_joined() const; - std::optional get_date_exited() const; }; private: - std::string war_name; // edge cases where this is empty/undef for some reason, probably need to just generate war names like usual for that. - std::vector attackers; - std::vector defenders; - std::vector wargoals; + std::string PROPERTY(war_name); // edge cases where this is empty/undef for some reason, probably need to just generate war names like usual for that. + std::vector PROPERTY(attackers); + std::vector PROPERTY(defenders); + std::vector PROPERTY(wargoals); WarHistory(std::string_view new_war_name, std::vector&& new_attackers, std::vector&& new_defenders, std::vector&& new_wargoals); - - public: - std::string_view get_war_name() const; - std::vector const& get_attackers() const; - std::vector const& get_defenders() const; - std::vector const& get_wargoals() const; }; struct AllianceHistory { friend struct DiplomaticHistoryManager; private: - Country const* first; - Country const* second; + Country const* PROPERTY(first); + Country const* PROPERTY(second); const Date start; const Date end; AllianceHistory(Country const* new_first, Country const* new_second, const Date new_start, const Date new_end); - - public: - Country const* get_first() const; - Country const* get_second() const; }; struct SubjectHistory { @@ -94,18 +71,13 @@ namespace OpenVic { }; private: - Country const* overlord; - Country const* subject; - const type_t type; + Country const* PROPERTY(overlord); + Country const* PROPERTY(subject); + const type_t PROPERTY_CUSTOM_NAME(type, get_subject_type); const Date start; const Date end; SubjectHistory(Country const* new_overlord, Country const* new_subject, const type_t new_type, const Date new_start, const Date new_end); - - public: - Country const* get_overlord() const; - Country const* get_subject() const; - const type_t get_subject_type() const; }; struct DiplomaticHistoryManager { -- cgit v1.2.3-56-ga3b1