From 3f5499cebc06356ed99159be3fb9676292cf7b8b Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 24 Jul 2024 10:44:13 +0200 Subject: turns: rename domain to core --- core/include/turns/core/disposition.hpp | 27 +++++++++++ core/include/turns/core/participant.hpp | 58 ++++++++++++++++++++++ core/include/turns/core/turn_order.hpp | 85 +++++++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 core/include/turns/core/disposition.hpp create mode 100644 core/include/turns/core/participant.hpp create mode 100644 core/include/turns/core/turn_order.hpp (limited to 'core/include') diff --git a/core/include/turns/core/disposition.hpp b/core/include/turns/core/disposition.hpp new file mode 100644 index 0000000..291aaf5 --- /dev/null +++ b/core/include/turns/core/disposition.hpp @@ -0,0 +1,27 @@ +#ifndef TURNS_DOMAIN_DISPOSITION_HPP +#define TURNS_DOMAIN_DISPOSITION_HPP + +#include +#include + +#include + +namespace turns::core +{ + + enum struct disposition : std::uint8_t + { + neutral, + friendly, + hostile, + secret, + + ///! End marker + END + }; + + auto presentation_name_for(disposition value) -> Glib::ustring; + +} // namespace turns::core + +#endif \ No newline at end of file diff --git a/core/include/turns/core/participant.hpp b/core/include/turns/core/participant.hpp new file mode 100644 index 0000000..9b5dab4 --- /dev/null +++ b/core/include/turns/core/participant.hpp @@ -0,0 +1,58 @@ +#ifndef TURNS_DOMAIN_PARTICIPANT_HPP +#define TURNS_DOMAIN_PARTICIPANT_HPP + +#include "turns/core/disposition.hpp" + +#include + +#include +#include +#include +#include +#include + +namespace turns::core +{ + 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; + + 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{*this, "disposition", core::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::core + +#endif \ No newline at end of file diff --git a/core/include/turns/core/turn_order.hpp b/core/include/turns/core/turn_order.hpp new file mode 100644 index 0000000..43ee075 --- /dev/null +++ b/core/include/turns/core/turn_order.hpp @@ -0,0 +1,85 @@ +#ifndef TURNS_DOMAIN_TURN_ORDER_HPP +#define TURNS_DOMAIN_TURN_ORDER_HPP + +#include "turns/core/disposition.hpp" +#include "turns/core/participant.hpp" + +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace turns::core +{ + + 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 is_empty_type = bool; + using has_next_type = bool; + using has_previous_type = bool; + 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(); + + /** Life-time */ + turn_order(); + + 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 start() -> void; + auto stop() -> void; + + private: + auto get_item_type_vfunc() -> GType override; + auto get_n_items_vfunc() -> unsigned override; + auto get_item_vfunc(unsigned position) -> void * override; + + /** Signal handlers */ + auto handle_priority_changed(value_type entry) -> void; + + /** Data management */ + auto find(value_type entry) const -> const_iterator; + auto insert(value_type entry) -> const_iterator; + + 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::core + +#endif \ No newline at end of file -- cgit v1.2.3