| 1 | // |
| 2 | // AbstractDelegate.h |
| 3 | // |
| 4 | // Library: Foundation |
| 5 | // Package: Events |
| 6 | // Module: AbstractDelegate |
| 7 | // |
| 8 | // Implementation of the AbstractDelegate template. |
| 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_AbstractDelegate_INCLUDED |
| 18 | #define Foundation_AbstractDelegate_INCLUDED |
| 19 | |
| 20 | |
| 21 | #include "Poco/Foundation.h" |
| 22 | |
| 23 | |
| 24 | namespace Poco { |
| 25 | |
| 26 | |
| 27 | template <class TArgs> |
| 28 | class AbstractDelegate |
| 29 | /// Base class for Delegate and Expire. |
| 30 | { |
| 31 | public: |
| 32 | AbstractDelegate() |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | AbstractDelegate(const AbstractDelegate& /*del*/) |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | virtual ~AbstractDelegate() |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | virtual bool notify(const void* sender, TArgs& arguments) = 0; |
| 45 | /// Invokes the delegate's callback function. |
| 46 | /// Returns true if successful, or false if the delegate |
| 47 | /// has been disabled or has expired. |
| 48 | |
| 49 | virtual bool equals(const AbstractDelegate& other) const = 0; |
| 50 | /// Compares the AbstractDelegate with the other one for equality. |
| 51 | |
| 52 | virtual AbstractDelegate* clone() const = 0; |
| 53 | /// Returns a deep copy of the AbstractDelegate. |
| 54 | |
| 55 | virtual void disable() = 0; |
| 56 | /// Disables the delegate, which is done prior to removal. |
| 57 | |
| 58 | virtual const AbstractDelegate* unwrap() const |
| 59 | /// Returns the unwrapped delegate. Must be overridden by decorators |
| 60 | /// like Expire. |
| 61 | { |
| 62 | return this; |
| 63 | } |
| 64 | }; |
| 65 | |
| 66 | |
| 67 | template <> |
| 68 | class AbstractDelegate<void> |
| 69 | /// Base class for Delegate and Expire. |
| 70 | { |
| 71 | public: |
| 72 | AbstractDelegate() |
| 73 | { |
| 74 | } |
| 75 | |
| 76 | AbstractDelegate(const AbstractDelegate&) |
| 77 | { |
| 78 | } |
| 79 | |
| 80 | virtual ~AbstractDelegate() |
| 81 | { |
| 82 | } |
| 83 | |
| 84 | virtual bool notify(const void* sender) = 0; |
| 85 | /// Invokes the delegate's callback function. |
| 86 | /// Returns true if successful, or false if the delegate |
| 87 | /// has been disabled or has expired. |
| 88 | |
| 89 | virtual bool equals(const AbstractDelegate& other) const = 0; |
| 90 | /// Compares the AbstractDelegate with the other one for equality. |
| 91 | |
| 92 | virtual AbstractDelegate* clone() const = 0; |
| 93 | /// Returns a deep copy of the AbstractDelegate. |
| 94 | |
| 95 | virtual void disable() = 0; |
| 96 | /// Disables the delegate, which is done prior to removal. |
| 97 | |
| 98 | virtual const AbstractDelegate* unwrap() const |
| 99 | /// Returns the unwrapped delegate. Must be overridden by decorators |
| 100 | /// like Expire. |
| 101 | { |
| 102 | return this; |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | |
| 107 | } // namespace Poco |
| 108 | |
| 109 | |
| 110 | #endif // Foundation_AbstractDelegate_INCLUDED |
| 111 | |