boost signal2 trackable

挺简单的一个类,只是维护了一个成员 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

  

转载于:https://www.cnblogs.com/csxy/p/5456879.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值