posts - 58,  comments - 75,  trackbacks - 0

/////////////////////////////////////////////////////////////////////
//slot_base
class BOOST_SIGNALS_DECL slot_base
{
public:
 struct data_t
 {
  std::vector<const trackable*> bound_objects;
  connection watch_bound_objects;
 };
 shared_ptr<data_t> get_data() const { return data; }

 std::vector<const trackable*>& get_bound_objects() const
 {
  return data->bound_objects;
 }

 bool is_active() const
 {
  return data->watch_bound_objects.connected();
 }

protected:
 void create_connection();
 shared_ptr<data_t> data;

private:
 static void bound_object_destructed(void*, void*) {}
};

//////////////////////////////////////////////////////////////////////////////////
//slot
template<typename SlotFunction>
class slot : public BOOST_SIGNALS_NAMESPACE::detail::slot_base
{
 typedef BOOST_SIGNALS_NAMESPACE::detail::slot_base inherited;
 typedef typename inherited::data_t data_t;
public:
 template<typename F>
 slot(const F& f) : slot_function(BOOST_SIGNALS_NAMESPACE::get_invocable_slot(f, BOOST_SIGNALS_NAMESPACE::tag_type(f)))
 {
  this->data.reset(new data_t);
  BOOST_SIGNALS_NAMESPACE::detail::bound_objects_visitor do_bind(this->data->bound_objects);
  visit_each(do_bind,
       BOOST_SIGNALS_NAMESPACE::get_inspectable_slot
          (f, BOOST_SIGNALS_NAMESPACE::tag_type(f)));
  create_connection();
 }
public:
 const SlotFunction& get_slot_function() const { return slot_function; }

 void release() const { data->watch_bound_objects.set_controlling(false); }

private:
 slot();
 slot& operator=(const slot&);

 SlotFunction slot_function;
};

//////////////////////////////////////////////////////////////////////////
//slot_base::create_connection
void slot_base::create_connection()
{
 basic_connection* con = new basic_connection();

 {
  con->signal = static_cast<void*>(this);
  con->signal_data = 0;
  con->blocked_ = false ;
  con->signal_disconnect = &bound_object_destructed;
 }
 
 data->watch_bound_objects.reset(con);

 scoped_connection safe_connection(data->watch_bound_objects);

 for(std::vector<const trackable*>::iterator i = data->bound_objects.begin();
  i != data->bound_objects.end(); ++i)
 {
  BOOST_SIGNALS_NAMESPACE::detail::bound_object binding;
  (*i)->signal_connected(data->watch_bound_objects, binding);

  BOOST_SIGNALS_NAMESPACE::detail::auto_disconnect_bound_object disconnector(binding);

  con->bound_objects.push_back(binding);
  disconnector.release();
 }

 safe_connection.release();
 data->watch_bound_objects.set_controlling(true);
}

posted on 2007-04-24 15:15 walkspeed 阅读(521) 评论(0)  编辑 收藏 引用 所属分类: boost学习

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理



<2024年12月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(4)

随笔分类(64)

随笔档案(58)

文章分类(3)

文章档案(3)

相册

收藏夹(9)

C++零碎

好友

搜索

  •  

积分与排名

  • 积分 - 159886
  • 排名 - 163

最新评论

阅读排行榜

评论排行榜