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 | |
16 | |
17 | #ifndef Foundation_AbstractStrategy_INCLUDED |
18 | #define Foundation_AbstractStrategy_INCLUDED |
19 | |
20 | |
21 | #include "Poco/KeyValueArgs.h" |
22 | #include "Poco/ValidArgs.h" |
23 | #include "Poco/EventArgs.h" |
24 | #include <set> |
25 | |
26 | |
27 | namespace Poco { |
28 | |
29 | |
30 | template <class TKey, class TValue> |
31 | class AbstractStrategy |
32 | /// An AbstractStrategy is the interface for all strategies. |
33 | { |
34 | public: |
35 | AbstractStrategy() |
36 | { |
37 | } |
38 | |
39 | virtual ~AbstractStrategy() |
40 | { |
41 | } |
42 | |
43 | virtual void onUpdate(const void* pSender, const KeyValueArgs <TKey, TValue>& args) |
44 | /// Updates an existing entry. |
45 | { |
46 | onRemove(pSender,args.key()); |
47 | onAdd(pSender, args); |
48 | } |
49 | |
50 | virtual void onAdd(const void* pSender, const KeyValueArgs <TKey, TValue>& key) = 0; |
51 | /// Adds the key to the strategy. |
52 | /// If for the key already an entry exists, an exception will be thrown. |
53 | |
54 | virtual void onRemove(const void* pSender, const TKey& key) = 0; |
55 | /// Removes an entry from the strategy. If the entry is not found |
56 | /// the remove is ignored. |
57 | |
58 | virtual void onGet(const void* pSender, const TKey& key) = 0; |
59 | /// Informs the strategy that a read-access happens to an element. |
60 | |
61 | virtual void onClear(const void* pSender, const EventArgs& args) = 0; |
62 | /// Removes all elements from the cache. |
63 | |
64 | virtual void onIsValid(const void* pSender, ValidArgs<TKey>& key) = 0; |
65 | /// Used to query if a key is still valid (i.e. cached). |
66 | |
67 | virtual void onReplace(const void* pSender, std::set<TKey>& elemsToRemove) = 0; |
68 | /// Used by the Strategy to indicate which elements should be removed from |
69 | /// the cache. Note that onReplace does not change the current list of keys. |
70 | /// The cache object is responsible to remove the elements. |
71 | }; |
72 | |
73 | |
74 | } // namespace Poco |
75 | |
76 | |
77 | #endif // Foundation_AbstractStrategy_INCLUDED |
78 | |