This commit is contained in:
Olivier Goffart 2020-05-20 09:34:14 +02:00
parent 6b3765857a
commit bf64e40476
4 changed files with 23 additions and 31 deletions

View file

@ -7,42 +7,35 @@ namespace sixtyfps {
template<typename T>
struct Property
{
Property() {
internal::sixtyfps_property_init(&inner);
}
~Property() {
internal::sixtyfps_property_drop(&inner);
}
Property(const Property&) = delete;
Property(Property&&) = delete;
Property &operator=(const Property&) = delete;
Property() { internal::sixtyfps_property_init(&inner); }
~Property() { internal::sixtyfps_property_drop(&inner); }
Property(const Property &) = delete;
Property(Property &&) = delete;
Property &operator=(const Property &) = delete;
/* Should it be implicit?
void operator=(const T &value) {
set(value);
}*/
void set(const T &value) const {
this->value = value;
}
void set(const T &value) const { this->value = value; }
const T &get() const {
const T &get() const
{
internal::sixtyfps_property_update(&inner, &value);
return value;
}
template <typename F>
void set_binding(F binding) const {
template<typename F>
void set_binding(F binding) const
{
internal::sixtyfps_property_set_binding(
&inner,
[](const void *user_data, const void *value) {
*reinterpret_cast<T*>(value) = (*reinterpret_cast<F*>(user_data))();
},
new F(binding),
[](const void *user_data) {
delete reinterpret_cast<F*>(user_data);
}
);
&inner,
[](const void *user_data, const void *value) {
*reinterpret_cast<T *>(value) = (*reinterpret_cast<F *>(user_data))();
},
new F(binding),
[](const void *user_data) { delete reinterpret_cast<F *>(user_data); });
}
private: