Medical Imaging Interaction Toolkit
2023.12.00
Medical Imaging Interaction Toolkit
|
Go to the documentation of this file.
13 #ifndef BERRYMESSAGE_H_
14 #define BERRYMESSAGE_H_
17 #include <Poco/Mutex.h>
23 #define berryNewMessageMacro(msgHandleObject) \
24 private: Message<> m_ ## msgHandleObject ## Message; \
26 inline void Add ## msgHandleObject ## Listener(const MessageAbstractDelegate<>& delegate) \
27 { m_ ## msgHandleObject ## Message += delegate; } \
28 inline void Remove ## msgHandleObject ## Listener(const MessageAbstractDelegate<>& delegate) \
29 { m_ ## msgHandleObject ## Message -= delegate; } \
32 #define berryNewMessageWithReturnMacro(msgHandleObject, returnType) \
33 private: Message<returnType> m_ ## msgHandleObject ## Message; \
35 inline void Add ## msgHandleObject ## Listener(const MessageAbstractDelegate<returnType>& delegate) \
36 { m_ ## msgHandleObject ## Message += delegate; } \
37 inline void Remove ## msgHandleObject ## Listener(const MessageAbstractDelegate<returnType>& delegate) \
38 { m_ ## msgHandleObject ## Message -= delegate; } \
41 #define berryNewMessage1Macro(msgHandleObject, type1) \
42 private: Message1< type1 > m_msgHandleObject ## Message; \
44 void Add ## msgHandleObject ## Listener(const MessageAbstractDelegate1< type1 >& delegate) \
45 { m_ ## msgHandleObject ## Message += delegate; } \
46 void Remove ## msgHandleObject ## Listener(const MessageAbstractDelegate1< type1 >& delegate) \
47 { m_ ## msgHandleObject ## Message -= delegate; } \
53 template<
typename A =
void>
67 template<
typename T,
typename A =
void>
81 template<
typename T,
typename U,
typename A =
void>
90 virtual A
Execute(T t, U u)
const = 0;
95 template<
typename T,
typename U,
typename V,
typename A =
void>
104 virtual A
Execute(T t, U u, V v)
const = 0;
109 template<
typename T,
typename U,
typename V,
typename W,
typename A =
void>
118 virtual A
Execute(T t, U u, V v, W w)
const = 0;
123 template<
class R,
typename A =
void>
131 m_Object(object), m_MemberFunctionPointer(memberFunctionPointer)
142 return (m_Object->*m_MemberFunctionPointer)();
152 if ((
void*) this->m_Object != (
void*) cmd->m_Object)
154 if (this->m_MemberFunctionPointer != cmd->m_MemberFunctionPointer)
166 A (R::*m_MemberFunctionPointer)();
169 template<
class R,
typename T,
typename A =
void>
177 m_Object(object), m_MemberFunctionPointer(memberFunctionPointer)
188 return (m_Object->*m_MemberFunctionPointer)(t);
198 if ((
void*) this->m_Object != (
void*) cmd->m_Object)
200 if (this->m_MemberFunctionPointer != cmd->m_MemberFunctionPointer)
212 A (R::*m_MemberFunctionPointer)(T);
215 template<
class R,
typename T,
typename U,
typename A =
void>
223 m_Object(object), m_MemberFunctionPointer(memberFunctionPointer)
234 return (m_Object->*m_MemberFunctionPointer)(t, u);
244 if ((
void*) this->m_Object != (
void*) cmd->m_Object)
246 if (this->m_MemberFunctionPointer != cmd->m_MemberFunctionPointer)
258 A (R::*m_MemberFunctionPointer)(T, U);
261 template<
class R,
typename T,
typename U,
typename V,
typename A =
void>
269 m_Object(object), m_MemberFunctionPointer(memberFunctionPointer)
280 return (m_Object->*m_MemberFunctionPointer)(t, u, v);
290 if ((
void*) this->m_Object != (
void*) cmd->m_Object)
292 if (this->m_MemberFunctionPointer != cmd->m_MemberFunctionPointer)
304 A (R::*m_MemberFunctionPointer)(T, U, V);
307 template<
class R,
typename T,
typename U,
typename V,
typename W,
316 m_Object(object), m_MemberFunctionPointer(memberFunctionPointer)
327 return (m_Object->*m_MemberFunctionPointer)(t, u, v, w);
337 if ((
void*) this->m_Object != (
void*) cmd->m_Object)
339 if (this->m_MemberFunctionPointer != cmd->m_MemberFunctionPointer)
351 A (R::*m_MemberFunctionPointer)(T, U, V, W);
370 m_Object(r), m_ExceptionCallback(c)
376 (m_Object->*m_ExceptionCallback)(exc);
381 if (!m_Object)
return nullptr;
401 m_ExcHandler(nullptr)
408 for (
auto iter = m_Delegates.begin(); iter
409 != m_Delegates.end(); ++iter)
421 Poco::FastMutex::ScopedLock lock(m_Mutex);
422 for (
auto iter = m_Delegates.begin(); iter
423 != m_Delegates.end(); ++iter)
425 if ((*iter)->operator==(copy))
431 m_Delegates.push_back(copy);
436 Poco::FastMutex::ScopedLock lock(m_Mutex);
437 for (
auto iter = m_Delegates.begin(); iter
438 != m_Delegates.end(); ++iter)
440 if ((*iter)->operator==(&d))
443 m_Delegates.erase(iter);
451 return m_Delegates.empty();
454 template<
typename Dummy>
460 Poco::FastMutex::ScopedLock lock(m_Mutex);
461 delegates.assign(m_Delegates.begin(), m_Delegates.end());
464 for (
auto iter = delegates.begin(); iter
465 != delegates.end(); ++iter)
472 catch (
const std::exception& e)
501 Poco::FastMutex::ScopedLock lock(m_Mutex);
502 delegates.assign(m_Delegates.begin(), m_Delegates.end());
505 for (
auto iter = delegates.begin(); iter
506 != delegates.end(); ++iter)
513 catch (
const std::exception& e)
535 template<
typename T,
typename U>
541 Poco::FastMutex::ScopedLock lock(m_Mutex);
542 delegates.assign(m_Delegates.begin(), m_Delegates.end());
545 for (
auto iter = delegates.begin(); iter
546 != delegates.end(); ++iter)
551 (*iter)->Execute(t, u);
553 catch (
const std::exception& e)
575 template<
typename T,
typename U,
typename V>
581 Poco::FastMutex::ScopedLock lock(m_Mutex);
582 delegates.assign(m_Delegates.begin(), m_Delegates.end());
585 for (
auto iter = delegates.begin(); iter
586 != delegates.end(); ++iter)
591 (*iter)->Execute(t, u, v);
593 catch (
const std::exception& e)
615 template<
typename T,
typename U,
typename V,
typename W>
616 void Send4(T t, U u, V v, W w)
const
621 Poco::FastMutex::ScopedLock lock(m_Mutex);
622 delegates.assign(m_Delegates.begin(), m_Delegates.end());
625 for (
auto iter = delegates.begin(); iter
626 != delegates.end(); ++iter)
631 (*iter)->Execute(t, u, v, w);
633 catch (
const std::exception& e)
657 Poco::FastMutex::ScopedLock lock(m_Mutex);
659 m_ExcHandler = handler.
Clone();
664 Poco::FastMutex::ScopedLock lock(m_Mutex);
665 if (m_ExcHandler)
return m_ExcHandler->
Clone();
671 Poco::FastMutex::ScopedLock lock(m_Mutex);
694 mutable std::vector<Delegate*> m_Delegates;
697 mutable Poco::FastMutex m_Mutex;
715 template<
typename A =
void>
786 template<
typename T,
typename A =
void>
857 template<
typename T,
typename U,
typename A =
void>
928 template<
typename T,
typename U,
typename V,
typename A =
void>
999 template<
typename T,
typename U,
typename V,
typename W,
typename A =
void>
1028 void Send(T t, U u, V v, W w)
const
1035 this->
Send(t, u , v, w);
void Remove(const Delegate &d) const
MessageDelegate3(R *object, A(R::*memberFunctionPointer)(T, U, V))
ListenerList GetListeners() const
DelegateList< AbstractDelegate >::ListType ListenerList
MessageAbstractDelegate1< T, A > * Clone() const override
AbstractExceptionHandler * GetExceptionHandler() const
ListenerList GetListeners() const
void SetExceptionHandler(const AbstractExceptionHandler &handler)
void(R::* HandleExceptionCallback)(const std::exception &)
std::vector< Delegate * > ListType
void SetExceptionHandler(const AbstractExceptionHandler &handler)
AbstractExceptionHandler * GetExceptionHandler() const
MessageDelegate4(R *object, A(R::*memberFunctionPointer)(T, U, V, W))
virtual bool operator==(const MessageAbstractDelegate2 *cmd)=0
void operator+=(const AbstractDelegate &delegate) const
virtual ~MessageAbstractDelegate1()
MessageAbstractDelegate< A > AbstractDelegate
virtual bool operator==(const MessageAbstractDelegate *cmd)=0
virtual ~AbstractExceptionHandler()
MessageAbstractDelegate4< T, U, V, W, A > * Clone() const override
MessageExceptionHandler(R *r, HandleExceptionCallback c)
void operator-=(const AbstractDelegate &delegate) const
void operator()(T t, U u, V v, W w) const
MessageAbstractDelegate3< T, U, V, A > AbstractDelegate
bool operator==(const MessageAbstractDelegate3< T, U, V, A > *c) override
AbstractExceptionHandler * GetExceptionHandler() const
void operator+=(const AbstractDelegate &delegate) const
AbstractExceptionHandler * GetExceptionHandler() const
DelegateList< AbstractDelegate > delegates
void RemoveListener(const AbstractDelegate &delegate) const
virtual ~MessageAbstractDelegate4()
A Execute(T t, U u, V v, W w) const override
bool operator==(const MessageAbstractDelegate< A > *c) override
DelegateList< AbstractDelegate > delegates
void AddListener(const AbstractDelegate &delegate) const
DelegateList< AbstractDelegate > delegates
virtual ~MessageAbstractDelegate3()
void operator()(T t, U u, V v) const
Event/message/notification class.
bool operator==(const MessageAbstractDelegate4< T, U, V, W, A > *c) override
void SetExceptionHandler(const AbstractExceptionHandler &handler)
MessageDelegate1(R *object, A(R::*memberFunctionPointer)(T))
void RemoveListener(const AbstractDelegate &delegate) const
void operator-=(const AbstractDelegate &delegate) const
void operator-=(const AbstractDelegate &delegate) const
void Send(T t, U u, V v, W w) const
DelegateList< AbstractDelegate >::ListType ListenerList
virtual A Execute(T t, U u, V v) const =0
bool HasListeners() const
~MessageDelegate3() override
void SetExceptionHandler(const AbstractExceptionHandler &handler)
virtual bool operator==(const MessageAbstractDelegate4 *cmd)=0
AbstractExceptionHandler * Clone() const override
void SetExceptionHandler(const AbstractExceptionHandler &handler)
void SetExceptionHandler(const AbstractExceptionHandler &handler)
bool operator==(const MessageAbstractDelegate1< T, A > *c) override
MessageAbstractDelegate2< T, U, A > AbstractDelegate
MessageAbstractDelegate3< T, U, V, A > * Clone() const override
void operator-=(const AbstractDelegate &delegate) const
virtual MessageAbstractDelegate2 * Clone() const =0
virtual MessageAbstractDelegate1 * Clone() const =0
bool HasListeners() const
ListenerList GetListeners() const
void operator+=(const AbstractDelegate &delegate) const
AbstractExceptionHandler * GetExceptionHandler() const
AbstractExceptionHandler * GetExceptionHandler() const
MessageAbstractDelegate4< T, U, V, W, A > AbstractDelegate
MessageAbstractDelegate< A > * Clone() const override
void operator()(T t, U u) const
void operator+=(const AbstractDelegate &delegate) const
void Add(const Delegate &d) const
DelegateList< AbstractDelegate > delegates
bool operator==(const MessageAbstractDelegate2< T, U, A > *c) override
virtual MessageAbstractDelegate3 * Clone() const =0
ListenerList GetListeners() const
void Send4(T t, U u, V v, W w) const
virtual bool operator==(const MessageAbstractDelegate3 *cmd)=0
virtual bool operator==(const MessageAbstractDelegate1 *cmd)=0
virtual void HandleException(const std::exception &exc)=0
A Execute(T t, U u) const override
void Send(T t, U u) const
bool HasListeners() const
~MessageDelegate() override
MessageDelegate2(R *object, A(R::*memberFunctionPointer)(T, U))
MessageAbstractDelegate1< T, A > AbstractDelegate
ListenerList GetListeners() const
DelegateList< AbstractDelegate > delegates
void AddListener(const AbstractDelegate &delegate) const
MessageDelegate(R *object, A(R::*memberFunctionPointer)())
void RemoveListener(const AbstractDelegate &delegate) const
ListType GetDelegates() const
virtual ~MessageAbstractDelegate()
~MessageDelegate4() override
void operator+=(const AbstractDelegate &delegate) const
void Send2(T t, U u) const
void Send3(T t, U u, V v) const
virtual MessageAbstractDelegate4 * Clone() const =0
A Execute(T t, U u, V v) const override
void operator()(T t) const
virtual MessageAbstractDelegate * Clone() const =0
void operator-=(const AbstractDelegate &delegate) const
void Send(T t, U u, V v) const
DelegateList< AbstractDelegate >::ListType ListenerList
bool HasListeners() const
void RemoveListener(const AbstractDelegate &delegate) const
~MessageDelegate2() override
void HandleException(const std::exception &exc) override
DelegateList< AbstractDelegate >::ListType ListenerList
void AddListener(const AbstractDelegate &delegate) const
virtual ~MessageAbstractDelegate2()
void AddListener(const AbstractDelegate &delegate) const
void RemoveListener(const AbstractDelegate &delegate) const
virtual AbstractExceptionHandler * Clone() const =0
MessageAbstractDelegate2< T, U, A > * Clone() const override
void AddListener(const AbstractDelegate &delegate) const
bool HasListeners() const
DelegateList< AbstractDelegate >::ListType ListenerList
virtual A Execute(T t, U u, V v, W w) const =0
~MessageDelegate1() override
virtual A Execute(T t, U u) const =0