14#include <AUI/Common/ASignal.h>
15#include <AUI/Common/APropertyPrecomputed.h>
16#include <AUI/Common/PropertyModifier.h>
17#include <AUI/Common/detail/property.h>
30struct AProperty: AObjectBase {
31 static_assert(!std::is_reference_v<T>,
"====================> AProperty: attempt to wrap a reference.");
50 requires aui::default_initializable<T>
53 template <aui::convertible_to<T> U>
54 AProperty(U&& value) noexcept(noexcept(T(std::forward<U>(value)))):
raw(std::forward<U>(value)) {}
60 const AObjectBase* boundObject()
const {
64 AProperty(
const AProperty& value):
raw(value.
raw) {
67 AProperty(AProperty&& value)
noexcept:
raw(std::move(value.raw)) {
71 AProperty& operator=(
const AProperty& value) {
79 AProperty& operator=(AProperty&& value)
noexcept {
83 operator=(std::move(value.raw));
88 template <aui::convertible_to<T> U>
89 AProperty& operator=(U&& value)
noexcept {
90 static constexpr auto IS_COMPARABLE =
requires { this->
raw == value; };
91 if constexpr (IS_COMPARABLE) {
92 if (this->
raw == value) [[unlikely]] {
96 this->
raw = std::forward<U>(value);
101 template <ASignalInvokable SignalInvokable>
102 void operator^(SignalInvokable&& t) {
103 t.invokeSignal(
nullptr);
121 const T& value() const noexcept {
126 [[nodiscard]]
operator const T&()
const noexcept {
return value(); }
129 const T* operator->() const noexcept {
134 const T& operator*() const noexcept {
148 template<aui::invocable<const T&> Projection>
151 return aui::detail::property::makeReadonlyProjection(*
this, std::forward<Projection>(projection));
157 template<aui::invocable<const T&> ProjectionRead,
158 aui::invocable<const std::invoke_result_t<ProjectionRead, T>&> ProjectionWrite>
160 auto biProjected(ProjectionRead&& projectionRead, ProjectionWrite&& projectionWrite)
noexcept {
161 return aui::detail::property::makeBidirectionalProjection(*
this,
162 std::forward<ProjectionRead>(projectionRead),
163 std::forward<ProjectionWrite>(projectionWrite));
169 template<aui::detail::property::ProjectionB
idirectional<T> Projection>
172 return aui::detail::property::makeBidirectionalProjection(*
this, projectionBidirectional);
175 template<
typename Rhs>
176 decltype(
auto)
operator[](Rhs&& rhs)
const {
177 return raw[std::forward<Rhs>(rhs)];
181 friend class AObject;
186 auto assignment() noexcept {
187 return aui::detail::property::makeAssignment(*
this);
199 using Underlying = T;
200 PropertyModifier(
AProperty<T>& owner): mOwner(&owner) {}
201 ~PropertyModifier() {
202 if (mOwner ==
nullptr) {
209 Underlying& value()
const noexcept {
214 Underlying* operator->()
const noexcept {
225#include <AUI/Common/APropertyDef.h>
Definition AObjectBase.h:24
Temporary transparent object that gains write access to underlying property's value,...
Definition PropertyModifier.h:26
Definition concepts.h:226
Definition concepts.h:195
type_of< T > t
Selects views that are of the specified C++ types.
Definition type_of.h:71
ASignal< Args... > emits
A signal declaration.
Definition ASignal.h:577
#define emit
emits the specified signal in context of this object.
Definition AObject.h:344
Basic easy-to-use property implementation containing T.
Definition AProperty.h:30
void notify()
Notify observers that a change was occurred (no preconditions).
Definition AProperty.h:116
auto readProjected(Projection &&projection) const noexcept
Makes a readonly projection of this property.
Definition AProperty.h:150
emits< T > changed
Signal that notifies data changes.
Definition AProperty.h:47
auto biProjected(Projection &&projectionBidirectional) noexcept
Makes a bidirectional projection of this property (by a single aui::lambda_overloaded).
Definition AProperty.h:171
aui::PropertyModifier< AProperty > writeScope() noexcept
Definition AProperty.h:141
auto biProjected(ProjectionRead &&projectionRead, ProjectionWrite &&projectionWrite) noexcept
Makes a bidirectional projection of this property.
Definition AProperty.h:160
T raw
Stored value.
Definition AProperty.h:42
static void addDependency(const AAbstractSignal &signal)
Adds observer to the specified signal, if called inside a reactive expression evaluation.