From 4ec6a2ae12b6adb843c0777649ff45a741ca6cbc Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 23 Jul 2024 15:08:19 +0200 Subject: domain: redesign turn_order --- domain/include/turns/domain/participant.hpp | 46 +++++++----- domain/include/turns/domain/turn_order.hpp | 111 +++++++++++----------------- 2 files changed, 73 insertions(+), 84 deletions(-) (limited to 'domain/include/turns') diff --git a/domain/include/turns/domain/participant.hpp b/domain/include/turns/domain/participant.hpp index d845c77..b51425d 100644 --- a/domain/include/turns/domain/participant.hpp +++ b/domain/include/turns/domain/participant.hpp @@ -13,34 +13,44 @@ namespace turns::domain { - struct participant : Glib::Object { auto static create(Glib::ustring name, float priority, disposition disposition) -> Glib::RefPtr; + participant(); participant(Glib::ustring name, float priority, disposition disposition); auto operator<=>(participant const & other) const noexcept -> std::partial_ordering; - auto property_disposition() -> Glib::PropertyProxy; - auto property_disposition() const -> Glib::PropertyProxy_ReadOnly; - auto get_disposition() const noexcept -> disposition; - auto set_disposition(disposition value) -> void; - - auto property_name() -> Glib::PropertyProxy; - auto property_name() const -> Glib::PropertyProxy_ReadOnly; - auto get_name() const -> Glib::ustring; - auto set_name(Glib::ustring value) -> void; - - auto property_priority() -> Glib::PropertyProxy; - auto property_priority() const -> Glib::PropertyProxy_ReadOnly; - auto get_priority() const noexcept -> float; - auto set_priority(float value) -> void; + template + auto disposition(this Self && self) + { + return self.m_disposition.get_proxy(); + } + + template + auto is_active(this Self && self) + { + return self.m_is_active.get_proxy(); + } + + template + auto name(this Self && self) + { + return self.m_name.get_proxy(); + } + + template + auto priority(this Self && self) + { + return self.m_priority.get_proxy(); + } private: - Glib::Property m_disposition; - Glib::Property m_name; - Glib::Property m_priority; + Glib::Property m_disposition{*this, "disposition", domain::disposition::neutral}; + Glib::Property m_is_active{*this, "active", false}; + Glib::Property m_name{*this, "name", ""}; + Glib::Property m_priority{*this, "priority", 0.0f}; }; } // namespace turns::domain diff --git a/domain/include/turns/domain/turn_order.hpp b/domain/include/turns/domain/turn_order.hpp index 3b42562..ca44b62 100644 --- a/domain/include/turns/domain/turn_order.hpp +++ b/domain/include/turns/domain/turn_order.hpp @@ -4,9 +4,12 @@ #include "turns/domain/disposition.hpp" #include "turns/domain/participant.hpp" +#include #include +#include +#include -#include +#include #include #include #include @@ -14,91 +17,67 @@ namespace turns::domain { - struct turn_order : Glib::Object + struct turn_order : Gio::ListModel, + Glib::Object { + using value_type = Glib::RefPtr; + using container_type = std::vector; + using iterator = container_type::iterator; + using const_iterator = container_type::const_iterator; + using active_participant_type = unsigned int; - using empty_type = bool; + using is_empty_type = bool; using has_next_type = bool; using has_previous_type = bool; - using running_type = bool; - using round_type = unsigned int; + using is_running_type = bool; + using round_number_type = unsigned int; auto static constexpr invalid_participant_index = std::numeric_limits::max(); + auto static constexpr invalid_round_number = std::numeric_limits::max(); - auto static create() -> Glib::RefPtr; - + /** Life-time */ turn_order(); - /** Modifiers */ + auto static create() -> Glib::RefPtr; + + /** Properties */ + auto is_empty() const -> Glib::PropertyProxy_ReadOnly; + auto has_next() const -> Glib::PropertyProxy_ReadOnly; + auto has_previous() const -> Glib::PropertyProxy_ReadOnly; + auto is_running() const -> Glib::PropertyProxy_ReadOnly; + auto round_number() const -> Glib::PropertyProxy_ReadOnly; + /** Element Modifications */ auto add(Glib::ustring const & name, float priority, disposition disposition) -> void; auto clear() -> void; + auto remove(unsigned index) -> void; + + /** Turn Modification */ auto next() -> void; auto previous() -> void; - auto remove(unsigned int index) -> void; - auto reset() -> void; auto start() -> void; auto stop() -> void; - /** Querries */ - - /** - * Get the index of the currently active participant of this turn order, if any. - * - * @returns an unsigned integer in the range [0, size()) if there is an active participant, or turn_order::invalid_participant_index otherwise. - */ - auto active_participant() const noexcept -> active_participant_type; - - /** - * Check if this turn order is empty. - */ - auto empty() const noexcept -> empty_type; - - /** - * Get the actor at the specified position in this turn order. - * - * @return a valid pointer to a participant object if the index was valid, nullptr otherwise. - */ - auto get(unsigned int index) const noexcept -> Glib::RefPtr; - - /** - * Get the underlying list model, to be used with list views. - */ - auto list_model() -> Glib::RefPtr; - - /** - * Get the current round. - */ - auto round() const noexcept -> round_type; - - /** - * Check if this turn order is currently running. - */ - auto running() const noexcept -> running_type; - - /** - * Get the size of this turn order - */ - auto size() const noexcept -> unsigned int; + private: + auto get_item_type_vfunc() -> GType override; + auto get_n_items_vfunc() -> unsigned override; + auto get_item_vfunc(unsigned position) -> void * override; - /** Properties */ + /** Signal handlers */ + auto handle_priority_changed(value_type entry) -> void; - auto property_active_participant() const -> Glib::PropertyProxy_ReadOnly; - auto property_empty() const -> Glib::PropertyProxy_ReadOnly; - auto property_has_next() const -> Glib::PropertyProxy_ReadOnly; - auto property_has_previous() const -> Glib::PropertyProxy_ReadOnly; - auto property_running() const -> Glib::PropertyProxy_ReadOnly; - auto property_round() const -> Glib::PropertyProxy_ReadOnly; + /** Data management */ + auto find(value_type entry) const -> const_iterator; + auto insert(value_type entry) -> const_iterator; - private: - Glib::RefPtr> m_model; - - Glib::Property m_active_participant; - Glib::Property m_empty; - Glib::Property m_has_next; - Glib::Property m_has_previous; - Glib::Property m_running; - Glib::Property m_round; + container_type m_data{}; + std::optional m_active{}; + + Glib::Property m_has_next{*this, "has-next", false}; + Glib::Property m_has_previous{*this, "has-previous", false}; + Glib::Property m_is_empty{*this, "is-empty", true}; + Glib::Property m_is_running{*this, "is-running", false}; + Glib::Property m_round_number{*this, "round-number", invalid_round_number}; }; } // namespace turns::domain -- cgit v1.2.3