summaryrefslogtreecommitdiff
path: root/lib/src
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2025-05-23 11:06:04 +0200
committerFelix Morgner <felix.morgner@gmail.com>2025-05-23 11:06:04 +0200
commit260df0a1158385736b2da24a2e4a14e365d1ec92 (patch)
treee589f2941e514785a0126a7512a191009fed4569 /lib/src
parentddce5043e70de5eab3d35b0986faf9a12933dedf (diff)
downloadturns-260df0a1158385736b2da24a2e4a14e365d1ec92.tar.xz
turns-260df0a1158385736b2da24a2e4a14e365d1ec92.zip
lib: add remove_at to TurnOrder
Diffstat (limited to 'lib/src')
-rw-r--r--lib/src/turns-turn-order.c17
-rw-r--r--lib/src/turns-turn-order.h8
-rw-r--r--lib/src/turnsmm/turn-order.cpp6
-rw-r--r--lib/src/turnsmm/turn-order.hpp1
4 files changed, 32 insertions, 0 deletions
diff --git a/lib/src/turns-turn-order.c b/lib/src/turns-turn-order.c
index 5d6f99b..9a08d2e 100644
--- a/lib/src/turns-turn-order.c
+++ b/lib/src/turns-turn-order.c
@@ -230,6 +230,23 @@ void turns_turn_order_clear(TurnsTurnOrder * self)
g_list_model_items_changed(G_LIST_MODEL(self), 0, old_size, 0);
}
+void turns_turn_order_remove_at(TurnsTurnOrder * self, guint position)
+{
+ g_return_if_fail(TURNS_IS_TURN_ORDER(self));
+
+ auto element = g_slist_nth(self->participants, position);
+
+ if (!element)
+ {
+ return;
+ }
+
+ g_object_unref(element->data);
+ self->participants = g_slist_delete_link(self->participants, element);
+
+ g_list_model_items_changed(G_LIST_MODEL(self), position, 1, 0);
+}
+
gsize turns_turn_order_get_participant_count(TurnsTurnOrder const * self)
{
g_return_val_if_fail(TURNS_IS_TURN_ORDER((TurnsTurnOrder *)self), 0);
diff --git a/lib/src/turns-turn-order.h b/lib/src/turns-turn-order.h
index a69700f..91220b9 100644
--- a/lib/src/turns-turn-order.h
+++ b/lib/src/turns-turn-order.h
@@ -67,6 +67,14 @@ void turns_turn_order_add(TurnsTurnOrder * self, TurnsParticipant * participant)
void turns_turn_order_clear(TurnsTurnOrder * self);
/**
+ * turns_turn_order_remove_at:
+ * @self: a turn order
+ *
+ * Removes the participant at the given position.
+ */
+void turns_turn_order_remove_at(TurnsTurnOrder * self, guint position);
+
+/**
* turns_turn_order_get_participant_count:
* @self: a turn order.
*
diff --git a/lib/src/turnsmm/turn-order.cpp b/lib/src/turnsmm/turn-order.cpp
index 35694b2..3767817 100644
--- a/lib/src/turnsmm/turn-order.cpp
+++ b/lib/src/turnsmm/turn-order.cpp
@@ -21,6 +21,7 @@
#include <giomm/listmodel.h>
#include <glib-object.h>
+#include <glib.h>
#include <bit>
#include <cstddef>
@@ -98,6 +99,11 @@ namespace Turns
return turns_turn_order_clear(Glib::unwrap(this));
}
+ auto TurnOrder::remove_at(guint position) noexcept -> void
+ {
+ return turns_turn_order_remove_at(unwrap(this), position);
+ }
+
auto TurnOrder::get_participant_count() const noexcept -> std::size_t
{
return turns_turn_order_get_participant_count(unwrap(this));
diff --git a/lib/src/turnsmm/turn-order.hpp b/lib/src/turnsmm/turn-order.hpp
index 64f72aa..fe8c756 100644
--- a/lib/src/turnsmm/turn-order.hpp
+++ b/lib/src/turnsmm/turn-order.hpp
@@ -51,6 +51,7 @@ namespace Turns
auto add(Glib::RefPtr<Participant> const & participant) noexcept -> void;
auto clear() noexcept -> void;
+ auto remove_at(guint position) noexcept -> void;
[[nodiscard]] auto get_participant_count() const noexcept -> std::size_t;
[[nodiscard]] auto get_running() const noexcept -> bool;