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

@@ -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