Loading...
Searching...
No Matches
StateMachineUtils.hpp
1#pragma once
2#include <score/model/path/Path.hpp>
3
4#include <QAbstractTransition>
5#include <QEvent>
6
13namespace score
14{
15
16template <int N>
17struct NumberedEvent : public QEvent
18{
19 static constexpr const int user_type = N;
21 : QEvent{QEvent::Type(QEvent::User + N)}
22 {
23 }
24};
25
26template <typename Element, int N>
27struct NumberedWithPath_Event final : public NumberedEvent<N>
28{
29 explicit NumberedWithPath_Event(const Path<Element>& p)
31 , path(p)
32 {
33 }
34
37 , path(std::move(p))
38 {
39 }
40
41 Path<Element> path;
42};
43
44template <typename PointType>
45struct PositionedEvent : public QEvent
46{
47 PositionedEvent(const PointType& pt, QEvent::Type type)
48 : QEvent{type}
49 , point{pt}
50 {
51 }
52
53 ~PositionedEvent() override = default;
54
55 PointType point;
56};
57
58template <typename Event>
59class MatchedTransition : public QAbstractTransition
60{
61public:
62 using event_type = Event;
63 using QAbstractTransition::QAbstractTransition;
64
65protected:
66 bool eventTest(QEvent* e) override
67 {
68 return e->type() == QEvent::Type(QEvent::User + Event::user_type);
69 }
70
71 void onTransition(QEvent* event) override { }
72};
73
74template <typename State, typename T>
75class StateAwareTransition : public T
76{
77public:
78 explicit StateAwareTransition(State& state)
79 : m_state{state}
80 {
81 }
82
83 State& state() const { return m_state; }
84
85private:
86 State& m_state;
87};
88
89template <
90 typename Transition, typename SourceState, typename TargetState, typename... Args>
91Transition* make_transition(SourceState source, TargetState dest, Args&&... args)
92{
93 Transition* t = new Transition{std::forward<Args>(args)...};
94 t->setTargetState(dest);
95 source->addTransition(t);
96 return t;
97}
98
99namespace Modifier
100{
101struct Click_tag
102{
103 static constexpr const int value = 100;
104};
105struct Move_tag
106{
107 static constexpr const int value = 200;
108};
109struct Release_tag
110{
111 static constexpr const int value = 300;
112};
113}
114enum Modifier_tagme
115{
116 Click = 100,
117 Move = 200,
118 Release = 300
119};
120
121using Press_Event = NumberedEvent<1>;
122using Move_Event = NumberedEvent<2>;
123using Release_Event = NumberedEvent<3>;
124using Cancel_Event = NumberedEvent<4>;
125using Shift_Event = NumberedEvent<5>;
126
127using Press_Transition = MatchedTransition<Press_Event>;
128using Move_Transition = MatchedTransition<Move_Event>;
129using Release_Transition = MatchedTransition<Release_Event>;
130using Cancel_Transition = MatchedTransition<Cancel_Event>;
131using ShiftTransition = MatchedTransition<Shift_Event>;
132}
The Path class is a typesafe wrapper around ObjectPath.
Definition Path.hpp:52
Definition StateMachineUtils.hpp:60
Definition StateMachineUtils.hpp:76
Utilities for OSSIA data structures.
Definition DeviceInterface.hpp:33
Base toolkit upon which the software is built.
Definition Application.cpp:90
Definition StateMachineUtils.hpp:18
Definition StateMachineUtils.hpp:28
Definition StateMachineUtils.hpp:46