AbstractDelegate.h 2.3 KB

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