OSSIA
Open Scenario System for Interactive Application
expression.hpp
Go to the documentation of this file.
1 #pragma once
6 #include <ossia/editor/expression/expression_generic.hpp>
9 
47 namespace ossia::expressions
48 {
54 OSSIA_EXPORT bool evaluate(const expression_base& e);
55 inline bool evaluate(const expression_ptr& e)
56 {
57  return evaluate(*e);
58 }
59 
67 OSSIA_EXPORT void update(const expression_base& e);
68 inline void update(const expression_ptr& e)
69 {
70  update(*e);
71 }
72 
77 OSSIA_EXPORT void reset(expression_base& e);
78 inline void reset(const expression_ptr& e)
79 {
80  return reset(*e);
81 }
82 
89 OSSIA_EXPORT bool operator==(const expression_base& lhs, const expression_base& rhs);
90 OSSIA_EXPORT bool operator!=(const expression_base& lhs, const expression_base& rhs);
91 
95 OSSIA_EXPORT expression_callback_iterator
96 add_callback(expression_base&, expression_result_callback);
97 
101 OSSIA_EXPORT void remove_callback(expression_base&, expression_callback_iterator);
102 
107 OSSIA_EXPORT std::size_t callback_count(expression_base&);
108 
113 OSSIA_EXPORT const expression_base& expression_true();
114 
118 OSSIA_EXPORT const expression_base& expression_false();
119 
130 inline expression_ptr make_expression_true()
131 {
132  return std::make_unique<expression_base>(ossia::in_place_type<expression_bool>, true);
133 }
134 
135 inline bool is_expression_true(ossia::expression& e) noexcept
136 {
137  const auto p = e.target<expression_bool>();
138  return p && p->evaluate();
139 }
140 
146 inline expression_ptr make_expression_false()
147 {
148  return std::make_unique<expression_base>(ossia::in_place_type<expression_bool>, false);
149 }
150 
156 template <typename... Args>
157 expression_ptr make_expression_atom(Args&&... args)
158 {
159  return std::make_unique<expression_base>(
160  ossia::in_place_type<expression_atom>, std::forward<Args>(args)...);
161 }
162 OSSIA_EXPORT
163 expression_ptr make_expression_atom(
164  const ossia::expressions::expression_atom::val_t& lhs,
165  ossia::expressions::comparator c,
166  const ossia::expressions::expression_atom::val_t& rhs);
167 OSSIA_EXPORT
168 expression_ptr make_expression_atom(
169  ossia::expressions::expression_atom::val_t&& lhs, ossia::expressions::comparator c,
170  ossia::expressions::expression_atom::val_t&& rhs);
171 
177 template <typename... Args>
178 expression_ptr make_expression_bool(Args&&... args)
179 {
180  return std::make_unique<expression_base>(
181  ossia::in_place_type<expression_bool>, std::forward<Args>(args)...);
182 }
183 
189 template <typename... Args>
190 expression_ptr make_expression_composition(Args&&... args)
191 {
192  return std::make_unique<expression_base>(
193  ossia::in_place_type<expression_composition>, std::forward<Args>(args)...);
194 }
195 
201 template <typename... Args>
202 expression_ptr make_expression_not(Args&&... args)
203 {
204  return std::make_unique<expression_base>(
205  ossia::in_place_type<expression_not>, std::forward<Args>(args)...);
206 }
207 
213 template <typename... Args>
214 expression_ptr make_expression_pulse(Args&&... args)
215 {
216  return std::make_unique<expression_base>(
217  ossia::in_place_type<expression_pulse>, std::forward<Args>(args)...);
218 }
219 
220 template <typename T, typename... Args>
221 expression_ptr make_expression_generic(Args&&... args)
222 {
223  static_assert(
224  std::is_base_of<expression_generic_base, T>::value,
225  "Must inherit from expression_generic_base");
226 
227  return std::make_unique<expression_base>(
228  ossia::in_place_type<expression_generic>,
229  std::make_unique<T>(std::forward<Args>(args)...));
230 }
231 }
expression_ptr make_expression_composition(Args &&... args)
make_expression_composition
Definition: expression.hpp:190
expression_ptr make_expression_bool(Args &&... args)
make_expression_bool
Definition: expression.hpp:178
expression_ptr make_expression_pulse(Args &&... args)
make_expression_pulse
Definition: expression.hpp:214
expression_ptr make_expression_not(Args &&... args)
make_expression_not
Definition: expression.hpp:202
expression_ptr make_expression_false()
make_expression_false
Definition: expression.hpp:146
expression_ptr make_expression_true()
make_expression_true
Definition: expression.hpp:130
expressions::expression_base expression
Definition: expression_fwd.hpp:222