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

  

时间: 2024-08-25 01:14:22

boost signal2 trackable的相关文章

boost signal2 slot_base

先看成员_tracked_objects,从字面上讲是被跟踪的对象,再看,相关函数 bool expired() const,这个函数是检查_tracked_objects是否已经expired.只不过是使用一些设计模式上的东西,理解也比较好理解, if(apply_visitor(detail::expired_weak_ptr_visitor(), *it)) return true; 实质也就是将*it传入detail::expired_weak_ptr_visitor(),其实就是调用仿

Boost signal 代码示例

网上介绍Boost signal原理的文章很多,这里不介绍原理,仅贴一些示例代码,这在初步接触Boost signal时能够有个较好的感性认识,深入了解需要去体会挖掘boost源码.代码基本上来自Boost turioal,其中有一些错误会导致编译不过,这里都做了更正: 1. 基本运用 #include <boost/signals2.hpp> #include <boost/bind.hpp> #include <iostream> using namespace s

Visual Studio 2013 boost

E:\Visual Studio 2013\install\VC\bin\amd64>E:\IFC\boost_1_56_0_vs2013'E:\IFC\boost_1_56_0_vs2013' 不是内部或外部命令,也不是可运行的程序或批处理文件. E:\Visual Studio 2013\install\VC\bin\amd64>cd E:\IFC\boost_1_56_0_vs2013 E:\IFC\boost_1_56_0_vs2013>E:\IFC\boost_1_56_0_v

mac下编译 boost编译工具b2

cd boost_1_64_0/tools/build ./bootstrap.sh --with-toolset=gcc 输出: -n Bootstrapping the build engine with toolset gcc... engine/bin.macosxx86_64/b2 Bootstrapping is done. To build and install, run: ./b2 install --prefix=<DIR> ./b2 install --prefix=/u

10 C++ Boost ASIO网路通信库 TCP/UDP,HTTP

  tcp 同步服务器,显示服务器端时间 tcp 同步服务器,提供多种选择 多线程的tcp 同步服务器 tcp 同步客户端 boost 域名地址解析 tcp异步服务器 tcp 异步客户端 UDP同步服务器 UDP同步客户端 UDP异步服务器 UDP异步客户端 HTTP同步客户端 HTTP异步客户端 同步实验: 异步实验 多线程异步实验 tcp 同步服务器,显示服务器端时间 [email protected]:~/boost$ cat main.cpp  #include <ctime> #in

Boost学习笔记(三) progress_timer

progress_timer也是一个计时器,它继承自timer,会在析构时自动输出时间,省去timer手动调用elapsed()的工作,是一个用于自动计时相当方便的小工具. #include <boost\timer.hpp> #include <boost\progress.hpp> #include <iostream> using namespace boost; using namespace std; int main() { boost::progress_

Boost练习程序(multi_index_container)

代码来自:http://blog.csdn.net/whuqin/article/details/8482547 该容器能实现多列索引,挺好. #include <string> #include <iostream> #include <boost/multi_index_container.hpp> #include <boost/multi_index/member.hpp> #include <boost/multi_index/ordered

win7 codeblock在调用boost::asio中遇到的错误———解决办法

错误一:    undefined reference to `boost::system::generic_category()'         undefined reference to `boost::system::generic_category()'         undefined reference to `boost::system::system_category()' 解决办法:在boost的system库的error_code.hpp源代码中添加: #define

boost智能指针使用

#include <iostream> #include <tr1/memory> #include <boost/scoped_ptr.hpp> //scoped_ptr还不属于tr1 #include <boost/scoped_array.hpp> //scored_array也不属于tr1 #include <boost/shared_array.hpp> //shared_array也不属于tr1 class CTest { publi