Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)

toolbox/sharedPointer.hh
Go to the documentation of this file.
00001 #pragma once
00002 #include "boost/shared_ptr.hpp"
00003 #include "boost/weak_ptr.hpp"
00004 
00005 namespace concepts {
00006 
00007   struct null_deleter
00008   {
00009     void operator()(void const *) const
00010     {
00011     }
00012   };
00013 
00019   template<class T>
00020   class RCP : public boost::shared_ptr<T>
00021   {
00022   public:
00024     RCP() : boost::shared_ptr<T>() {}
00025 
00038     explicit RCP(T* x) : boost::shared_ptr<T>(x) {}
00039     
00040     RCP(boost::shared_ptr<T>& x) : boost::shared_ptr<T>(x) {}
00041 
00042     template<class F>
00043     RCP(const boost::shared_ptr<F>& x) : boost::shared_ptr<T>(x) {}
00044 
00046     template<class F, class G>
00047     RCP(F x, G y) : boost::shared_ptr<T>(x, y) {}
00048 
00049     RCP<T>& operator=(const RCP<T> x)
00050     {
00051       RCP<T>(x).swap(*this);
00052       return *this;
00053     }
00054 
00055     template<class F>
00056     RCP<T>& operator=(const boost::shared_ptr<F> x)
00057     {
00058       RCP<T>(x).swap(*this);
00059       return *this;
00060     }
00061 
00062     // this conversion operator is already implemented for shared_ptr
00063     #if 0 
00064     // template function for implicit conversion ops.
00065     template<class NewType>
00066       operator RCP<NewType>() 
00067       {
00068         return RCP<NewType>( boost::shared_ptr<NewType>(*this) ); 
00069       }
00070     #endif
00071   };
00072 
00091   template <class T>
00092   RCP<T> makeRCP(T* x)
00093   {
00094     return RCP<T>(x);
00095   }
00096 
00109   template<class T>
00110   RCP<T> makeRCP_weak(T* x)
00111   {
00112     return RCP<T>(x, null_deleter());
00113   }
00114   
00115     #if 1
00116   template<class T>
00117   RCP<const T> makecRCP_weak(T* x) // create a const pointer
00118   {
00119     return RCP<const T>(x, null_deleter());
00120   }
00121   #endif
00122 
00123 
00124 } // namespace concepts

Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)