diff options
author | Hop311 <Hop3114@gmail.com> | 2023-11-22 23:11:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-22 23:11:42 +0100 |
commit | a54898b7770e0d66b729216173960686c67e58bb (patch) | |
tree | af8ed836a4789ef94c5bfed27abb713922f45af3 /src/openvic-simulation/history | |
parent | e76336cd92639f4ec71088fc4c80aea4c25528cd (diff) | |
parent | 738a203e0d8b4df87c42888043b99c13d5d97511 (diff) |
Merge pull request #78 from OpenVicProject/property-macro
Refactoring (*mostly* related to the property macro)
Diffstat (limited to 'src/openvic-simulation/history')
-rw-r--r-- | src/openvic-simulation/history/Bookmark.cpp | 20 | ||||
-rw-r--r-- | src/openvic-simulation/history/Bookmark.hpp | 16 | ||||
-rw-r--r-- | src/openvic-simulation/history/DiplomaticHistory.cpp | 72 | ||||
-rw-r--r-- | src/openvic-simulation/history/DiplomaticHistory.hpp | 64 |
4 files changed, 23 insertions, 149 deletions
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<Province const*> 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<Country const*> const& WarHistory::added_wargoal_t::get_third_party() const { - return third_party; -} - -std::optional<Province const*> 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<Date> 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<Date> WarHistory::war_participant_t::get_date_exited() const { - return exited; -} - WarHistory::WarHistory( std::string_view new_war_name, std::vector<war_participant_t>&& new_attackers, @@ -64,52 +28,16 @@ WarHistory::WarHistory( std::vector<added_wargoal_t>&& 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<WarHistory::war_participant_t> const& WarHistory::get_attackers() const { - return attackers; -} - -std::vector<WarHistory::war_participant_t> const& WarHistory::get_defenders() const { - return defenders; -} - -std::vector<WarHistory::added_wargoal_t> 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<Country const*> third_party; - std::optional<Province const*> target; + Date PROPERTY_CUSTOM_NAME(added, get_date_added); + Country const* PROPERTY(actor); + Country const* PROPERTY(receiver); + WargoalType const* PROPERTY(wargoal); + std::optional<Country const*> PROPERTY(third_party); + std::optional<Province const*> PROPERTY(target); added_wargoal_t(Date new_added, Country const* new_actor, Country const* new_receiver, WargoalType const* new_wargoal, std::optional<Country const*> new_third_party, std::optional<Province const*> 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<Country const*> const& get_third_party() const; - std::optional<Province const*> const& get_target() const; }; struct war_participant_t { friend struct DiplomaticHistoryManager; private: - Country const* country; - Date joined; - std::optional<Date> exited; + Country const* PROPERTY(country); + Date PROPERTY_CUSTOM_NAME(joined, get_date_joined); + std::optional<Date> PROPERTY_CUSTOM_NAME(exited, get_date_exited); war_participant_t(Country const* new_country, Date new_joined, std::optional<Date> new_exited); - - public: - Country const* get_country() const; - Date get_date_joined() const; - std::optional<Date> 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<war_participant_t> attackers; - std::vector<war_participant_t> defenders; - std::vector<added_wargoal_t> 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<war_participant_t> PROPERTY(attackers); + std::vector<war_participant_t> PROPERTY(defenders); + std::vector<added_wargoal_t> PROPERTY(wargoals); WarHistory(std::string_view new_war_name, std::vector<war_participant_t>&& new_attackers, std::vector<war_participant_t>&& new_defenders, std::vector<added_wargoal_t>&& new_wargoals); - - public: - std::string_view get_war_name() const; - std::vector<war_participant_t> const& get_attackers() const; - std::vector<war_participant_t> const& get_defenders() const; - std::vector<added_wargoal_t> 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 { |