diff options
Diffstat (limited to 'domain/include/turns')
| -rw-r--r-- | domain/include/turns/domain/participant.hpp | 46 | ||||
| -rw-r--r-- | domain/include/turns/domain/turn_order.hpp | 111 |
2 files changed, 73 insertions, 84 deletions
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(); participant(Glib::ustring name, float priority, disposition disposition); auto operator<=>(participant const & other) const noexcept -> std::partial_ordering; - auto property_disposition() -> Glib::PropertyProxy<disposition>; - auto property_disposition() const -> Glib::PropertyProxy_ReadOnly<disposition>; - auto get_disposition() const noexcept -> disposition; - auto set_disposition(disposition value) -> void; - - auto property_name() -> Glib::PropertyProxy<Glib::ustring>; - auto property_name() const -> Glib::PropertyProxy_ReadOnly<Glib::ustring>; - auto get_name() const -> Glib::ustring; - auto set_name(Glib::ustring value) -> void; - - auto property_priority() -> Glib::PropertyProxy<float>; - auto property_priority() const -> Glib::PropertyProxy_ReadOnly<float>; - auto get_priority() const noexcept -> float; - auto set_priority(float value) -> void; + template<typename Self> + auto disposition(this Self && self) + { + return self.m_disposition.get_proxy(); + } + + template<typename Self> + auto is_active(this Self && self) + { + return self.m_is_active.get_proxy(); + } + + template<typename Self> + auto name(this Self && self) + { + return self.m_name.get_proxy(); + } + + template<typename Self> + auto priority(this Self && self) + { + return self.m_priority.get_proxy(); + } private: - Glib::Property<disposition> m_disposition; - Glib::Property<Glib::ustring> m_name; - Glib::Property<float> m_priority; + Glib::Property<domain::disposition> m_disposition{*this, "disposition", domain::disposition::neutral}; + Glib::Property<bool> m_is_active{*this, "active", false}; + Glib::Property<Glib::ustring> m_name{*this, "name", ""}; + Glib::Property<float> 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 <initializer_list> #include <limits> +#include <optional> +#include <vector> -#include <giomm/liststore.h> +#include <giomm/listmodel.h> #include <glibmm/property.h> #include <glibmm/refptr.h> #include <glibmm/ustring.h> @@ -14,91 +17,67 @@ namespace turns::domain { - struct turn_order : Glib::Object + struct turn_order : Gio::ListModel, + Glib::Object { + using value_type = Glib::RefPtr<participant>; + using container_type = std::vector<value_type>; + 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<active_participant_type>::max(); + auto static constexpr invalid_round_number = std::numeric_limits<round_number_type>::max(); - auto static create() -> Glib::RefPtr<turn_order>; - + /** Life-time */ turn_order(); - /** Modifiers */ + auto static create() -> Glib::RefPtr<turn_order>; + + /** Properties */ + auto is_empty() const -> Glib::PropertyProxy_ReadOnly<is_empty_type>; + auto has_next() const -> Glib::PropertyProxy_ReadOnly<has_next_type>; + auto has_previous() const -> Glib::PropertyProxy_ReadOnly<has_previous_type>; + auto is_running() const -> Glib::PropertyProxy_ReadOnly<is_running_type>; + auto round_number() const -> Glib::PropertyProxy_ReadOnly<round_number_type>; + /** 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<participant>; - - /** - * Get the underlying list model, to be used with list views. - */ - auto list_model() -> Glib::RefPtr<Gio::ListModel>; - - /** - * 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<active_participant_type>; - auto property_empty() const -> Glib::PropertyProxy_ReadOnly<empty_type>; - auto property_has_next() const -> Glib::PropertyProxy_ReadOnly<has_next_type>; - auto property_has_previous() const -> Glib::PropertyProxy_ReadOnly<has_previous_type>; - auto property_running() const -> Glib::PropertyProxy_ReadOnly<running_type>; - auto property_round() const -> Glib::PropertyProxy_ReadOnly<round_type>; + /** Data management */ + auto find(value_type entry) const -> const_iterator; + auto insert(value_type entry) -> const_iterator; - private: - Glib::RefPtr<Gio::ListStore<participant>> m_model; - - Glib::Property<active_participant_type> m_active_participant; - Glib::Property<empty_type> m_empty; - Glib::Property<has_next_type> m_has_next; - Glib::Property<has_previous_type> m_has_previous; - Glib::Property<running_type> m_running; - Glib::Property<round_type> m_round; + container_type m_data{}; + std::optional<unsigned> m_active{}; + + Glib::Property<has_next_type> m_has_next{*this, "has-next", false}; + Glib::Property<has_previous_type> m_has_previous{*this, "has-previous", false}; + Glib::Property<is_empty_type> m_is_empty{*this, "is-empty", true}; + Glib::Property<is_running_type> m_is_running{*this, "is-running", false}; + Glib::Property<round_number_type> m_round_number{*this, "round-number", invalid_round_number}; }; } // namespace turns::domain |
