ctkEACacheMap_p.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #ifndef CTKEACACHEMAP_P_H
  16. #define CTKEACACHEMAP_P_H
  17. /**
  18. * This is the interface of a simple cache map.
  19. */
  20. template<class K, class V, class Impl>
  21. struct ctkEACacheMap
  22. {
  23. virtual ~ctkEACacheMap() {}
  24. /**
  25. * Return the value for the key in case there is one in the cache.
  26. *
  27. * @param key The key to look-up
  28. *
  29. * @return The value for the given key in case there is one in the cache,
  30. * <tt>null</tt> otherwise
  31. */
  32. const V value(const K& key) const
  33. {
  34. return static_cast<const Impl*>(this)->value(key);
  35. }
  36. const V value(const K& key, const V& defaultValue) const
  37. {
  38. return static_cast<const Impl*>(this)->value(key, defaultValue);
  39. }
  40. /**
  41. * Add a value for the key to this cache.
  42. *
  43. * @param key The key for the value
  44. * @param value The value to add to the cache
  45. */
  46. void insert(const K& key, const V& value)
  47. {
  48. static_cast<Impl*>(this)->insert(key, value);
  49. }
  50. /**
  51. * Remove a key and its value from the cache.
  52. *
  53. * @param key The key to remove
  54. *
  55. * @return The value of the key in case there is one in the cache, <tt>null</tt>
  56. * otherwise
  57. */
  58. const V remove(const K& key)
  59. {
  60. return static_cast<Impl*>(this)->remove(key);
  61. }
  62. /**
  63. * Returns the number of key-value pairs in this cache.
  64. *
  65. * @return The number of key-value pairs in this cache
  66. */
  67. int size() const
  68. {
  69. return static_cast<const Impl*>(this)->size();
  70. }
  71. /**
  72. * Remove all entries of the cache.
  73. */
  74. void clear()
  75. {
  76. static_cast<Impl*>(this)->clear();
  77. }
  78. };
  79. #endif // CTKEACACHEMAP_P_H