summaryrefslogtreecommitdiff
path: root/domain/src/turn_order.cpp
blob: 81b7fe75686500767474b19772d5cadcb6993c1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#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) -> void
  {
    auto participant = participant::create(name, order_value);
    participant->property_order_value().signal_changed().connect([this] { sort(); });
    insert_sorted(participant, comparator);
  }

  auto turn_order::sort() -> void
  {
    super::sort(comparator);
  }

}  // namespace turns::domain