AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
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
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<AObject> object) noexcept = 0;
380 virtual void clearAllConnections() noexcept = 0;
381
382protected:
383 void linkSlot(AObject* object) noexcept;
384 void unlinkSlot(AObject* object) noexcept;
385
386 static bool& isDisconnected();
387
388 static _weak<AObject> weakPtrFromObject(AObject* object);
389
390private:
391 bool mDestroyed = false;
392};
393
394#include <AUI/Common/AObject.h>
395
396inline bool& AAbstractSignal::isDisconnected() {
397 return AObject::isDisconnected();
398}
399
400inline _weak<AObject> AAbstractSignal::weakPtrFromObject(AObject* object) { // AAbstractSignal is a friend of AObject
401 return object->weakPtr();
402}
Base class for signal.
Definition: AAbstractSignal.h:368
A base object class.
Definition: AObject.h:49
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