AbstractStrategy.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // AbstractStrategy.h
  3. //
  4. // $Id: //poco/1.4/Foundation/include/Poco/AbstractStrategy.h#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Cache
  8. // Module: AbstractCache
  9. //
  10. // Definition of the AbstractStrategy class.
  11. //
  12. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
  13. // and Contributors.
  14. //
  15. // SPDX-License-Identifier: BSL-1.0
  16. //
  17. #ifndef Foundation_AbstractStrategy_INCLUDED
  18. #define Foundation_AbstractStrategy_INCLUDED
  19. #include "Poco/KeyValueArgs.h"
  20. #include "Poco/ValidArgs.h"
  21. #include "Poco/EventArgs.h"
  22. #include <set>
  23. namespace Poco {
  24. template <class TKey, class TValue>
  25. class AbstractStrategy
  26. /// An AbstractStrategy is the interface for all strategies.
  27. {
  28. public:
  29. AbstractStrategy()
  30. {
  31. }
  32. virtual ~AbstractStrategy()
  33. {
  34. }
  35. virtual void onUpdate(const void* pSender, const KeyValueArgs <TKey, TValue>& args)
  36. /// Updates an existing entry.
  37. {
  38. onRemove(pSender,args.key());
  39. onAdd(pSender, args);
  40. }
  41. virtual void onAdd(const void* pSender, const KeyValueArgs <TKey, TValue>& key) = 0;
  42. /// Adds the key to the strategy.
  43. /// If for the key already an entry exists, an exception will be thrown.
  44. virtual void onRemove(const void* pSender, const TKey& key) = 0;
  45. /// Removes an entry from the strategy. If the entry is not found
  46. /// the remove is ignored.
  47. virtual void onGet(const void* pSender, const TKey& key) = 0;
  48. /// Informs the strategy that a read-access happens to an element.
  49. virtual void onClear(const void* pSender, const EventArgs& args) = 0;
  50. /// Removes all elements from the cache.
  51. virtual void onIsValid(const void* pSender, ValidArgs<TKey>& key) = 0;
  52. /// Used to query if a key is still valid (i.e. cached).
  53. virtual void onReplace(const void* pSender, std::set<TKey>& elemsToRemove) = 0;
  54. /// Used by the Strategy to indicate which elements should be removed from
  55. /// the cache. Note that onReplace does not change the current list of keys.
  56. /// The cache object is reponsible to remove the elements.
  57. };
  58. } // namespace Poco
  59. #endif // Foundation_AbstractStrategy_INCLUDED