Poco::BasicEvent improvements and preparations for future support of lambdas/std::function

This commit is contained in:
Guenter Obiltschnig
2014-11-24 11:17:27 +01:00
parent 77bbc7e9ba
commit d5d048e689
12 changed files with 351 additions and 343 deletions

View File

@@ -34,17 +34,17 @@ class FunctionPriorityDelegate: public AbstractPriorityDelegate<TArgs>
/// for use as a PriorityDelegate.
{
public:
typedef void (*NotifyMethod)(const void*, TArgs&);
typedef void (*NotifyFunction)(const void*, TArgs&);
FunctionPriorityDelegate(NotifyMethod method, int prio):
FunctionPriorityDelegate(NotifyFunction function, int prio):
AbstractPriorityDelegate<TArgs>(prio),
_receiverMethod(method)
_function(function)
{
}
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
AbstractPriorityDelegate<TArgs>(delegate),
_receiverMethod(delegate._receiverMethod)
_function(delegate._function)
{
}
@@ -52,9 +52,8 @@ public:
{
if (&delegate != this)
{
this->_pTarget = delegate._pTarget;
this->_receiverMethod = delegate._receiverMethod;
this->_priority = delegate._priority;
this->_function = delegate._function;
this->_priority = delegate._priority;
}
return *this;
}
@@ -66,9 +65,9 @@ public:
bool notify(const void* sender, TArgs& arguments)
{
Mutex::ScopedLock lock(_mutex);
if (_receiverMethod)
if (_function)
{
(*_receiverMethod)(sender, arguments);
(*_function)(sender, arguments);
return true;
}
else return false;
@@ -77,7 +76,7 @@ public:
bool equals(const AbstractDelegate<TArgs>& other) const
{
const FunctionPriorityDelegate* pOtherDelegate = dynamic_cast<const FunctionPriorityDelegate*>(other.unwrap());
return pOtherDelegate && this->priority() == pOtherDelegate->priority() && _receiverMethod == pOtherDelegate->_receiverMethod;
return pOtherDelegate && this->priority() == pOtherDelegate->priority() && _function == pOtherDelegate->_function;
}
AbstractDelegate<TArgs>* clone() const
@@ -88,11 +87,11 @@ public:
void disable()
{
Mutex::ScopedLock lock(_mutex);
_receiverMethod = 0;
_function = 0;
}
protected:
NotifyMethod _receiverMethod;
NotifyFunction _function;
Mutex _mutex;
private:
@@ -104,17 +103,17 @@ template <class TArgs>
class FunctionPriorityDelegate<TArgs, true, false>: public AbstractPriorityDelegate<TArgs>
{
public:
typedef void (*NotifyMethod)(void*, TArgs&);
typedef void (*NotifyFunction)(void*, TArgs&);
FunctionPriorityDelegate(NotifyMethod method, int prio):
FunctionPriorityDelegate(NotifyFunction function, int prio):
AbstractPriorityDelegate<TArgs>(prio),
_receiverMethod(method)
_function(function)
{
}
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
AbstractPriorityDelegate<TArgs>(delegate),
_receiverMethod(delegate._receiverMethod)
_function(delegate._function)
{
}
@@ -122,9 +121,8 @@ public:
{
if (&delegate != this)
{
this->_pTarget = delegate._pTarget;
this->_receiverMethod = delegate._receiverMethod;
this->_priority = delegate._priority;
this->_function = delegate._function;
this->_priority = delegate._priority;
}
return *this;
}
@@ -136,9 +134,9 @@ public:
bool notify(const void* sender, TArgs& arguments)
{
Mutex::ScopedLock lock(_mutex);
if (_receiverMethod)
if (_function)
{
(*_receiverMethod)(const_cast<void*>(sender), arguments);
(*_function)(const_cast<void*>(sender), arguments);
return true;
}
else return false;
@@ -147,7 +145,7 @@ public:
bool equals(const AbstractDelegate<TArgs>& other) const
{
const FunctionPriorityDelegate* pOtherDelegate = dynamic_cast<const FunctionPriorityDelegate*>(other.unwrap());
return pOtherDelegate && this->priority() == pOtherDelegate->priority() && _receiverMethod == pOtherDelegate->_receiverMethod;
return pOtherDelegate && this->priority() == pOtherDelegate->priority() && _function == pOtherDelegate->_function;
}
AbstractDelegate<TArgs>* clone() const
@@ -158,11 +156,11 @@ public:
void disable()
{
Mutex::ScopedLock lock(_mutex);
_receiverMethod = 0;
_function = 0;
}
protected:
NotifyMethod _receiverMethod;
NotifyFunction _function;
Mutex _mutex;
private:
@@ -174,17 +172,17 @@ template <class TArgs>
class FunctionPriorityDelegate<TArgs, false>: public AbstractPriorityDelegate<TArgs>
{
public:
typedef void (*NotifyMethod)(TArgs&);
typedef void (*NotifyFunction)(TArgs&);
FunctionPriorityDelegate(NotifyMethod method, int prio):
FunctionPriorityDelegate(NotifyFunction function, int prio):
AbstractPriorityDelegate<TArgs>(prio),
_receiverMethod(method)
_function(function)
{
}
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
AbstractPriorityDelegate<TArgs>(delegate),
_receiverMethod(delegate._receiverMethod)
_function(delegate._function)
{
}
@@ -192,9 +190,8 @@ public:
{
if (&delegate != this)
{
this->_pTarget = delegate._pTarget;
this->_receiverMethod = delegate._receiverMethod;
this->_priority = delegate._priority;
this->_function = delegate._function;
this->_priority = delegate._priority;
}
return *this;
}
@@ -206,9 +203,9 @@ public:
bool notify(const void* sender, TArgs& arguments)
{
Mutex::ScopedLock lock(_mutex);
if (_receiverMethod)
if (_function)
{
(*_receiverMethod)(arguments);
(*_function)(arguments);
return true;
}
else return false;
@@ -217,7 +214,7 @@ public:
bool equals(const AbstractDelegate<TArgs>& other) const
{
const FunctionPriorityDelegate* pOtherDelegate = dynamic_cast<const FunctionPriorityDelegate*>(other.unwrap());
return pOtherDelegate && this->priority() == pOtherDelegate->priority() && _receiverMethod == pOtherDelegate->_receiverMethod;
return pOtherDelegate && this->priority() == pOtherDelegate->priority() && _function == pOtherDelegate->_function;
}
AbstractDelegate<TArgs>* clone() const
@@ -228,11 +225,11 @@ public:
void disable()
{
Mutex::ScopedLock lock(_mutex);
_receiverMethod = 0;
_function = 0;
}
protected:
NotifyMethod _receiverMethod;
NotifyFunction _function;
Mutex _mutex;
private:
@@ -241,22 +238,22 @@ private:
template <>
class FunctionPriorityDelegate<void,true,true>: public AbstractPriorityDelegate<void>
class FunctionPriorityDelegate<void, true, true>: public AbstractPriorityDelegate<void>
/// Wraps a freestanding function or static member function
/// for use as a PriorityDelegate.
{
public:
typedef void (*NotifyMethod)(const void*);
typedef void (*NotifyFunction)(const void*);
FunctionPriorityDelegate(NotifyMethod method, int prio):
FunctionPriorityDelegate(NotifyFunction function, int prio):
AbstractPriorityDelegate<void>(prio),
_receiverMethod(method)
_function(function)
{
}
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
AbstractPriorityDelegate<void>(delegate),
_receiverMethod(delegate._receiverMethod)
_function(delegate._function)
{
}
@@ -264,8 +261,8 @@ public:
{
if (&delegate != this)
{
this->_receiverMethod = delegate._receiverMethod;
this->_priority = delegate._priority;
this->_function = delegate._function;
this->_priority = delegate._priority;
}
return *this;
}
@@ -277,9 +274,9 @@ public:
bool notify(const void* sender)
{
Mutex::ScopedLock lock(_mutex);
if (_receiverMethod)
if (_function)
{
(*_receiverMethod)(sender);
(*_function)(sender);
return true;
}
else return false;
@@ -288,7 +285,7 @@ public:
bool equals(const AbstractDelegate<void>& other) const
{
const FunctionPriorityDelegate* pOtherDelegate = dynamic_cast<const FunctionPriorityDelegate*>(other.unwrap());
return pOtherDelegate && this->priority() == pOtherDelegate->priority() && _receiverMethod == pOtherDelegate->_receiverMethod;
return pOtherDelegate && this->priority() == pOtherDelegate->priority() && _function == pOtherDelegate->_function;
}
AbstractDelegate<void>* clone() const
@@ -299,11 +296,11 @@ public:
void disable()
{
Mutex::ScopedLock lock(_mutex);
_receiverMethod = 0;
_function = 0;
}
protected:
NotifyMethod _receiverMethod;
NotifyFunction _function;
Mutex _mutex;
private:
@@ -315,17 +312,17 @@ template <>
class FunctionPriorityDelegate<void, true, false>: public AbstractPriorityDelegate<void>
{
public:
typedef void (*NotifyMethod)(void*);
typedef void (*NotifyFunction)(void*);
FunctionPriorityDelegate(NotifyMethod method, int prio):
FunctionPriorityDelegate(NotifyFunction function, int prio):
AbstractPriorityDelegate<void>(prio),
_receiverMethod(method)
_function(function)
{
}
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
AbstractPriorityDelegate<void>(delegate),
_receiverMethod(delegate._receiverMethod)
_function(delegate._function)
{
}
@@ -333,8 +330,8 @@ public:
{
if (&delegate != this)
{
this->_receiverMethod = delegate._receiverMethod;
this->_priority = delegate._priority;
this->_function = delegate._function;
this->_priority = delegate._priority;
}
return *this;
}
@@ -346,9 +343,9 @@ public:
bool notify(const void* sender)
{
Mutex::ScopedLock lock(_mutex);
if (_receiverMethod)
if (_function)
{
(*_receiverMethod)(const_cast<void*>(sender));
(*_function)(const_cast<void*>(sender));
return true;
}
else return false;
@@ -357,7 +354,7 @@ public:
bool equals(const AbstractDelegate<void>& other) const
{
const FunctionPriorityDelegate* pOtherDelegate = dynamic_cast<const FunctionPriorityDelegate*>(other.unwrap());
return pOtherDelegate && this->priority() == pOtherDelegate->priority() && _receiverMethod == pOtherDelegate->_receiverMethod;
return pOtherDelegate && this->priority() == pOtherDelegate->priority() && _function == pOtherDelegate->_function;
}
AbstractDelegate<void>* clone() const
@@ -368,11 +365,11 @@ public:
void disable()
{
Mutex::ScopedLock lock(_mutex);
_receiverMethod = 0;
_function = 0;
}
protected:
NotifyMethod _receiverMethod;
NotifyFunction _function;
Mutex _mutex;
private:
@@ -384,17 +381,17 @@ template <>
class FunctionPriorityDelegate<void, false>: public AbstractPriorityDelegate<void>
{
public:
typedef void (*NotifyMethod)();
typedef void (*NotifyFunction)();
FunctionPriorityDelegate(NotifyMethod method, int prio):
FunctionPriorityDelegate(NotifyFunction function, int prio):
AbstractPriorityDelegate<void>(prio),
_receiverMethod(method)
_function(function)
{
}
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
AbstractPriorityDelegate<void>(delegate),
_receiverMethod(delegate._receiverMethod)
_function(delegate._function)
{
}
@@ -402,8 +399,8 @@ public:
{
if (&delegate != this)
{
this->_receiverMethod = delegate._receiverMethod;
this->_priority = delegate._priority;
this->_function = delegate._function;
this->_priority = delegate._priority;
}
return *this;
}
@@ -415,9 +412,9 @@ public:
bool notify(const void* sender)
{
Mutex::ScopedLock lock(_mutex);
if (_receiverMethod)
if (_function)
{
(*_receiverMethod)();
(*_function)();
return true;
}
else return false;
@@ -426,7 +423,7 @@ public:
bool equals(const AbstractDelegate<void>& other) const
{
const FunctionPriorityDelegate* pOtherDelegate = dynamic_cast<const FunctionPriorityDelegate*>(other.unwrap());
return pOtherDelegate && this->priority() == pOtherDelegate->priority() && _receiverMethod == pOtherDelegate->_receiverMethod;
return pOtherDelegate && this->priority() == pOtherDelegate->priority() && _function == pOtherDelegate->_function;
}
AbstractDelegate<void>* clone() const
@@ -437,17 +434,18 @@ public:
void disable()
{
Mutex::ScopedLock lock(_mutex);
_receiverMethod = 0;
_function = 0;
}
protected:
NotifyMethod _receiverMethod;
NotifyFunction _function;
Mutex _mutex;
private:
FunctionPriorityDelegate();
};
} // namespace Poco