adds priority version of Void delegate/expire/strategy

This commit is contained in:
arturo
2013-01-23 10:11:04 +01:00
parent 1de98a00c2
commit 72100d56d8
4 changed files with 572 additions and 1 deletions

View File

@@ -135,7 +135,80 @@ protected:
Delegates _delegates;
};
template <class TDelegate>
class PriorityStrategy<void, TDelegate>
/// NotificationStrategy for PriorityEvent.
///
/// Delegates are kept in a std::vector<>, ordered
/// by their priority.
{
public:
typedef SharedPtr<TDelegate> DelegatePtr;
typedef std::vector<DelegatePtr> Delegates;
typedef typename Delegates::iterator Iterator;
public:
void notify(const void* sender)
{
for (Iterator it = _delegates.begin(); it != _delegates.end(); ++it)
{
(*it)->notify(sender);
}
}
void 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;
}
}
_delegates.push_back(DelegatePtr(static_cast<TDelegate*>(delegate.clone())));
}
void remove(const TDelegate& delegate)
{
for (Iterator it = _delegates.begin(); it != _delegates.end(); ++it)
{
if (delegate.equals(**it))
{
(*it)->disable();
_delegates.erase(it);
return;
}
}
}
PriorityStrategy& operator = (const PriorityStrategy& s)
{
if (this != &s)
{
_delegates = s._delegates;
}
return *this;
}
void clear()
{
for (Iterator it = _delegates.begin(); it != _delegates.end(); ++it)
{
(*it)->disable();
}
_delegates.clear();
}
bool empty() const
{
return _delegates.empty();
}
protected:
Delegates _delegates;
};
} // namespace Poco