BaseScenarioContainer.hpp
1 #pragma once
2 #include <Scenario/Process/ScenarioInterface.hpp>
3 
4 #include <score/document/DocumentContext.hpp>
5 #include <score/model/Identifier.hpp>
7 #include <score/serialization/JSONVisitor.hpp>
8 #include <score/tools/std/IndirectContainer.hpp>
9 
10 #include <score_plugin_scenario_export.h>
11 
12 #include <tuple>
13 
14 class DataStream;
15 
16 class JSONObject;
17 class QObject;
18 
19 namespace Scenario
20 {
21 class IntervalModel;
22 class EventModel;
23 class StateModel;
24 class TimeSyncModel;
25 class SCORE_PLUGIN_SCENARIO_EXPORT BaseScenarioContainer : public ScenarioInterface
26 {
27  SCORE_SERIALIZE_FRIENDS
28 public:
29  struct no_init
30  {
31  };
32  explicit BaseScenarioContainer(
33  const score::DocumentContext& ctx, QObject* parentObject);
34  explicit BaseScenarioContainer(
35  no_init, const score::DocumentContext& ctx, QObject* parentObject);
36 
37  virtual ~BaseScenarioContainer() override;
38  const score::DocumentContext& context() const noexcept { return m_context; }
39 
40  QObject& parentObject() const { return *m_parent; }
41 
42  score::IndirectContainer<IntervalModel> getIntervals() const final override
43  {
44  return {m_interval};
45  }
46  score::IndirectContainer<StateModel> getStates() const final override
47  {
48  return {m_startState, m_endState};
49  }
50  score::IndirectContainer<EventModel> getEvents() const final override
51  {
52  return {m_startEvent, m_endEvent};
53  }
54  score::IndirectContainer<TimeSyncModel> getTimeSyncs() const final override
55  {
56  return {m_startNode, m_endNode};
57  }
58 
59  IntervalModel* findInterval(const Id<IntervalModel>& id) const final override;
60 
61  EventModel* findEvent(const Id<EventModel>& id) const final override;
62 
63  TimeSyncModel* findTimeSync(const Id<TimeSyncModel>& id) const final override;
64 
65  StateModel* findState(const Id<StateModel>& id) const final override;
66 
67  IntervalModel& interval(const Id<IntervalModel>& id) const final override;
68 
69  EventModel& event(const Id<EventModel>& id) const final override;
70 
71  TimeSyncModel& timeSync(const Id<TimeSyncModel>& id) const final override;
72 
73  StateModel& state(const Id<StateModel>& id) const final override;
74 
75  IntervalModel& interval() const;
76 
77  TimeSyncModel& startTimeSync() const;
78  TimeSyncModel& endTimeSync() const;
79 
80  EventModel& startEvent() const;
81  EventModel& endEvent() const;
82 
83  StateModel& startState() const;
84  StateModel& endState() const;
85 
86  score::IndirectArray<IntervalModel, 1> intervals() const { return m_interval; }
88  {
89  return {m_startEvent, m_endEvent};
90  }
92  {
93  return {m_startState, m_endState};
94  }
96  {
97  return {m_startNode, m_endNode};
98  }
99 
100 protected:
101  const score::DocumentContext& m_context;
102  TimeSyncModel* m_startNode{};
103  TimeSyncModel* m_endNode{};
104 
105  EventModel* m_startEvent{};
106  EventModel* m_endEvent{};
107 
108  StateModel* m_startState{};
109  StateModel* m_endState{};
110 
111  IntervalModel* m_interval{};
112 
113  auto elements() const
114  {
115  return std::make_tuple(
116  m_startNode, m_endNode, m_startEvent, m_endEvent, m_startState, m_endState,
117  m_interval);
118  }
119 
120 private:
121  QObject* m_parent{}; // Parent for the intervals, timesyncs, etc.
122  // If inheriting, m_parent should be this.
123 };
124 
125 inline auto intervals(const BaseScenarioContainer& scenar)
126 {
127  return scenar.intervals();
128 }
129 inline auto events(const BaseScenarioContainer& scenar)
130 {
131  return scenar.events();
132 }
133 inline auto timeSyncs(const BaseScenarioContainer& scenar)
134 {
135  return scenar.timeSyncs();
136 }
137 inline auto states(const BaseScenarioContainer& scenar)
138 {
139  return scenar.states();
140 }
141 
142 template <>
144 {
145  static const constexpr auto accessor
146  = static_cast<score::IndirectArray<IntervalModel, 1> (*)(
147  const BaseScenarioContainer&)>(&intervals);
148 };
149 template <>
151 {
152  static const constexpr auto accessor
153  = static_cast<score::IndirectArray<EventModel, 2> (*)(
154  const BaseScenarioContainer&)>(&events);
155 };
156 template <>
158 {
159  static const constexpr auto accessor
160  = static_cast<score::IndirectArray<TimeSyncModel, 2> (*)(
161  const BaseScenarioContainer&)>(&timeSyncs);
162 };
163 template <>
165 {
166  static const constexpr auto accessor
167  = static_cast<score::IndirectArray<StateModel, 2> (*)(
168  const BaseScenarioContainer&)>(&states);
169 };
170 }
Definition: VisitorInterface.hpp:53
Definition: VisitorInterface.hpp:61
Definition: BaseScenarioContainer.hpp:26
Definition: EventModel.hpp:36
Definition: IntervalModel.hpp:50
Definition: ScenarioInterface.hpp:20
Definition: StateModel.hpp:63
Definition: TimeSyncModel.hpp:34
The id_base_t class.
Definition: Identifier.hpp:57
Definition: IndirectContainer.hpp:184
Definition: IndirectContainer.hpp:129
Main plug-in of score.
Definition: score-plugin-dataflow/Dataflow/PortItem.hpp:14
Definition: BaseScenarioContainer.hpp:30
Definition: ScenarioInterface.hpp:55
Definition: DocumentContext.hpp:18