7#ifndef MYGUI_DELEGATE_H_
8#define MYGUI_DELEGATE_H_
29 m_baseDelegateUnlink =
this;
33 return m_baseDelegateUnlink == _unlink->m_baseDelegateUnlink;
40 template <
typename ...Args>
49 mFunctionPointer(_functionPointer)
58 mFunctionPointer(_functionPointer)
67 mFunctionPointer(_functionPointer)
78 if (
nullptr == _delegate)
return false;
79 return _delegate->mObject == mObject && _delegate->mFunctionPointer.
compare(mFunctionPointer);
84 return mUnlink == _unlink;
91 const void* mObject =
nullptr;
98template <
typename ...Args>
105template <
typename T,
typename ...Args>
109 [=](Args&&... args) {
return (_object->*_method)(std::forward<decltype(args)>(args)...); },
113template <
typename T,
typename ...Args>
117 [=](Args&&... args) {
return (_object->*_method)(std::forward<decltype(args)>(args)...); },
125template <
typename ...Args>
134 template <
typename ...Args>
144 mDelegate = _event.mDelegate;
145 const_cast<Delegate&
>(_event).mDelegate =
nullptr;
155 return mDelegate ==
nullptr;
167 mDelegate = _delegate;
178 const_cast<Delegate&
>(_event).mDelegate =
nullptr;
180 if (mDelegate !=
nullptr && !mDelegate->
compare(del))
190 if (mDelegate ==
nullptr)
return;
191 mDelegate->
invoke(args...);
198 template <
typename ...Args>
213 for (
const auto& delegate : mListDelegates)
215 if (delegate)
return false;
222 for (
auto iter = mListDelegates.begin(); iter != mListDelegates.end(); ++iter)
234 for (
auto iter = mListDelegates.begin(); iter != mListDelegates.end(); ++iter)
236 if ((*iter) && (*iter)->compare(_unlink))
246 for (
auto iter = mListDelegates.begin(); iter != mListDelegates.end(); ++iter)
248 if ((*iter) && (*iter)->compare(_delegate))
253 mListDelegates.push_back(_delegate);
258 for (
auto iter = mListDelegates.begin(); iter != mListDelegates.end(); ++iter)
260 if ((*iter) && (*iter)->compare(_delegate))
262 if ((*iter) != _delegate)
delete (*iter);
272 auto iter = mListDelegates.begin();
273 while (iter != mListDelegates.end())
275 if (
nullptr == (*iter))
277 iter = mListDelegates.erase(iter);
281 (*iter)->invoke(args...);
295 mListDelegates = del;
306 mListDelegates = del;
322 for (
auto iter = mListDelegates.begin(); iter != mListDelegates.end(); ++iter)
328 delete_is_not_found(del, _delegates);
335 for (
auto iter = _delegates.begin(); iter != _delegates.end(); ++iter)
337 if ((*iter) && (*iter)->compare(_del))
352 template <
typename ...Args>
354 template <
typename ...Args>
356 template <
typename ...Args>
358 template <
typename ...Args>
360 template <
typename ...Args>
362 template <
typename ...Args>
366 template <
typename ...Args>
368 template <
typename ...Args>
370 template <
typename ...Args>
372 template <
typename ...Args>
374 template <
typename ...Args>
376 template <
typename ...Args>
#define MYGUI_EXCEPT(dest)
#define MYGUI_OBSOLETE(text)
bool compare(const Any &other) const
void invoke(Args... args)
DelegateFunction(Function _function, Any _functionPointer, const void *_object)
DelegateFunction(Function _function, Any _functionPointer)
DelegateFunction(Function _function, Any _functionPointer, const IDelegateUnlink *_object)
std::function< void(Args...)> Function
bool compare(DelegateFunction< Args... > *_delegate) const
bool compare(IDelegateUnlink *_unlink) const
void operator()(Args... args) const
DelegateFunction< Args... > IDelegate
Delegate(const Delegate &_event)
Delegate & operator=(const Delegate< Args... > &_event)
Delegate & operator=(IDelegate *_delegate)
virtual ~IDelegateUnlink()=default
bool compare(IDelegateUnlink *_unlink) const
MultiDelegate & operator=(const MultiDelegate &_event)
void operator-=(IDelegate *_delegate)
DelegateFunction< Args... > IDelegate
typename std::list< IDelegate * > ListDelegate
void operator+=(IDelegate *_delegate)
MultiDelegate(const MultiDelegate &_event)
void clear(IDelegateUnlink *_unlink)
void operator()(Args... args) const
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))