From 54932f433b1001a3ec4b4ea51d0865acb8dabf5e Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Fri, 21 Jun 2019 13:28:51 +0800 Subject: [PATCH] Gui: add convenient smart pointer CoinPtr to manager coin node --- src/Gui/ViewProvider.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Gui/ViewProvider.h b/src/Gui/ViewProvider.h index 9d175230b1cd..2bf274ec2add 100644 --- a/src/Gui/ViewProvider.h +++ b/src/Gui/ViewProvider.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -77,6 +78,26 @@ enum ViewStatus { }; +/** Convenience smart pointer to wrap coin node. + * + * It is basically boost::intrusive plus implicit pointer conversion to save the + * trouble of typing get() all the time. + */ +template +class CoinPtr: public boost::intrusive_ptr { +public: + // Too bad, VC2013 does not support constructor inheritance + //using boost::intrusive_ptr::intrusive_ptr; + typedef boost::intrusive_ptr inherited; + CoinPtr() {} + CoinPtr(T *p, bool add_ref=true):inherited(p,add_ref){} + template CoinPtr(CoinPtr const &r):inherited(r){} + + operator T *() const { + return this->get(); + } +}; + /** General interface for all visual stuff in FreeCAD * This class is used to generate and handle all around