AUI Framework  develop
Cross-platform base for C++ UI apps
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages Concepts
SharedPtr.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 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 "SharedPtrTypes.h"
   15
   16#include <AUI/Common/AObject.h>
   17#include <AUI/Thread/AThread.h>
   18#include <AUI/Reflect/AClass.h>
   19
   20template<typename T, typename... Args>
   21inline _<T> _new(Args&& ... args)
   22{
   23    return static_cast<_<T>>(std::make_shared<T>(std::forward<Args>(args)...));
   24}
   25
   26template<typename T, typename E>
   27inline _<T> _new(std::initializer_list<E> il) {
   28    return static_cast<_<T>>(std::make_shared<T>(il.begin(), il.end()));
   29}
   30
   31
   32template<typename T>
   33std::ostream& operator<<(std::ostream& os, const _<T>& rhs) noexcept {
   34    return os << "[" << AClass<T>::name() << " " << rhs.get() << "]";
   35}
   36
   37// gtest printer
   38template<typename T>
   39inline void PrintTo(const _<T>& ptr, std::ostream* stream) {
   40    *stream << ptr;
   41}
   42
   43template<typename T>
   44template<typename SignalField, typename Object, typename Function>
   45inline _<T>& _<T>::connect(SignalField signalField, Object object, Function&& function) {
   46    AObject::connect(super::get()->*signalField, object, std::forward<Function>(function));
   47    return *this;
   48}
   49
   50template<typename T>
   51template<typename SignalField, typename Function>
   52inline _<T>& _<T>::connect(SignalField signalField, Function&& function) {
   53    AObject::connect(super::get()->*signalField, super::get(), std::forward<Function>(function));
   54    return *this;
   55}
   56
   57
   58#ifdef AUI_SHARED_PTR_FIND_INSTANCES
   59template<typename T>
   61    return AStacktrace::capture(3);
   62}
   63#endif
static AString name()
[ARROW_ERROR_MESSAGE_EXAMPLE]
Definition AClass.h:28
Stacktrace consisting of a collection of stack function frames.
Definition AStacktrace.h:28
static AStacktrace capture(unsigned skipFrames=0, unsigned maxFrames=128) noexcept
Creates stacktrace of the current thread.
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.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:86