AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AAbstractSignal.h
1/*
2 * AUI Framework - Declarative UI toolkit for modern C++20
3 * Copyright (C) 2020-2024 Alex2772 and Contributors
4 *
5 * SPDX-License-Identifier: MPL-2.0
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 */
11
12#pragma once
13
14#include <exception>
15
16#include <AUI/Core.h>
17#include <AUI/Common/SharedPtrTypes.h>
18#include <AUI/Traits/values.h>
19
20class AObject;
21
358
359
367class API_AUI_CORE AAbstractSignal
368{
369 friend class AObject;
370public:
371 virtual ~AAbstractSignal() {
372 mDestroyed = true;
373 }
374
375 [[nodiscard]] bool isDestroyed() const noexcept {
376 return mDestroyed;
377 }
378
379 virtual void clearAllConnectionsWith(aui::no_escape<AObjectBase> object) const noexcept = 0;
380 virtual void clearAllConnections() const noexcept = 0;
381
382 virtual void addGenericObserver(AObjectBase* object, std::function<void()> observer) = 0;
383
384 [[nodiscard]]
385 virtual bool hasConnectionsWith(aui::no_escape<AObjectBase> object) const noexcept = 0;
386
387protected:
388 void linkSlot(AObjectBase* object) noexcept;
389 void unlinkSlot(AObjectBase* object) noexcept;
390
391 static bool& isDisconnected();
392
393 static _weak<AObject> weakPtrFromObject(AObject* object);
394
395private:
396 bool mDestroyed = false;
397};
398
399#include <AUI/Common/AObject.h>
400
401inline bool& AAbstractSignal::isDisconnected() {
402 return AObject::isDisconnected();
403}
404
405inline _weak<AObject> AAbstractSignal::weakPtrFromObject(AObject* object) { // AAbstractSignal is a friend of AObject
406 return object->weakPtr();
407}
Base class for signal.
Definition AAbstractSignal.h:368
Definition AObjectBase.h:23
A base object class.
Definition AObject.h:39
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:51
Does not allow escaping, allowing to accept lvalue ref, rvalue ref, shared_ptr and etc without overhe...
Definition values.h:127