TimerTaskAdapter.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // TimerTaskAdapter.h
  3. //
  4. // Library: Util
  5. // Package: Timer
  6. // Module: TimerTaskAdapter
  7. //
  8. // Definition of the TimerTaskAdapter class template.
  9. //
  10. // Copyright (c) 2009, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef Util_TimerTaskAdapter_INCLUDED
  16. #define Util_TimerTaskAdapter_INCLUDED
  17. #include "Poco/Util/Util.h"
  18. #include "Poco/Util/TimerTask.h"
  19. namespace Poco {
  20. namespace Util {
  21. template <class C>
  22. class TimerTaskAdapter: public TimerTask
  23. /// This class template simplifies the implementation
  24. /// of TimerTask objects by allowing a member function
  25. /// of an object to be called as task.
  26. {
  27. public:
  28. typedef void (C::*Callback)(TimerTask&);
  29. TimerTaskAdapter(C& object, Callback method): _pObject(&object), _method(method)
  30. /// Creates the TimerTaskAdapter, using the given
  31. /// object and its member function as task target.
  32. ///
  33. /// The member function must accept one argument,
  34. /// a reference to a TimerTask object.
  35. {
  36. }
  37. void run()
  38. {
  39. (_pObject->*_method)(*this);
  40. }
  41. protected:
  42. ~TimerTaskAdapter()
  43. /// Destroys the TimerTaskAdapter.
  44. {
  45. }
  46. private:
  47. TimerTaskAdapter();
  48. C* _pObject;
  49. Callback _method;
  50. };
  51. } } // namespace Poco::Util
  52. #endif // Util_TimerTaskAdapter_INCLUDED