summaryrefslogtreecommitdiff
path: root/domain
diff options
context:
space:
mode:
Diffstat (limited to 'domain')
-rw-r--r--domain/CMakeLists.txt2
-rw-r--r--domain/include/turns/domain/participant.hpp4
-rw-r--r--domain/include/turns/domain/turn_order.hpp26
-rw-r--r--domain/src/participant.cpp10
-rw-r--r--domain/src/turn_order.cpp40
-rw-r--r--domain/tests/participant.cpp6
6 files changed, 77 insertions, 11 deletions
diff --git a/domain/CMakeLists.txt b/domain/CMakeLists.txt
index 2de847a..066f638 100644
--- a/domain/CMakeLists.txt
+++ b/domain/CMakeLists.txt
@@ -2,6 +2,7 @@
add_library("domain"
"src/participant.cpp"
+ "src/turn_order.cpp"
)
add_library("turns::domain" ALIAS "domain")
@@ -24,6 +25,7 @@ target_include_directories("domain" PUBLIC
target_link_libraries("domain" PUBLIC
"$<$<AND:$<CXX_COMPILER_ID:GNU,Clang>,$<CONFIG:Debug>>:gcov>"
+ "PkgConfig::giomm"
"PkgConfig::glibmm"
)
diff --git a/domain/include/turns/domain/participant.hpp b/domain/include/turns/domain/participant.hpp
index 7c047ea..934e0bb 100644
--- a/domain/include/turns/domain/participant.hpp
+++ b/domain/include/turns/domain/participant.hpp
@@ -22,8 +22,8 @@ namespace turns::domain
auto property_name() -> Glib::PropertyProxy<Glib::ustring>;
auto property_name() const -> Glib::PropertyProxy_ReadOnly<Glib::ustring>;
- auto property_over_value() -> Glib::PropertyProxy<float>;
- auto property_over_value() const -> Glib::PropertyProxy_ReadOnly<float>;
+ auto property_order_value() -> Glib::PropertyProxy<float>;
+ auto property_order_value() const -> Glib::PropertyProxy_ReadOnly<float>;
private:
Glib::Property<Glib::ustring> m_name;
diff --git a/domain/include/turns/domain/turn_order.hpp b/domain/include/turns/domain/turn_order.hpp
new file mode 100644
index 0000000..8c9afa7
--- /dev/null
+++ b/domain/include/turns/domain/turn_order.hpp
@@ -0,0 +1,26 @@
+#ifndef TURNS_DOMAIN_TURN_ORDER_HPP
+#define TURNS_DOMAIN_TURN_ORDER_HPP
+
+#include "turns/domain/participant.hpp"
+
+#include <giomm/liststore.h>
+#include <glibmm/ustring.h>
+#include <glibmm/refptr.h>
+
+namespace turns::domain
+{
+
+ struct turn_order : Gio::ListStore<participant>
+ {
+ using super = Gio::ListStore<participant>;
+ using super::super;
+
+ auto static create() -> Glib::RefPtr<turn_order>;
+
+ auto append(Glib::ustring const & name, float order_value) -> turn_order &;
+ auto sort() -> void;
+ };
+
+} // namespace turns::domain
+
+#endif \ No newline at end of file
diff --git a/domain/src/participant.cpp b/domain/src/participant.cpp
index 8b16916..b52bcca 100644
--- a/domain/src/participant.cpp
+++ b/domain/src/participant.cpp
@@ -13,11 +13,9 @@ namespace turns::domain
participant::participant(Glib::ustring name, float order_value)
: Glib::ObjectBase{typeid(participant)}
- , m_name{*this, "name"}
- , m_order_value{*this, "order_value"}
+ , m_name{*this, "name", name}
+ , m_order_value{*this, "order_value", order_value}
{
- m_name = name;
- m_order_value = order_value;
}
auto participant::operator<=>(participant const & other) const noexcept -> std::partial_ordering
@@ -35,12 +33,12 @@ namespace turns::domain
return m_name.get_proxy();
}
- auto participant::property_over_value() -> Glib::PropertyProxy<float>
+ auto participant::property_order_value() -> Glib::PropertyProxy<float>
{
return m_order_value.get_proxy();
}
- auto participant::property_over_value() const -> Glib::PropertyProxy_ReadOnly<float>
+ auto participant::property_order_value() const -> Glib::PropertyProxy_ReadOnly<float>
{
return m_order_value.get_proxy();
}
diff --git a/domain/src/turn_order.cpp b/domain/src/turn_order.cpp
new file mode 100644
index 0000000..8b9e042
--- /dev/null
+++ b/domain/src/turn_order.cpp
@@ -0,0 +1,40 @@
+#include "turns/domain/turn_order.hpp"
+
+namespace turns::domain
+{
+
+ namespace
+ {
+ auto constexpr comparator = [](auto lhs, auto rhs){
+ auto result = *lhs <=> *rhs;
+ if(result == std::partial_ordering::equivalent || result == std::partial_ordering::unordered)
+ {
+ return 0;
+ }
+ else if(result == std::partial_ordering::less)
+ {
+ return 1;
+ }
+ return -1;
+ };
+ }
+
+ auto turn_order::create() -> Glib::RefPtr<turn_order>
+ {
+ return Glib::make_refptr_for_instance(new turn_order{});
+ }
+
+ auto turn_order::append(Glib::ustring const & name, float order_value) -> turn_order &
+ {
+ auto participant = participant::create(name, order_value);
+ participant->property_order_value().signal_changed().connect([this] { sort(); });
+ insert_sorted(participant, comparator);
+ return *this;
+ }
+
+ auto turn_order::sort() -> void
+ {
+ super::sort(comparator);
+ }
+
+} // namespace turns::domain \ No newline at end of file
diff --git a/domain/tests/participant.cpp b/domain/tests/participant.cpp
index aa6ddcb..4f32aa0 100644
--- a/domain/tests/participant.cpp
+++ b/domain/tests/participant.cpp
@@ -33,13 +33,13 @@ namespace turns::domain::tests
SECTION("the order can be read")
{
- REQUIRE(instance.property_over_value() == constructed_order);
+ REQUIRE(instance.property_order_value() == constructed_order);
}
SECTION("the order can be changed")
{
- instance.property_over_value() = 8;
- REQUIRE(instance.property_over_value() == 8);
+ instance.property_order_value() = 8;
+ REQUIRE(instance.property_order_value() == 8);
}
SECTION("can be compared with another participant")