14#include "AObjectBase.h"
16namespace aui::detail {
17 template<
typename Object,
typename Lambda>
18 Lambda&& makeLambda(Object*, Lambda&& lambda)
requires requires { std::is_class_v<Lambda>; } {
19 return std::forward<Lambda>(lambda);
22 template<
typename Object1,
typename Object2,
typename Returns,
typename... Args>
23 auto makeLambda(Object1*
object, Returns(Object2::*method)(Args...)) {
24 return [object, method](Args...
args) {
25 (
object->*method)(std::forward<Args>(
args)...);
39class API_AUI_CORE AObject:
public AObjectBase,
public std::enable_shared_from_this<AObject>,
public aui::noncopyable {
40 friend class AAbstractSignal;
41 template <
typename ... Args>
64 virtual ~AObject() =
default;
66 static void disconnect();
81 template <AAnySignal Signal, aui::derived_from<AObjectBase> Object, ACompatibleSlotFor<Signal> Function>
82 static decltype(
auto)
connect(
const Signal& signal, Object*
object, Function&& function) {
83 return const_cast<Signal&
>(signal).
connect(
object, aui::detail::makeLambda(
object, std::forward<Function>(function)));
101 template <AAnyProperty Property, aui::derived_from<AObjectBase> Object,
typename Function>
102 static decltype(
auto)
connect(
const Property& property, Object*
object, Function&& function) {
103 auto lambda = aui::detail::makeLambda(
object, std::forward<Function>(function));
104 property.changed.makeRawInvocable(lambda)(*property);
105 return connect(property.changed,
object, std::move(lambda));
122 template <APropertyReadable PropertySource, APropertyWritable PropertyDestination>
123 static void connect(PropertySource&& propertySource, PropertyDestination&& propertyDestination)
requires requires {
128 propertyDestination.assignment());
151 template <APropertyWritable PropertySource, APropertyWritable PropertyDestination>
152 static void biConnect(PropertySource&& propertySource, PropertyDestination&& propertyDestination)
requires requires {
158 propertyDestination.assignment());
160 propertySource.assignment());
176 template <AAnySignalOrProperty Connectable, aui::derived_from<AObjectBase> Object,
177 ACompatibleSlotFor<Connectable> Function>
178 static decltype(
auto)
179 connect(
const Connectable& connectable, Object&
object, Function&& function) {
180 return connect(connectable, &
object, std::forward<Function>(function));
196 template <
typename Connectable, ACompatibleSlotFor<Connectable> Function>
197 decltype(
auto)
connect(
const Connectable& connectable, Function&& function) {
198 return connect(connectable,
this, std::forward<Function>(function));
219 template <AAnySignalOrProperty Connectable, aui::derived_from<AObjectBase> Object, ACompatibleSlotFor<Connectable> Function>
220 static decltype(
auto)
222 return connect(connectable,
object.get(), std::forward<Function>(function));
244 template <AAnySignalOrProperty Connectable, aui::derived_from<AObjectBase> Object,
typename Function>
245 static decltype(
auto)
247 return connect(connectable, slotDef.boundObject, std::move(slotDef.invocable));
267 template <AAnyProperty Property,
typename Object, ACompatibleSlotFor<Property> Function>
272 property.changed.makeRawInvocable(function)(*property);
273 connect(property.changed,
object, std::forward<Function>(function));
274 const_cast<std::decay_t<decltype(property.changed)
>&>(
property.changed).connectNonAObject(std::move(
object), aui::detail::makeLambda(
object,std::forward<Function>(function)));
277 void setSignalsEnabled(
bool enabled) { mSignalsEnabled = enabled; }
279 [[nodiscard]]
bool isSignalsEnabled() const noexcept {
return mSignalsEnabled; }
281 template <ASignalInvokable T>
282 void operator^(T&& t)
noexcept {
283 if (mSignalsEnabled) {
284 t.invokeSignal(
this);
289 const _<AAbstractThread>& getThread() const noexcept {
return mAttachedThread; }
291 bool isSlotsCallsOnlyOnMyThread() const noexcept {
return mSlotsCallsOnlyOnMyThread; }
293 static void moveToThread(aui::no_escape<AObject>
object, _<AAbstractThread> thread);
295 void setSlotsCallsOnlyOnMyThread(
bool slotsCallsOnlyOnMyThread) {
296 mSlotsCallsOnlyOnMyThread = slotsCallsOnlyOnMyThread;
307 bool mSignalsEnabled =
true;
315 bool mSlotsCallsOnlyOnMyThread =
false;
317 static bool& isDisconnected();
340#define emit (*this) ^
367#define AUI_EMIT_FOREIGN(object, signal, ...) (*object) ^ object->signal(__VA_ARGS__)
369#include "SharedPtr.h"
static decltype(auto) connect(const Connectable &connectable, ASlotDef< Object *, Function > slotDef)
Connects signal to the slot of the specified object. Slot is packed to single argument.
Definition AObject.h:246
void setThread(_< AAbstractThread > thread)
Set thread of the object.
Definition AObject.h:303
static constexpr AObjectBase * GENERIC_OBSERVER
Indicates that a connection should not be explicitly linked to receiver's lifetime.
Definition AObject.h:61
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:215
type_of< T > t
Selects views that are of the specified C++ types.
Definition type_of.h:71
API_AUI_CORE const ACommandLineArgs & args() noexcept
static decltype(auto) connect(const Property &property, Object *object, Function &&function)
Connects property to the slot of the specified object.
Definition AObject.h:102
static void biConnect(PropertySource &&propertySource, PropertyDestination &&propertyDestination)
Connects source property to the destination property and opposite (bidirectionally).
Definition AObject.h:152
static void connect(const Property &property, _< Object > object, Function &&function)
Connects signal or property to the slot of the specified non-AObject type.
Definition AObject.h:269
static void connect(PropertySource &&propertySource, PropertyDestination &&propertyDestination)
Connects source property to the destination property.
Definition AObject.h:123
static decltype(auto) connect(const Connectable &connectable, Object &object, Function &&function)
Connects signal or property to the slot of the specified object.
Definition AObject.h:179
static decltype(auto) connect(const Signal &signal, Object *object, Function &&function)
Connects signal to the slot of the specified object.
Definition AObject.h:82
static decltype(auto) connect(const Connectable &connectable, _< Object > object, Function &&function)
Connects signal or property to the slot of the specified object.
Definition AObject.h:221
decltype(auto) connect(const Connectable &connectable, Function &&function)
Connects signal or property to slot of "this" object.
Definition AObject.h:197
Definition concepts.h:188
Forbids copy of your class.
Definition values.h:45