14#include "AObjectBase.h"
17namespace aui::property_precomputed {
19struct DependencyObserver : AObjectBase {
21 virtual void invalidate() = 0;
24struct API_AUI_CORE DependencyObserverRegistrar {
25 explicit DependencyObserverRegistrar(DependencyObserver& observer);
26 ~DependencyObserverRegistrar();
29 DependencyObserver* mPrevObserver;
37API_AUI_CORE
void addDependency(
const AAbstractSignal& signal);
64struct APropertyPrecomputed final : aui::property_precomputed::detail::DependencyObserver {
66 using Factory = std::function<T()>;
68 template<aui::factory<T> Factory>
69 APropertyPrecomputed(Factory&& expression): mCurrentValue([
this, expression = std::forward<Factory>(expression)] {
71 aui::property_precomputed::detail::DependencyObserverRegistrar r(*
this);
77 APropertyPrecomputed(
const APropertyPrecomputed&) =
delete;
78 APropertyPrecomputed(APropertyPrecomputed&&)
noexcept =
delete;
80 template <ASignalInvokable SignalInvokable>
81 void operator^(SignalInvokable&& t) {
82 t.invokeSignal(
nullptr);
85 void invalidate()
override {
86 mCurrentValue.reset();
88 emit this->changed(value());
92 AObjectBase* boundObject() {
97 const T& value()
const {
102 operator const T&()
const {
107 const T& operator*()
const {
118template<aui::invocable<> Factory>
Definition concepts.h:194
ASignal< Args... > emits
A signal declaration.
Definition ASignal.h:348
#define emit
emits the specified signal in context of this object.
Definition AObject.h:310
Definition APropertyPrecomputed.h:64
A value that initializes when accessed for the first time.
Definition values.h:182