signal_wrapper_base.h
Go to the documentation of this file.00001 #ifndef _SIGX_SIGNAL_BASE_HPP_
00002 #define _SIGX_SIGNAL_BASE_HPP_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <tr1/memory>
00024 #include <utility>
00025 #include <sigxconfig.h>
00026 #include <sigx/fwddecl.h>
00027 #include <sigx/static_assert.h>
00028 #include <sigx/nonheapallocatable.h>
00029 #include <sigx/shared_dispatchable.h>
00030 #include <sigx/connection_wrapper.h>
00031 #include <sigx/auto_tunneler.h>
00032
00033
00034 namespace sigx
00035 {
00036
00043 class SIGX_API signal_wrapper_base: nonheapallocatable
00044 {
00045
00046 protected:
00050 signal_wrapper_base();
00051
00052 ~signal_wrapper_base() throw();
00053 signal_wrapper_base(const shared_dispatchable& _A_disp, const std::tr1::shared_ptr<signal_source_base>& _A_sigsource) throw();
00054
00055
00056
00057
00058
00059
00064 std::pair<connection_wrapper, std::tr1::shared_ptr<sigc_connection_ptr> >
00065 prepare_connection(const tunnel_base& _A_tunnel) const;
00066
00071 template<typename T_functor, typename T_functor_conn_handler>
00072 connection_wrapper connect(const T_functor& _A_func, const T_functor_conn_handler& _A_func_conn_handler) const;
00073
00074 protected:
00077 shared_dispatchable m_disp;
00079 std::tr1::shared_ptr<signal_source_base> m_sigsource;
00080 };
00081
00082
00083 template<typename T_functor, typename T_functor_conn_handler>
00084 connection_wrapper signal_wrapper_base::connect(const T_functor& _A_func, const T_functor_conn_handler& _A_func_conn_handler) const
00085 {
00086 typedef internal::auto_tunneler<T_functor> auto_tunneler_t;
00087
00088
00089
00090
00091
00092 SIGX_STATIC_ASSERT((sigx::internal::is_or_adapts_slot<T_functor>::value == false));
00093
00094
00095 SIGX_STATIC_ASSERT((sigc::is_base_and_derived<tunnel_base, typename auto_tunneler_t::functor_type>::value == true));
00096
00097 typename auto_tunneler_t::functor_type functor2connect =
00098 auto_tunneler_t::auto_open_tunnel(_A_func);
00099
00100
00101 functor2connect.activate_validity_tracking();
00102
00103 const std::pair<connection_wrapper, std::tr1::shared_ptr<sigc_connection_ptr> >& ret =
00104 signal_wrapper_base::prepare_connection(functor2connect);
00105
00106 try
00107 {
00108
00109
00110
00111 open_tunnel_with(
00112 _A_func_conn_handler,
00113 m_disp
00114 )
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 ( ret.second, m_sigsource,
00133 sigc::exception_catch(functor2connect,
00134
00135
00136
00137
00138 bad_dispatcher_catcher<typename auto_tunneler_t::functor_type::result_type>()
00139 )
00140 );
00141 }
00142 catch (...)
00143 {
00144
00145
00146 *ret.second = 0;
00147 throw;
00148 }
00149
00150 return ret.first;
00151 }
00152
00153
00154 }
00155
00156
00157 #endif // end file guard