summaryrefslogtreecommitdiff
path: root/lib/src
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2025-05-13 15:59:02 +0200
committerFelix Morgner <felix.morgner@gmail.com>2025-05-13 15:59:02 +0200
commit9513f7303ffde9fbda869e346523a23197f4ece9 (patch)
treef35ab8afa3273d1a8c4da2fc2ac9580a157a3a2c /lib/src
parent661e98cf8bb61f29049d405aef9cdaace1449ac8 (diff)
downloadturns-9513f7303ffde9fbda869e346523a23197f4ece9.tar.xz
turns-9513f7303ffde9fbda869e346523a23197f4ece9.zip
lib: begin TurnOrder implementation
Diffstat (limited to 'lib/src')
-rw-r--r--lib/src/turns-init.cpp4
-rw-r--r--lib/src/turns-participant.h2
-rw-r--r--lib/src/turns-turn-order.cpp80
-rw-r--r--lib/src/turns-turn-order.h18
-rw-r--r--lib/src/turnsmm/init.cpp5
-rw-r--r--lib/src/turnsmm/private/turn-order_p.hpp31
-rw-r--r--lib/src/turnsmm/turn-order.cpp92
-rw-r--r--lib/src/turnsmm/turn-order.hpp45
8 files changed, 274 insertions, 3 deletions
diff --git a/lib/src/turns-init.cpp b/lib/src/turns-init.cpp
index 544dc14..6fbe837 100644
--- a/lib/src/turns-init.cpp
+++ b/lib/src/turns-init.cpp
@@ -2,6 +2,7 @@
#include "turns-enums.h"
#include "turns-participant.h"
+#include "turns-turn-order.h"
#include <glib-object.h>
#include <glib.h>
@@ -10,8 +11,9 @@ G_BEGIN_DECLS
auto turns_init() -> void
{
- g_type_ensure(TURNS_TYPE_PARTICIPANT);
g_type_ensure(TURNS_TYPE_DISPOSITION);
+ g_type_ensure(TURNS_TYPE_PARTICIPANT);
+ g_type_ensure(TURNS_TYPE_TURN_ORDER);
}
G_END_DECLS \ No newline at end of file
diff --git a/lib/src/turns-participant.h b/lib/src/turns-participant.h
index a0e0d98..3ddfaa6 100644
--- a/lib/src/turns-participant.h
+++ b/lib/src/turns-participant.h
@@ -20,7 +20,7 @@ G_DECLARE_FINAL_TYPE(TurnsParticipant, turns_participant, TURNS, PARTICIPANT, GO
* - @p priority is 0.0f
* - @p disposition is Disposition.Neutral.
*/
-TurnsParticipant * turns_participant_new() G_GNUC_WARN_UNUSED_RESULT;
+TurnsParticipant * turns_participant_new(void) G_GNUC_WARN_UNUSED_RESULT;
/**
* @brief Construct a new Participant with the given values.
diff --git a/lib/src/turns-turn-order.cpp b/lib/src/turns-turn-order.cpp
new file mode 100644
index 0000000..538ff11
--- /dev/null
+++ b/lib/src/turns-turn-order.cpp
@@ -0,0 +1,80 @@
+#include "turns-turn-order.h"
+
+#include <glib-object.h>
+#include <glib.h>
+
+#include <array>
+#include <cstddef>
+
+G_BEGIN_DECLS
+
+struct _TurnsTurnOrder
+{
+ GObject parent_instance;
+
+ gboolean running;
+};
+
+G_DEFINE_FINAL_TYPE(TurnsTurnOrder, turns_turn_order, G_TYPE_OBJECT);
+
+G_END_DECLS
+
+namespace
+{
+ enum struct property
+ {
+ Running = 1,
+ N_PROPERTIES,
+ };
+
+ auto static constinit properties = std::array<GParamSpec *, static_cast<std::size_t>(property::N_PROPERTIES)>{};
+
+ auto get_property(GObject * self, guint id, GValue * value, GParamSpec * specification) -> void
+ {
+ auto instance = TURNS_TURN_ORDER(self);
+
+ switch (static_cast<property>(id))
+ {
+ case property::Running:
+ return g_value_set_boolean(value, turns_turn_order_get_running(instance));
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(self, id, specification);
+ }
+ }
+
+} // namespace
+
+G_BEGIN_DECLS
+
+static void turns_turn_order_class_init(TurnsTurnOrderClass * klass)
+{
+ auto object_class = G_OBJECT_CLASS(klass);
+
+ object_class->get_property = get_property;
+
+ properties[static_cast<std::size_t>(property::Running)] =
+ g_param_spec_boolean("running",
+ "Running",
+ "Whether or not the turn order is running (e.g. has been started)",
+ false,
+ static_cast<GParamFlags>(G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY));
+
+ g_object_class_install_properties(object_class, properties.size(), properties.data());
+}
+
+static void turns_turn_order_init(TurnsTurnOrder *)
+{
+}
+
+TurnsTurnOrder * turns_turn_order_new()
+{
+ return TURNS_TURN_ORDER(g_object_new(TURNS_TYPE_TURN_ORDER, nullptr));
+}
+
+gboolean turns_turn_order_get_running(TurnsTurnOrder const * self)
+{
+ g_return_val_if_fail(TURNS_IS_TURN_ORDER(const_cast<TurnsTurnOrder *>(self)), false);
+ return self->running;
+}
+
+G_END_DECLS \ No newline at end of file
diff --git a/lib/src/turns-turn-order.h b/lib/src/turns-turn-order.h
new file mode 100644
index 0000000..2370445
--- /dev/null
+++ b/lib/src/turns-turn-order.h
@@ -0,0 +1,18 @@
+#ifndef TURNS_TURN_ORDER_H
+#define TURNS_TURN_ORDER_H
+
+#include <glib-object.h>
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+#define TURNS_TYPE_TURN_ORDER turns_turn_order_get_type()
+G_DECLARE_FINAL_TYPE(TurnsTurnOrder, turns_turn_order, TURNS, TURN_ORDER, GObject)
+
+TurnsTurnOrder * turns_turn_order_new(void) G_GNUC_WARN_UNUSED_RESULT;
+
+gboolean turns_turn_order_get_running(TurnsTurnOrder const * self) G_GNUC_WARN_UNUSED_RESULT;
+
+G_END_DECLS
+
+#endif
diff --git a/lib/src/turnsmm/init.cpp b/lib/src/turnsmm/init.cpp
index 77c217b..3104b1d 100644
--- a/lib/src/turnsmm/init.cpp
+++ b/lib/src/turnsmm/init.cpp
@@ -1,9 +1,10 @@
#include "turnsmm/init.hpp"
#include "turns-init.h"
-#include "turnsmm/enums.hpp"
#include "turnsmm/participant.hpp"
#include "turnsmm/private/participant_p.hpp" // IWYU pragma: keep
+#include "turnsmm/private/turn-order_p.hpp" // IWYU pragma: keep
+#include "turnsmm/turn-order.hpp"
#include <glibmm/value.h>
#include <glibmm/wrap.h>
@@ -21,8 +22,10 @@ namespace Turns
turns_init();
WRAP_CLASS(Participant, participant);
+ WRAP_CLASS(TurnOrder, turn_order);
ENSURE_TYPE(Participant);
+ ENSURE_TYPE(TurnOrder);
}
} // namespace Turns \ No newline at end of file
diff --git a/lib/src/turnsmm/private/turn-order_p.hpp b/lib/src/turnsmm/private/turn-order_p.hpp
new file mode 100644
index 0000000..b128fd4
--- /dev/null
+++ b/lib/src/turnsmm/private/turn-order_p.hpp
@@ -0,0 +1,31 @@
+#ifndef TURNSMM_TURN_ORDER_P_HPP
+#define TURNSMM_TURN_ORDER_P_HPP
+
+#include "turns-turn-order.h"
+
+#include <glibmm/class.h>
+#include <glibmm/object.h>
+#include <glibmm/objectbase.h>
+
+#include <glib-object.h>
+
+namespace Turns
+{
+
+ class TurnOrder_Class : Glib::Class
+ {
+ public:
+ using BaseClassParent = GObjectClass;
+ using BaseClassType = TurnsTurnOrderClass;
+ using BaseObjectType = TurnsTurnOrder;
+ using CppClassParent = Glib::Object_Class;
+ using CppObjectType = class TURN_ORDER;
+
+ auto init() -> Glib::Class const &;
+ auto static class_init_function(void * gclass, void * data) -> void;
+ auto static wrap_new(GObject * object) -> Glib::ObjectBase *;
+ };
+
+} // namespace Turns
+
+#endif \ No newline at end of file
diff --git a/lib/src/turnsmm/turn-order.cpp b/lib/src/turnsmm/turn-order.cpp
new file mode 100644
index 0000000..8dbcd9c
--- /dev/null
+++ b/lib/src/turnsmm/turn-order.cpp
@@ -0,0 +1,92 @@
+#include "turnsmm/turn-order.hpp"
+
+#include "turns-turn-order.h"
+#include "turnsmm/private/turn-order_p.hpp"
+
+#include <glibmm/class.h>
+#include <glibmm/object.h>
+#include <glibmm/objectbase.h>
+#include <glibmm/private/object_p.h>
+#include <glibmm/propertyproxy.h>
+#include <glibmm/refptr.h>
+#include <glibmm/wrap.h>
+
+#include <glib-object.h>
+
+#include <bit>
+
+namespace Turns
+{
+
+ namespace
+ {
+ auto constinit _class = TurnOrder_Class{};
+ } // namespace
+
+ auto TurnOrder_Class::init() -> Glib::Class const &
+ {
+ if (!gtype_)
+ {
+ class_init_func_ = &class_init_function;
+ gtype_ = turns_turn_order_get_type();
+ }
+ return *this;
+ }
+
+ auto TurnOrder_Class::class_init_function(void * gclass, void * data) -> void
+ {
+ auto const klass = static_cast<BaseClassType *>(gclass);
+ CppClassParent::class_init_function(klass, data);
+ }
+
+ auto TurnOrder_Class::wrap_new(GObject * object) -> Glib::ObjectBase *
+ {
+ return new TurnOrder(TURNS_TURN_ORDER(object));
+ }
+
+ TurnOrder::TurnOrder()
+ : Glib::ObjectBase{nullptr}
+ , Glib::Object{Glib::ConstructParams{_class.init()}}
+ {
+ }
+
+ auto TurnOrder::gobj() noexcept -> BaseObjectType *
+ {
+ return std::bit_cast<BaseObjectType *>(gobject_);
+ }
+
+ auto TurnOrder::gobj() const -> BaseObjectType const *
+ {
+ return std::bit_cast<BaseObjectType const *>(gobject_);
+ }
+
+ auto TurnOrder::gobj_copy() noexcept -> BaseObjectType *
+ {
+ reference();
+ return gobj();
+ }
+
+ auto TurnOrder::get_running() const noexcept -> bool
+ {
+ return turns_turn_order_get_running(const_cast<BaseObjectType *>(unwrap(this)));
+ }
+
+ auto TurnOrder::property_running() const noexcept -> Glib::PropertyProxy_ReadOnly<bool>
+ {
+ return {this, "running"};
+ }
+
+ TurnOrder::TurnOrder(BaseObjectType * gobj)
+ : Glib::Object(G_OBJECT(gobj))
+ {
+ }
+
+} // namespace Turns
+
+namespace Glib
+{
+ auto wrap(TurnsTurnOrder * object, bool copy) -> Glib::RefPtr<Turns::TurnOrder>
+ {
+ return Glib::make_refptr_for_instance<Turns::TurnOrder>(dynamic_cast<Turns::TurnOrder *>(Glib::wrap_auto(G_OBJECT(object), copy)));
+ }
+} // namespace Glib \ No newline at end of file
diff --git a/lib/src/turnsmm/turn-order.hpp b/lib/src/turnsmm/turn-order.hpp
new file mode 100644
index 0000000..822e879
--- /dev/null
+++ b/lib/src/turnsmm/turn-order.hpp
@@ -0,0 +1,45 @@
+#ifndef TURNSMM_TURN_ORDER_HPP
+#define TURNSMM_TURN_ORDER_HPP
+
+#include "turns-turn-order.h"
+
+#include <glibmm/object.h>
+#include <glibmm/propertyproxy.h>
+#include <glibmm/refptr.h>
+#include <glibmm/ustring.h>
+
+namespace Turns
+{
+
+ class TurnOrder final : public Glib::Object
+ {
+ public:
+ using BaseClassType = TurnsTurnOrderClass;
+ using BaseObjectType = TurnsTurnOrder;
+ using CppClassType = class TurnOrder_Class;
+ using CppObjectType = TurnOrder;
+
+ TurnOrder();
+
+ [[nodiscard]] auto gobj() noexcept -> BaseObjectType *;
+ [[nodiscard]] auto gobj() const -> BaseObjectType const *;
+ [[nodiscard]] auto gobj_copy() noexcept -> BaseObjectType *;
+
+ [[nodiscard]] auto get_running() const noexcept -> bool;
+
+ [[nodiscard]] auto property_running() const noexcept -> Glib::PropertyProxy_ReadOnly<bool>;
+
+ protected:
+ friend TurnOrder_Class;
+
+ explicit TurnOrder(BaseObjectType * gobj);
+ };
+
+} // namespace Turns
+
+namespace Glib
+{
+ auto wrap(TurnsTurnOrder * object, bool copy = false) -> Glib::RefPtr<Turns::TurnOrder>;
+} // namespace Glib
+
+#endif \ No newline at end of file