NotificationStrategy.h 3.0 KB

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