标签:
挺简单的一个类,只是维护了一个成员 shared_ptr<detail::trackable_pointee> _tracked_ptr; 这样看来的话,所谓的track还是基于智能指针,这里注意,track的对象需要从trackable_pointee继承,一个空类,主要还是为了用于标识。
#ifndef BOOST_SIGNALS2_TRACKABLE_HPP #define BOOST_SIGNALS2_TRACKABLE_HPP #include <boost/assert.hpp> #include <boost/shared_ptr.hpp> #include <boost/weak_ptr.hpp> namespace boost { namespace signals2 { namespace detail { class tracked_objects_visitor; // trackable_pointee is used to identify the tracked shared_ptr // originating from the signals2::trackable class. These tracked // shared_ptr are special in that we shouldn‘t bother to // increment their use count during signal invocation, since // they don‘t actually control the lifetime of the // signals2::trackable object they are associated with. class trackable_pointee {}; } class trackable { protected: trackable(): _tracked_ptr(static_cast<detail::trackable_pointee*>(0)) {} trackable(const trackable &): _tracked_ptr(static_cast<detail::trackable_pointee*>(0)) {} trackable& operator=(const trackable &) { return *this; } ~trackable() {} private: friend class detail::tracked_objects_visitor; weak_ptr<detail::trackable_pointee> get_weak_ptr() const { return _tracked_ptr; } shared_ptr<detail::trackable_pointee> _tracked_ptr; }; } // end namespace signals2 } // end namespace boost #endif // BOOST_SIGNALS2_TRACKABLE_HPP
标签:
原文地址:http://www.cnblogs.com/csxy/p/5456879.html