2 #include <ossia/detail/config.hpp>
4 #include <ossia/detail/audio_spin_mutex.hpp>
6 #include <ossia/detail/nullable_variant.hpp>
7 #include <ossia/detail/small_vector.hpp>
9 #include <smallfun.hpp>
25 = smallfun::function<void(
bool), smallfun::DefaultSize * 2>;
27 class expression_callback_container
29 using mutex = ossia::audio_spin_mutex;
30 using lock_guard = std::lock_guard<ossia::audio_spin_mutex>;
34 expression_callback_container() noexcept =
default;
35 expression_callback_container(
const expression_callback_container& other) =
delete;
36 expression_callback_container(expression_callback_container&& other) noexcept =
delete;
37 expression_callback_container& operator=(
const expression_callback_container& other)
39 expression_callback_container&
40 operator=(expression_callback_container&& other) noexcept
43 virtual ~expression_callback_container() =
default;
50 using impl =
typename ossia::static_vector<T, 2>;
51 using iterator =
typename impl::iterator;
58 iterator add_callback(T&& callback)
60 if(callback.allocated())
62 lock_guard lck{m_mutx};
63 auto it = m_callbacks.insert(m_callbacks.begin(), std::move(callback));
64 if(m_callbacks.size() == 1)
65 on_first_callback_added();
70 #if defined(__cpp_exceptions)
71 throw invalid_callback_error{};
82 void remove_callback(iterator it)
84 lock_guard lck{m_mutx};
85 if(m_callbacks.size() == 1)
86 on_removing_last_callback();
87 m_callbacks.erase(it);
94 std::size_t callback_count()
const
96 lock_guard lck{m_mutx};
97 return m_callbacks.size();
104 bool callbacks_empty()
const
106 lock_guard lck{m_mutx};
107 return m_callbacks.empty();
114 template <
typename... Args>
115 void send(Args&&... args)
117 lock_guard lck{m_mutx};
118 for(
auto& callback : m_callbacks)
121 callback(std::forward<Args>(args)...);
128 void callbacks_clear()
130 lock_guard lck{m_mutx};
131 if(!m_callbacks.empty())
132 on_removing_last_callback();
147 virtual void on_first_callback_added() { }
154 virtual void on_removing_last_callback() { }
157 impl m_callbacks TS_GUARDED_BY(m_mutx);
158 mutable ossia::audio_spin_mutex m_mutx;
162 using expression_callback_iterator =
typename expression_callback_container::iterator;
163 class expression_atom;
164 class expression_bool;
165 class expression_composition;
166 class expression_not;
167 class expression_pulse;
168 class expression_generic;
169 using expression_base = ossia::nullable_variant<
170 expression_atom, expression_bool, expression_composition, expression_not,
171 expression_pulse, expression_generic>;
187 using expression_ptr = std::unique_ptr<expressions::expression_base>;
smallfun::function< void(bool), smallfun::DefaultSize *2 > expression_result_callback
Definition: expression_fwd.hpp:25
expressions::expression_base expression
Definition: expression_fwd.hpp:222