AbstractStrategy.h 1.9 KB

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