4#include <photon/PtWidget.h>
16 template<
typename ValueT,
typename ParentT>
17 struct get_parent_func
19 typedef ValueT value_t;
20 typedef ParentT parent_t;
21 typedef void(parent_t::* adder_t)(value_t);
22 typedef void(parent_t::* remover_t)(value_t);
24 static const adder_t &default_adder() {
static adder_t adder = adder_t(0);
return adder; }
25 static const remover_t &default_remover() {
static remover_t remover = remover_t(0);
return remover; }
29 struct get_parent_func<void, void>
32 typedef Void parent_t;
33 typedef const int adder_t;
34 typedef const int remover_t;
36 static const adder_t &default_adder() {
static adder_t adder = 0;
return adder; }
37 static const remover_t &default_remover() {
static remover_t remover = 0;
return remover; }
40 template<
typename ValueT>
41 struct get_parent_func<ValueT, void> :
42 public get_parent_func<void, void>
46 template<
typename ParentT>
47 struct get_parent_func<void, ParentT> :
48 public get_parent_func<void, void>
55 class callback_container
62 template<
class Param1T,
class Param2T,
class Param3T>
63 callback_container(
int(*callback)( Param1T, Param2T, Param3T)):
64 _callback(reinterpret_cast<callback_t>(callback)),
65 _proxy_call(&callback_container::proxy_call<Param1T, Param2T, Param3T>)
68 template<
class Param1T,
class Param2T,
class Param3T>
71 _proxy_call = &callback_container::proxy_call<Param1T, Param2T, Param3T>;
76 return _proxy_call(
this, p1, p2, p3);
79 inline bool operator<(
const callback_container &rhs)
const
81 if(std::less<callback_t>()(_callback, rhs._callback))
83 if(std::less<callback_proxy_t>()(_proxy_call, rhs._proxy_call))
91 callback_proxy_t _proxy_call;
93 template<
class Param1T,
class Param2T,
class Param3T>
96 return reinterpret_cast<int(*)(Param1T, Param2T, Param3T)
>(container->_callback)(p1,
reinterpret_cast<Param2T
>(p2), p3);
105 typedef std::set<callback_container> callback_repo_t;
109 cb_with_data(callback_container cb,
void *dt = 0)
111 std::pair<callback_repo_t::iterator, bool> res = cb_with_data::repo().insert(cb);
113 callback = &(*res.first);
119 return (*callback)(p1, data, p3);
122 inline bool operator<(
const cb_with_data &rhs)
const
124 if(std::less<const callback_container*>()(callback, rhs.callback))
126 if(std::less<void*>()(data, rhs.data))
133 const callback_container *callback;
136 static callback_repo_t &repo() {
static callback_repo_t repo;
return repo; }
139 typedef std::set<cb_with_data> cb_data_repo_t;
141 static cb_data_repo_t &repo() {
static cb_data_repo_t repo;
return repo; }
145 const cb_with_data &cbwd = *
reinterpret_cast<const cb_with_data*
>(p2);
147 cb_data_repo_t::iterator it = repo().find(cbwd);
149 if(repo().end() == it)
160 template<
class Param1T,
class Param2T,
class Param3T>
161 ph_callback_t(
int(*value)(Param1T, Param2T, Param3T))
163 std::pair<cb_data_repo_t::iterator, bool> res = repo().insert(cb_with_data(value));
165 _callback.event_f = &proxy_call;
166 _callback.data =
const_cast<cb_with_data*
>(&(*(res.first)));
169 template<
class Param1T,
class Param2T,
class Param3T>
170 ph_callback_t(
int(*value)(Param1T, Param2T, Param3T), Param2T &data)
172 std::pair<cb_data_repo_t::iterator, bool> res = repo().insert(cb_with_data(value, data));
174 _callback.event_f = &proxy_call;
175 _callback.data =
const_cast<cb_with_data*
>(&(*(res.first)));
183 inline operator PtCallback_t()
const{
return _callback; }
189 template<class ParentT, typename detail::get_parent_func<ph_callback_t, ParentT>::adder_t Adder,
typename detail::get_parent_func<ph_callback_t, ParentT>::remover_t Remover = detail::get_parent_func<ph_callback_t, ParentT>::default_remover()>
192 typedef typename detail::get_parent_func<ph_callback_t, ParentT>::value_t value_t;
195 bind(ParentT *parent) :
199 inline void add(value_t value)
201 (_obj->*Adder)(value);
204 inline void remove(value_t value)
206 (_obj->*Remover)(value);
209 inline void operator+=(value_t value)
214 inline void operator-=(value_t value)
223 bind(
const bind &rhs);
225 inline bind &operator=(value_t);
226 inline bind &operator=(bind
const &);