OSSIA
Open Scenario System for Interactive Application
time_event.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <ossia/detail/config.hpp>
3 
7 
8 #include <cstdint>
9 #include <functional>
10 #include <memory>
11 
16 namespace ossia
17 {
18 class state;
19 class time_interval;
20 class time_sync;
21 class time_process;
22 class scenario;
33 class OSSIA_EXPORT time_event
34 {
35  friend class ossia::scenario;
36 
37 public:
39  enum class status : uint8_t
40  {
41  NONE = 0b00000000,
42  PENDING = 0b00000001,
43  HAPPENED = 0b00000010,
44  DISPOSED = 0b00000011,
45  FINISHED = 0b10000000
46  };
47 
54  enum class offset_behavior : uint8_t
55  {
56  EXPRESSION_TRUE,
57  EXPRESSION_FALSE,
58  EXPRESSION
59  };
60 
63  using exec_callback = std::function<void(status)>;
64 
65 public:
66  time_event(
67  time_event::exec_callback, time_sync& aTimeSync, expression_ptr anExpression);
68 
71 
75  void set_callback(time_event::exec_callback);
76 
77  void add_time_process(std::shared_ptr<time_process>);
78  void remove_time_process(time_process*);
79  [[nodiscard]] const auto& get_time_processes() const { return m_processes; }
80 
81  void tick(ossia::time_value date, ossia::time_value offset);
82 
85  [[nodiscard]] time_sync& get_time_sync() const;
86 
87  void set_time_sync(time_sync&);
88 
91  [[nodiscard]] const expression& get_expression() const;
92 
96  time_event& set_expression(expression_ptr);
97 
100  [[nodiscard]] status get_status() const;
101 
106  [[nodiscard]] offset_behavior get_offset_behavior() const;
107 
112  time_event& set_offset_behavior(offset_behavior);
113 
116  auto& previous_time_intervals() { return m_previous_time_intervals; }
117 
120  [[nodiscard]] const auto& previous_time_intervals() const
121  {
122  return m_previous_time_intervals;
123  }
124 
127  auto& next_time_intervals() { return m_next_time_intervals; }
128 
131  [[nodiscard]] const auto& next_time_intervals() const { return m_next_time_intervals; }
132 
133  void set_status(status s);
134 
135  void reset();
136 
137  /* To be called before deletion, to break the shared_ptr cycle */
138  void cleanup();
139 
140  void mute(bool m);
141 
142 private:
143  time_event::exec_callback m_callback;
144 
145  time_sync* m_timesync{};
146  ossia::small_vector<std::shared_ptr<time_process>, 1> m_processes;
147  status m_status;
148  offset_behavior m_offset{offset_behavior::EXPRESSION_TRUE};
149 
150  expression_ptr m_expression;
151 
152  small_ptr_container<time_interval, 1> m_previous_time_intervals;
153  small_ptr_container<time_interval, 1> m_next_time_intervals;
154 };
155 
156 inline constexpr auto
157 operator&(ossia::time_event::status lhs, ossia::time_event::status rhs) noexcept
158 {
159  using t = std::underlying_type_t<ossia::time_event::status>;
160  return static_cast<t>(lhs) & static_cast<t>(rhs);
161 }
162 }
The time_event class.
Definition: time_event.hpp:34
std::function< void(status)> exec_callback
to get the event status back
Definition: time_event.hpp:63
const auto & next_time_intervals() const
get next time constraints attached to the event
Definition: time_event.hpp:131
const auto & previous_time_intervals() const
get previous time constraints attached to the event
Definition: time_event.hpp:120
status
event status
Definition: time_event.hpp:40
offset_behavior
The OffsetBehavior enum Describes what happens when a parent scenario does an offset beyond this even...
Definition: time_event.hpp:55
auto & next_time_intervals()
get next time constraints attached to the event
Definition: time_event.hpp:127
auto & previous_time_intervals()
get previous time constraints attached to the event
Definition: time_event.hpp:116
~time_event()
destructor
The time_process class.
Definition: time_process.hpp:24
#time_sync is use to describe temporal structure to synchronize each attached #time_event evaluation.
Definition: time_sync.hpp:103
Definition: git_info.h:7
@ NONE
map<string, value>
expressions::expression_base expression
Definition: expression_fwd.hpp:222
The time_value class.
Definition: ossia/editor/scenario/time_value.hpp:28