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

@@ -37,6 +37,7 @@ class DefaultStrategy: public NotificationStrategy<TArgs, TDelegate>
/// order in which they have been registered.
{
public:
typedef TDelegate* DelegateHandle;
typedef SharedPtr<TDelegate> DelegatePtr;
typedef std::vector<DelegatePtr> Delegates;
typedef typename Delegates::iterator Iterator;
@@ -63,9 +64,11 @@ public:
}
}
void add(const TDelegate& delegate)
DelegateHandle add(const TDelegate& delegate)
{
_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)
@@ -80,6 +83,19 @@ public:
}
}
}
void remove(DelegateHandle delegateHandle)
{
for (Iterator it = _delegates.begin(); it != _delegates.end(); ++it)
{
if (*it == delegateHandle)
{
(*it)->disable();
_delegates.erase(it);
return;
}
}
}
DefaultStrategy& operator = (const DefaultStrategy& s)
{
@@ -108,6 +124,7 @@ protected:
Delegates _delegates;
};
template <class TDelegate>
class DefaultStrategy<void,TDelegate>: public NotificationStrategy<void, TDelegate>
/// Default notification strategy.
@@ -117,6 +134,7 @@ class DefaultStrategy<void,TDelegate>: public NotificationStrategy<void, TDelega
/// order in which they have been registered.
{
public:
typedef TDelegate* DelegateHandle;
typedef SharedPtr<TDelegate> DelegatePtr;
typedef std::vector<DelegatePtr> Delegates;
typedef typename Delegates::iterator Iterator;
@@ -143,9 +161,11 @@ public:
}
}
void add(const TDelegate& delegate)
DelegateHandle add(const TDelegate& delegate)
{
_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)
@@ -161,6 +181,19 @@ public:
}
}
void remove(DelegateHandle delegateHandle)
{
for (Iterator it = _delegates.begin(); it != _delegates.end(); ++it)
{
if (*it == delegateHandle)
{
(*it)->disable();
_delegates.erase(it);
return;
}
}
}
DefaultStrategy& operator = (const DefaultStrategy& s)
{
if (this != &s)
@@ -188,6 +221,7 @@ protected:
Delegates _delegates;
};
} // namespace Poco