// This file is part of Desktop App Toolkit, // a set of libraries for developing nice desktop applications. // // For license and copyright information please follow this link: // https://github.com/desktop-app/legal/blob/master/LEGAL // #pragma once #include #if __has_include() class QObject; template class QPointer; template class QWeakPointer; template class QSharedPointer; #if __has_include() namespace gsl { template class not_null; } // namespace gsl #endif // gsl namespace crl { template struct guard_traits; template struct guard_traits, void> { static QPointer create(const QPointer &value) { return value; } static QPointer create(QPointer &&value) { return std::move(value); } static bool check(const QPointer &guard) { return guard.data() != nullptr; } }; template struct guard_traits< T*, std::enable_if_t< std::is_base_of_v>>> { static QPointer create(T *value) { return value; } static bool check(const QPointer &guard) { return guard.data() != nullptr; } }; #if __has_include() template struct guard_traits< gsl::not_null, std::enable_if_t< std::is_base_of_v>>> { static QPointer create(gsl::not_null value) { return value.get(); } static bool check(const QPointer &guard) { return guard.data() != nullptr; } }; #endif // gsl template struct guard_traits, void> { static QWeakPointer create(const QWeakPointer &value) { return value; } static QWeakPointer create(QWeakPointer &&value) { return std::move(value); } static bool check(const QWeakPointer &guard) { return guard.toStrongRef() != nullptr; } }; template struct guard_traits, void> { static QWeakPointer create(const QSharedPointer &value) { return value; } static QWeakPointer create(QSharedPointer &&value) { return value; } static bool check(const QWeakPointer &guard) { return guard.toStrongRef() != nullptr; } }; } // namespace crl #endif // Qt