Signal-slot signal slot Technology 2

Source: Internet
Author: User

Let's look at the internal implementation of sigslot. H. Take the relatively simple signal1 as an example. It can have one parameter. One of the two template parameters is a parameter type, and the other is a multithreading policy.

Focuses on its

1) connect the Connect Method to the target class and target method

2) emit method, corresponding method for sending trigger messages to the slot

Template <class arg1_type, class mt_policy = role> class signal1: Public _ signal_base1 <arg1_type, mt_policy> {public: typedef _ signal_base1 <arg1_type, mt_policy> base; typedef typename base :: connections_list; using base: m_connected_slots; signal1 () {;} signal1 (const signal1 <arg1_type, mt_policy> & S): _ signal_base1 <arg1_type, mt_policy> (s) {;} template <class desttype> voi D connect (desttype * Pclass, void (desttype: * pmemfun) (arg1_type) {lock_block <mt_policy> lock (this); _ connection1 <desttype, arg1_type, mt_policy> * conn = new _ connection1 <desttype, arg1_type, mt_policy> (Pclass, pmemfun); m_connected_slots.push_back (conn); Pclass-> signal_connect (this );} void emit (arg1_type A1) {lock_block <mt_policy> lock (this); typename connections_list: const_iterator itnext, it = m_conn Ected_slots.begin (); typename connections_list: const_iterator itend = m_connected_slots.end (); While (it! = Itend) {itnext = it; ++ itnext; (* It)-> emit (A1); It = itnext ;}} void operator () (arg1_type A1) {lock_block <mt_policy> lock (this); typename connections_list: const_iterator itnext, it = upper (); typename connections_list: const_iterator itend = lower (); While (it! = Itend) {itnext = it; ++ itnext; (* It)-> emit (A1); It = itnext ;}}};

... To be continued...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.