// 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 namespace Ui { namespace details { template class AttachmentOwner : public QObject { public: template AttachmentOwner(QObject *parent, Args &&...args) : QObject(parent) , _value(std::forward(args)...) { } gsl::not_null value() { return &_value; } private: Value _value; }; } // namespace details template inline Value *CreateChild( Parent parent, Args &&...args) { if constexpr (std::is_pointer_v) { Expects(parent != nullptr); if constexpr (std::is_base_of_v) { return new Value(parent, std::forward(args)...); } else { return CreateChild>( parent, std::forward(args)...)->value(); } } else if constexpr (requires(const Parent & t) { t.get(); }) { return new Value(parent.get(), std::forward(args)...); } else { static_assert(requires(const Parent &t) { t.data(); }); return new Value(parent.data(), std::forward(args)...); } } template inline gsl::not_null>*> WrapAsQObject( gsl::not_null parent, Value &&value) { return CreateChild>>( parent.get(), std::forward(value)); } } // namespace Ui