diff --git a/src/public/asyncrenderloop.h b/src/public/asyncrenderloop.h index 0b61b58..ab91232 100644 --- a/src/public/asyncrenderloop.h +++ b/src/public/asyncrenderloop.h @@ -49,6 +49,7 @@ namespace QH { * int main (int argc, char* argv[]) { * auto loop = QSharedPointer(new MyRenderLoop(new QThread())); // wrong! it will be broken * auto loop = MyRenderLoop::MainSharedPtr>(QSharedPointer::create(new QThread())); // right! + * auto loop = MyRenderLoop::createMainPtr(new QThread()); // this is short version of initialization Main pointer * ... * return app.exec(); * } @@ -69,6 +70,11 @@ public: template class MainSharedPtr { public: + MainSharedPtr() { + static_assert(std::is_base_of_v, + "T must be derived from QSharedPointer"); + } + MainSharedPtr(const T& ptr): _ptr(ptr) { static_assert(std::is_base_of_v, "T must be derived from QSharedPointer"); @@ -83,14 +89,27 @@ public: return _ptr.operator->(); } + /** + * @brief get This is a alias of the QSharedPointer::get method. + * @return pointer to the object. + */ typename T::element_type* get() const { return _ptr.get(); } + /** + * @brief getShared This method return child shared pointer. You can use them as a general shared pointer of the object. + * @return reference to the object. + */ + const T& getShared() const { + return _ptr; + } + private: T _ptr; }; + AsyncRenderLoop(QThread* thread, QObject* ptr = nullptr); ~AsyncRenderLoop(); @@ -110,6 +129,18 @@ public: */ bool isRun() const; + /** + * @brief createMainPtr This method creates a shared pointer to the render loop. + * @tparam Type type of the render loop object. + * @tparam Args arguments for the constructor of the render loop object. + * @param arguments arguments for the constructor of the render loop object. + * @return shared pointer to the render loop. + */ + template + static MainSharedPtr> createMainPtr(Args && ...arguments) { + return MainSharedPtr>(QSharedPointer::create(std::forward(arguments)...)); + }; + protected: /** @@ -130,4 +161,5 @@ private: }; } + #endif // ASYNCRENDERLOOP_H