diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2024-07-14 16:39:58 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2024-07-14 16:39:58 +0200 |
| commit | 37732d5ccae97d80a9083ae295af018f154edb5a (patch) | |
| tree | 45977187c68fe016fab835788486854211f7cf40 /domain/src/turn_order.cpp | |
| parent | 3e6cc7e8e068447a2a2064754df56e18a1cf1c58 (diff) | |
| download | turns-37732d5ccae97d80a9083ae295af018f154edb5a.tar.xz turns-37732d5ccae97d80a9083ae295af018f154edb5a.zip | |
domain: add basic turn order type
Diffstat (limited to 'domain/src/turn_order.cpp')
| -rw-r--r-- | domain/src/turn_order.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
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 |
