OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
expression.hpp
Go to the documentation of this file.
1#pragma once
6#include <ossia/editor/expression/expression_generic.hpp>
9
47namespace ossia::expressions
48{
54OSSIA_EXPORT bool evaluate(const expression_base& e);
55inline bool evaluate(const expression_ptr& e)
56{
57 return evaluate(*e);
58}
59
67OSSIA_EXPORT void update(const expression_base& e);
68inline void update(const expression_ptr& e)
69{
70 update(*e);
71}
72
77OSSIA_EXPORT void reset(expression_base& e);
78inline void reset(const expression_ptr& e)
79{
80 return reset(*e);
81}
82
89OSSIA_EXPORT bool operator==(const expression_base& lhs, const expression_base& rhs);
90OSSIA_EXPORT bool operator!=(const expression_base& lhs, const expression_base& rhs);
91
95OSSIA_EXPORT expression_callback_iterator
96add_callback(expression_base&, expression_result_callback);
97
101OSSIA_EXPORT void remove_callback(expression_base&, expression_callback_iterator);
102
107OSSIA_EXPORT std::size_t callback_count(expression_base&);
108
113OSSIA_EXPORT const expression_base& expression_true();
114
118OSSIA_EXPORT const expression_base& expression_false();
119
130inline expression_ptr make_expression_true()
131{
132 return std::make_unique<expression_base>(ossia::in_place_type<expression_bool>, true);
133}
134
135inline bool is_expression_true(ossia::expression& e) noexcept
136{
137 const auto p = e.target<expression_bool>();
138 return p && p->evaluate();
139}
140
146inline expression_ptr make_expression_false()
147{
148 return std::make_unique<expression_base>(ossia::in_place_type<expression_bool>, false);
149}
150
156template <typename... Args>
157expression_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}
162OSSIA_EXPORT
163expression_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);
167OSSIA_EXPORT
168expression_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
177template <typename... Args>
178expression_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
189template <typename... Args>
190expression_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
201template <typename... Args>
202expression_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
213template <typename... Args>
214expression_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
220template <typename T, typename... Args>
221expression_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