AUI_PTR_ALIAS#
Constructs an alias shared_ptr.
| Header: | #include <AUI/Common/SharedPtrTypes.h> |
| CMake: | aui_link(my_target PUBLIC aui::core) |
Definition#
Detailed Description#
Shares ownership information with the initial value of owner, but holds a pointer to field whose name is specified
by field. If this shared_ptr is the last of the group to go out of scope, it will call the stored deleter for the
object originally managed by owner. However, calling get() on this shared_ptr will always return a copy of
pointer to the field.
_<AView> minimalCheckBox(_<AProperty<bool>> state) {
// lifetime is managed by _<State> in the outer scope, however,
// the bool field is all we need.
return CheckBox { .value = AUI_REACT(*state), ... };
}
AUI_ENTRY {
auto window = _new<AWindow>("Checkbox", 300_dp, 100_dp);
_<State> state = _new<State>();
window->setContents(
Vertical {
minimalCheckBox(AUI_PTR_ALIAS(state, checked)),
}
);
window->show();
return 0;
}
This macro enable developers to create shared_ptr that manage the lifetime of a parent object while directly
referencing a specific member or sub-object. This enhances flexibility in managing object ownership where a component
might only need a pointer to a specific property within a larger state object, as demonstrated by the example above.
Examples#
examples/7guis/flight_booker/src/main.cpp
7GUIs Flight Booker - Flight Booker.
AObject::connect(it->selectionId().changed, AObject::GENERIC_OBSERVER, [=](int newSelection) {
state->isReturnFlight = newSelection == 1;
});
},
dateTextField(AUI_PTR_ALIAS(state, departureDate)),
dateTextField(AUI_PTR_ALIAS(state, returnDate))
AUI_LET { AObject::connect(state->isReturnFlight, AUI_SLOT(it)::setEnabled); },
Button {
.content = Label { "Book" },
.onClick =