diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /contrib/libs/poco/XML/src/EventDispatcher.cpp | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'contrib/libs/poco/XML/src/EventDispatcher.cpp')
-rw-r--r-- | contrib/libs/poco/XML/src/EventDispatcher.cpp | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/contrib/libs/poco/XML/src/EventDispatcher.cpp b/contrib/libs/poco/XML/src/EventDispatcher.cpp new file mode 100644 index 0000000000..4656f9b45f --- /dev/null +++ b/contrib/libs/poco/XML/src/EventDispatcher.cpp @@ -0,0 +1,146 @@ +// +// EventDispatcher.cpp +// +// Library: XML +// Package: DOM +// Module: DOMEvents +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// SPDX-License-Identifier: BSL-1.0 +// + + +#include "Poco/DOM/EventDispatcher.h" +#include "Poco/DOM/Event.h" +#include "Poco/DOM/EventListener.h" + + +namespace +{ + class DispatchGuard + { + public: + DispatchGuard(int& count): + _count(count) + { + ++_count; + } + + ~DispatchGuard() + { + --_count; + } + + private: + int& _count; + }; +} + + +namespace Poco { +namespace XML { + + +EventDispatcher::EventDispatcher(): + _inDispatch(0) +{ +} + + +EventDispatcher::~EventDispatcher() +{ +} + + +void EventDispatcher::addEventListener(const XMLString& type, EventListener* listener, bool useCapture) +{ + EventListenerItem item; + item.type = type; + item.pListener = listener; + item.useCapture = useCapture; + _listeners.push_front(item); +} + + +void EventDispatcher::removeEventListener(const XMLString& type, EventListener* listener, bool useCapture) +{ + EventListenerList::iterator it = _listeners.begin(); + while (it != _listeners.end()) + { + if (it->type == type && it->pListener == listener && it->useCapture == useCapture) + { + it->pListener = 0; + } + if (!_inDispatch && !it->pListener) + { + EventListenerList::iterator del = it++; + _listeners.erase(del); + } + else ++it; + } +} + + +void EventDispatcher::dispatchEvent(Event* evt) +{ + DispatchGuard guard(_inDispatch); + EventListenerList::iterator it = _listeners.begin(); + while (it != _listeners.end()) + { + if (it->pListener && it->type == evt->type()) + { + it->pListener->handleEvent(evt); + } + if (!it->pListener) + { + EventListenerList::iterator del = it++; + _listeners.erase(del); + } + else ++it; + } +} + + +void EventDispatcher::captureEvent(Event* evt) +{ + DispatchGuard guard(_inDispatch); + EventListenerList::iterator it = _listeners.begin(); + while (it != _listeners.end()) + { + if (it->pListener && it->useCapture && it->type == evt->type()) + { + it->pListener->handleEvent(evt); + } + if (!it->pListener) + { + EventListenerList::iterator del = it++; + _listeners.erase(del); + } + else ++it; + } +} + + +void EventDispatcher::bubbleEvent(Event* evt) +{ + DispatchGuard guard(_inDispatch); + EventListenerList::iterator it = _listeners.begin(); + while (it != _listeners.end()) + { + if (it->pListener && !it->useCapture && it->type == evt->type()) + { + it->pListener->handleEvent(evt); + } + if (!it->pListener) + { + EventListenerList::iterator del = it++; + _listeners.erase(del); + } + else ++it; + } +} + + +} } // namespace Poco::XML |