| 1 | // |
| 2 | // NotificationStrategy.h |
| 3 | // |
| 4 | // Library: Foundation |
| 5 | // Package: Events |
| 6 | // Module: NotificationStrategy |
| 7 | // |
| 8 | // Definition of the NotificationStrategy interface. |
| 9 | // |
| 10 | // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH. |
| 11 | // and Contributors. |
| 12 | // |
| 13 | // SPDX-License-Identifier: BSL-1.0 |
| 14 | // |
| 15 | |
| 16 | |
| 17 | #ifndef Foundation_NotificationStrategy_INCLUDED |
| 18 | #define Foundation_NotificationStrategy_INCLUDED |
| 19 | |
| 20 | |
| 21 | #include "Poco/Foundation.h" |
| 22 | |
| 23 | |
| 24 | namespace Poco { |
| 25 | |
| 26 | |
| 27 | template <class TArgs, class TDelegate> |
| 28 | class NotificationStrategy |
| 29 | /// The interface that all notification strategies must implement. |
| 30 | /// |
| 31 | /// Note: Event is based on policy-driven design, so every strategy implementation |
| 32 | /// must provide all the methods from this interface (otherwise: compile errors) |
| 33 | /// but does not need to inherit from NotificationStrategy. |
| 34 | { |
| 35 | public: |
| 36 | typedef TDelegate* DelegateHandle; |
| 37 | |
| 38 | NotificationStrategy() |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | virtual ~NotificationStrategy() |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | virtual void notify(const void* sender, TArgs& arguments) = 0; |
| 47 | /// Sends a notification to all registered delegates. |
| 48 | |
| 49 | virtual DelegateHandle add(const TDelegate& delegate) = 0; |
| 50 | /// Adds a delegate to the strategy. |
| 51 | |
| 52 | virtual void remove(const TDelegate& delegate) = 0; |
| 53 | /// Removes a delegate from the strategy, if found. |
| 54 | /// Does nothing if the delegate has not been added. |
| 55 | |
| 56 | virtual void remove(DelegateHandle delegateHandle) = 0; |
| 57 | /// Removes a delegate from the strategy, if found. |
| 58 | /// Does nothing if the delegate has not been added. |
| 59 | |
| 60 | virtual void clear() = 0; |
| 61 | /// Removes all delegates from the strategy. |
| 62 | |
| 63 | virtual bool empty() const = 0; |
| 64 | /// Returns false if the strategy contains at least one delegate. |
| 65 | }; |
| 66 | |
| 67 | |
| 68 | template <class TDelegate> |
| 69 | class NotificationStrategy<void, TDelegate> |
| 70 | /// The interface that all notification strategies must implement. |
| 71 | /// |
| 72 | /// Note: Event is based on policy-driven design, so every strategy implementation |
| 73 | /// must provide all the methods from this interface (otherwise: compile errors) |
| 74 | /// but does not need to inherit from NotificationStrategy. |
| 75 | { |
| 76 | public: |
| 77 | typedef TDelegate* DelegateHandle; |
| 78 | |
| 79 | NotificationStrategy() |
| 80 | { |
| 81 | } |
| 82 | |
| 83 | virtual ~NotificationStrategy() |
| 84 | { |
| 85 | } |
| 86 | |
| 87 | virtual void notify(const void* sender) = 0; |
| 88 | /// Sends a notification to all registered delegates. |
| 89 | |
| 90 | virtual DelegateHandle add(const TDelegate& delegate) = 0; |
| 91 | /// Adds a delegate to the strategy. |
| 92 | |
| 93 | virtual void remove(const TDelegate& delegate) = 0; |
| 94 | /// Removes a delegate from the strategy, if found. |
| 95 | /// Does nothing if the delegate has not been added. |
| 96 | |
| 97 | virtual void remove(DelegateHandle delegateHandle) = 0; |
| 98 | /// Removes a delegate from the strategy, if found. |
| 99 | /// Does nothing if the delegate has not been added. |
| 100 | |
| 101 | virtual void clear() = 0; |
| 102 | /// Removes all delegates from the strategy. |
| 103 | |
| 104 | virtual bool empty() const = 0; |
| 105 | /// Returns false if the strategy contains at least one delegate. |
| 106 | }; |
| 107 | |
| 108 | |
| 109 | } // namespace Poco |
| 110 | |
| 111 | |
| 112 | #endif // Foundation_NotificationStrategy_INCLUDED |
| 113 | |