NotificationStrategy.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #ifndef Foundation_NotificationStrategy_INCLUDED
  16. #define Foundation_NotificationStrategy_INCLUDED
  17. #include "Poco/Foundation.h"
  18. namespace Poco {
  19. template <class TArgs, class TDelegate>
  20. class NotificationStrategy
  21. /// The interface that all notification strategies must implement.
  22. ///
  23. /// Note: Event is based on policy-driven design, so every strategy implementation
  24. /// must provide all the methods from this interface (otherwise: compile errors)
  25. /// but does not need to inherit from NotificationStrategy.
  26. {
  27. public:
  28. typedef TDelegate* DelegateHandle;
  29. NotificationStrategy()
  30. {
  31. }
  32. virtual ~NotificationStrategy()
  33. {
  34. }
  35. virtual void notify(const void* sender, TArgs& arguments) = 0;
  36. /// Sends a notification to all registered delegates.
  37. virtual DelegateHandle add(const TDelegate& delegate) = 0;
  38. /// Adds a delegate to the strategy.
  39. virtual void remove(const TDelegate& delegate) = 0;
  40. /// Removes a delegate from the strategy, if found.
  41. /// Does nothing if the delegate has not been added.
  42. virtual void remove(DelegateHandle delegateHandle) = 0;
  43. /// Removes a delegate from the strategy, if found.
  44. /// Does nothing if the delegate has not been added.
  45. virtual void clear() = 0;
  46. /// Removes all delegates from the strategy.
  47. virtual bool empty() const = 0;
  48. /// Returns false if the strategy contains at least one delegate.
  49. };
  50. template <class TDelegate>
  51. class NotificationStrategy<void, TDelegate>
  52. /// The interface that all notification strategies must implement.
  53. ///
  54. /// Note: Event is based on policy-driven design, so every strategy implementation
  55. /// must provide all the methods from this interface (otherwise: compile errors)
  56. /// but does not need to inherit from NotificationStrategy.
  57. {
  58. public:
  59. typedef TDelegate* DelegateHandle;
  60. NotificationStrategy()
  61. {
  62. }
  63. virtual ~NotificationStrategy()
  64. {
  65. }
  66. virtual void notify(const void* sender) = 0;
  67. /// Sends a notification to all registered delegates.
  68. virtual DelegateHandle add(const TDelegate& delegate) = 0;
  69. /// Adds a delegate to the strategy.
  70. virtual void remove(const TDelegate& delegate) = 0;
  71. /// Removes a delegate from the strategy, if found.
  72. /// Does nothing if the delegate has not been added.
  73. virtual void remove(DelegateHandle delegateHandle) = 0;
  74. /// Removes a delegate from the strategy, if found.
  75. /// Does nothing if the delegate has not been added.
  76. virtual void clear() = 0;
  77. /// Removes all delegates from the strategy.
  78. virtual bool empty() const = 0;
  79. /// Returns false if the strategy contains at least one delegate.
  80. };
  81. } // namespace Poco
  82. #endif // Foundation_NotificationStrategy_INCLUDED