Property as member of C++ classes #617
Replies: 2 comments 3 replies
-
I'm in favour of finding ways to reduce boiler plate. I'm unsure if adding wrapping magic solves that though. The pattern of calling sixtyfps::[blocking_]invoke_from_event_loop([&ui, val] {
ui->set_some_property(val);
}); is indeed suboptimal if called subsequently. I think it's better if the application groups updates together in messages and updates a bunch of properties in one block (invoked from the event loop). Perhaps the generator code can provide assistance in generating the interfaces for more efficient message passing, from the UI into worker threads and the other way around. I think of a message as information that originates from one or (likely) multiple properties and flows in both ways. The granularity of those is however naturally application dependent. Some of this can already be achieved by defining structures in |
Beta Was this translation helpful? Give feedback.
-
Alternative on
To wrap up this idea. What Property API may look like?
|
Beta Was this translation helpful? Give feedback.
-
(This is branch from discussion #607.)
I've seen come generated code. Properties are private members.
And
set_some_property
andget_some_property
are generated wrappers around private property.AFAIKG, those are meant to be called in main event loop only.
So, when working with threads the following patterns emerge
To keep window API smaller for user I suggest to make public properties but with extra functionalities on them.
I'd hide all read/write blocking operations under the hood of setter/(assign operator) and getter.
And add
unsafe_
set/get
methods that are meant to be called only from main event loop.And I'd add safe update methods for case like
ui->set_counter(ui->get_counter() + 1);
What seems nice option to me is to provide updating functor like:
ui->counter.update([](T const& old_val) -> T { return old_val + 1; });
With implementation like:
Cases for
operator+=
,operator-=
,operator*=
and similar can be also implemented as foroperator=
via update method.Probably there may be blocking update and non-blocking update.
I'd prefer conventional
update
to be most safe and others have some prefixes and suffixes.I believe this idea will reduce boilerplate.
However, user must be cautions when calling from main thread or worker thread.
Let's discuss this idea. Maybe during discussion we'll come up with better design.
Additional idea is to add some property.blocking() method as wrapper. To call blocking operations explicitly.
Beta Was this translation helpful? Give feedback.
All reactions