mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-16 18:56:52 +02:00
Poco::BasicEvent improvements and preparations for future support of lambdas/std::function
This commit is contained in:
@@ -36,6 +36,7 @@ class PriorityStrategy: public NotificationStrategy<TArgs, TDelegate>
|
||||
/// by their priority.
|
||||
{
|
||||
public:
|
||||
typedef TDelegate* DelegateHandle;
|
||||
typedef SharedPtr<TDelegate> DelegatePtr;
|
||||
typedef std::vector<DelegatePtr> Delegates;
|
||||
typedef typename Delegates::iterator Iterator;
|
||||
@@ -62,17 +63,20 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void add(const TDelegate& delegate)
|
||||
DelegateHandle add(const TDelegate& delegate)
|
||||
{
|
||||
for (Iterator it = _delegates.begin(); it != _delegates.end(); ++it)
|
||||
{
|
||||
if ((*it)->priority() > delegate.priority())
|
||||
{
|
||||
_delegates.insert(it, DelegatePtr(static_cast<TDelegate*>(delegate.clone())));
|
||||
return;
|
||||
DelegatePtr pDelegate(static_cast<TDelegate*>(delegate.clone()));
|
||||
_delegates.insert(it, pDelegate);
|
||||
return pDelegate.get();
|
||||
}
|
||||
}
|
||||
_delegates.push_back(DelegatePtr(static_cast<TDelegate*>(delegate.clone())));
|
||||
DelegatePtr pDelegate(static_cast<TDelegate*>(delegate.clone()));
|
||||
_delegates.push_back(pDelegate);
|
||||
return pDelegate.get();
|
||||
}
|
||||
|
||||
void remove(const TDelegate& delegate)
|
||||
@@ -88,6 +92,19 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void remove(DelegateHandle delegateHandle)
|
||||
{
|
||||
for (Iterator it = _delegates.begin(); it != _delegates.end(); ++it)
|
||||
{
|
||||
if (*it == delegateHandle)
|
||||
{
|
||||
(*it)->disable();
|
||||
_delegates.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PriorityStrategy& operator = (const PriorityStrategy& s)
|
||||
{
|
||||
if (this != &s)
|
||||
@@ -115,6 +132,7 @@ protected:
|
||||
Delegates _delegates;
|
||||
};
|
||||
|
||||
|
||||
template <class TDelegate>
|
||||
class PriorityStrategy<void, TDelegate>
|
||||
/// NotificationStrategy for PriorityEvent.
|
||||
@@ -123,6 +141,7 @@ class PriorityStrategy<void, TDelegate>
|
||||
/// by their priority.
|
||||
{
|
||||
public:
|
||||
typedef TDelegate* DelegateHandle;
|
||||
typedef SharedPtr<TDelegate> DelegatePtr;
|
||||
typedef std::vector<DelegatePtr> Delegates;
|
||||
typedef typename Delegates::iterator Iterator;
|
||||
@@ -137,17 +156,20 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void add(const TDelegate& delegate)
|
||||
DelegateHandle add(const TDelegate& delegate)
|
||||
{
|
||||
for (Iterator it = _delegates.begin(); it != _delegates.end(); ++it)
|
||||
{
|
||||
if ((*it)->priority() > delegate.priority())
|
||||
{
|
||||
_delegates.insert(it, DelegatePtr(static_cast<TDelegate*>(delegate.clone())));
|
||||
return;
|
||||
DelegatePtr pDelegate(static_cast<TDelegate*>(delegate.clone()));
|
||||
_delegates.insert(it, pDelegate);
|
||||
return pDelegate.get();
|
||||
}
|
||||
}
|
||||
_delegates.push_back(DelegatePtr(static_cast<TDelegate*>(delegate.clone())));
|
||||
DelegatePtr pDelegate(static_cast<TDelegate*>(delegate.clone()));
|
||||
_delegates.push_back(pDelegate);
|
||||
return pDelegate.get();
|
||||
}
|
||||
|
||||
void remove(const TDelegate& delegate)
|
||||
@@ -163,6 +185,19 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void remove(DelegateHandle delegateHandle)
|
||||
{
|
||||
for (Iterator it = _delegates.begin(); it != _delegates.end(); ++it)
|
||||
{
|
||||
if (*it == delegateHandle)
|
||||
{
|
||||
(*it)->disable();
|
||||
_delegates.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PriorityStrategy& operator = (const PriorityStrategy& s)
|
||||
{
|
||||
if (this != &s)
|
||||
@@ -189,6 +224,8 @@ public:
|
||||
protected:
|
||||
Delegates _delegates;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user