19 #include <type_traits>
32 template<
typename X,
typename Y,
typename =
void>
33 struct are_equality_comparable : std::false_type {
36 template<
typename X,
typename Y>
37 struct are_equality_comparable<X, Y,
41 decltype(std::equal_to<>{}(std::declval<X>(), std::declval<Y>()))>,
42 bool>::value>> : std::true_type {
45 template<
typename X,
typename Y>
46 constexpr
bool are_equality_comparable_v = are_equality_comparable<X, Y>::value;
59 using std::runtime_error::runtime_error;
87 -> std::enable_if_t<Private::are_equality_comparable_v<T, T>,
bool>
89 return std::equal_to<>{}(x, y);
99 template<
typename X,
typename Y>
101 -> std::enable_if_t<!Private::are_equality_comparable_v<X, Y>,
bool>
111 template<
typename PropertyType>
160 explicit Property(T value) noexcept(std::is_nothrow_move_constructible<T>::value)
161 : m_value{
std::move(value) }
181 : m_value(
std::move(other.m_value))
182 , m_valueAboutToChange(
std::move(other.m_valueAboutToChange))
183 , m_valueChanged(
std::move(other.m_valueChanged))
184 , m_destroyed(
std::move(other.m_destroyed))
185 , m_updater(
std::move(other.m_updater))
192 using namespace std::placeholders;
193 m_updater->setUpdateFunction(
199 other.m_moved.emit(*
this);
200 m_moved = std::move(other.m_moved);
210 m_value = std::move(other.m_value);
211 m_valueAboutToChange = std::move(other.m_valueAboutToChange);
212 m_valueChanged = std::move(other.m_valueChanged);
213 m_destroyed = std::move(other.m_destroyed);
214 m_updater = std::move(other.m_updater);
218 using namespace std::placeholders;
219 m_updater->setUpdateFunction(
225 other.m_moved.emit(*
this);
226 m_moved = std::move(other.m_moved);
237 template<
typename UpdaterT>
238 explicit Property(std::unique_ptr<UpdaterT> &&updater)
240 *
this = std::move(updater);
254 template<
typename UpdaterT>
257 m_updater = std::move(updater);
260 using namespace std::placeholders;
261 m_updater->setUpdateFunction(
265 setHelper(m_updater->get());
306 bool hasBinding() const noexcept {
return m_updater.get() !=
nullptr; }
326 "Cannot set value on a read-only property. This property likely holds the result of a binding expression."
329 setHelper(std::move(value));
362 void setHelper(T value)
367 m_valueAboutToChange.
emit(m_value, value);
368 m_value = std::move(value);
369 m_valueChanged.
emit(m_value);
376 mutable Signal<const T &, const T &> m_valueAboutToChange;
377 mutable Signal<const T &> m_valueChanged;
387 template<
typename PropertyType>
388 friend class Private::PropertyNode;
392 std::unique_ptr<PropertyUpdater<T>> m_updater;
401 stream <<
property.get();
414 prop.
set(std::move(temp));
421 struct is_property_helper : std::false_type {
425 struct is_property_helper<
Property<T>> : std::true_type {
429 struct is_property : is_property_helper<std::decay_t<T>> {
A property represents a value that can be part of or the result of data binding.
bool hasBinding() const noexcept
Property(Property< T > const &other)=delete
void reset()
Disconnects the binding from this Property.
Signal< const T &, const T & > & valueAboutToChange() const
Property< T > & operator=(T const &rhs)
Property & operator=(std::unique_ptr< UpdaterT > &&updater)
Property & operator=(Property< T > const &other)=delete
Signal< const T & > & valueChanged() const
Property(Property< T > &&other) noexcept(std::is_nothrow_move_constructible< T >::value)
Properties are movable.
Property(std::unique_ptr< UpdaterT > &&updater)
T const & operator()() const
Property(T value) noexcept(std::is_nothrow_move_constructible< T >::value)
Signal & destroyed() const
Property & operator=(Property< T > &&other) noexcept(std::is_nothrow_move_assignable< T >::value)
void emit(Args... p) const
The main namespace of the KDBindings library.
std::istream & operator>>(std::istream &stream, Property< T > &prop)
std::ostream & operator<<(std::ostream &stream, Property< T > const &property)
ReadOnlyProperty()=delete
An instance of the KDBindings::equal_to struct is used to decide whether two values of type T are equ...
auto operator()(const T &x, const T &y) const noexcept -> std::enable_if_t< Private::are_equality_comparable_v< T, T >, bool >
auto operator()(const X &, const Y &) const noexcept -> std::enable_if_t<!Private::are_equality_comparable_v< X, Y >, bool >