AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
APropertyDef< M, Getter, Setter, SignalArg > Struct Template Reference

Property implementation to use with custom getter/setter. More...

#include <AUI/Common/AProperty.h>

Public Types

using Model = M
 
using GetterReturnT = decltype(std::invoke(get, base))
 
using Underlying = std::decay_t<GetterReturnT>
 

Public Member Functions

 APropertyDef (const M *base, Getter get, Setter set, const emits< SignalArg > &changed)
 
template<aui::convertible_to< Underlying > U>
APropertyDefoperator= (U &&u)
 
GetterReturnT value () const noexcept
 
GetterReturnT operator* () const noexcept
 
const Underlying * operator-> () const noexcept
 
 operator GetterReturnT () const noexcept
 
M * boundObject () const
 
template<aui::invocable< const Underlying & > Projection>
auto readProjected (Projection &&projection) noexcept
 Makes a readonly projection of this property.
 
template<aui::invocable< const Underlying & > ProjectionRead, aui::invocable< const std::invoke_result_t< ProjectionRead, Underlying > & > ProjectionWrite>
auto biProjected (ProjectionRead &&projectionRead, ProjectionWrite &&projectionWrite) noexcept
 Makes a bidirectional projection of this property.
 
template<aui::detail::property::ProjectionBidirectional< Underlying > Projection>
auto biProjected (Projection &&projectionBidirectional) noexcept
 Makes a bidirectional projection of this property (by a single aui::lambda_overloaded).
 

Signals and public fields

const M * base
 AObject which this property belongs to.
 
Getter get
 Getter. Can be pointer-to-member(function or field) or lambda.
 
Setter set
 Setter. Can be pointer-to-member(function or field) or lambda.
 
const emits< SignalArg > & changed
 Reference to underlying signal emitting on value changes.
 

Detailed Description

template<typename M, aui::invocable< M & > Getter, aui::invocable< M &, std::invoke_result_t< Getter, M & > > Setter, typename SignalArg>
struct APropertyDef< M, Getter, Setter, SignalArg >

Property implementation to use with custom getter/setter.

See property system for more info.

class User: public AObject {
public:
auto name() const {
return APropertyDef {
this,
&User::getName, // this works too: &User::mName
&User::setName,
mNameChanged,
};
}
private:
AString mName;
emits<AString> mNameChanged;
void setName(AString name) {
// APropertyDef requires us to emit
// changed signal if value is actually
// changed
if (mName == name) {
return;
}
mName = std::move(name);
emit mNameChanged(mName);
}
const AString& getName() const {
return mName;
}
};
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

Performance considerations

APropertyDef does not involve extra runtime overhead between assignment and getter/setter.

Examples
/home/runner/work/aui/aui/aui.views/src/AUI/View/AView.h.

Member Data Documentation

◆ set

template<typename M, aui::invocable< M & > Getter, aui::invocable< M &, std::invoke_result_t< Getter, M & > > Setter, typename SignalArg>
Setter APropertyDef< M, Getter, Setter, SignalArg >::set

Setter. Can be pointer-to-member(function or field) or lambda.

The setter implementation typically emits changed signal. If it is, it must emit changes only if value is actually changed.

void setValue(int value) {
if (mValue == value) {
return;
}
mValue = value;
emit mValueChanged(valueChanged);
}

The documentation for this struct was generated from the following file:
Collaboration diagram for APropertyDef< M, Getter, Setter, SignalArg >: