libcommonc++  0.7
StaticCache.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_StaticCache_hxx
24 #define __ccxx_StaticCache_hxx
25 
27 
28 namespace ccxx {
29 
46 template<typename K, typename T> class StaticCache : public AbstractCache<K, T>
47 {
48  public:
49 
56  StaticCache(uint_t maxSize);
57 
61  virtual ~StaticCache();
62 
72  virtual T* get(const K& key);
73 
74  virtual void clear();
75 
76  protected:
77 
85  virtual T* constructItem() = 0;
86 
100  virtual bool loadItem(const K& key, T* item) = 0;
101 
102  private:
103 
104  typedef typename AbstractCache<K, T>::Link Link;
105  typedef typename AbstractCache<K, T>::MapType MapType;
106 
107  mutable Link* _free;
108 };
109 
110 #include <ccxx/StaticCacheImpl.h++>
111 
112 } // namespace ccxx
113 
114 #endif // __ccxx_StaticCache_hxx
virtual T * constructItem()=0
Construct a new cache item.
virtual void clear()
Remove all items from the cache.
unsigned int uint_t
An alias for unsigned int.
Definition: Integers.h++:74
An abstract base class for a general-purpose LRU-cache with a maximum capacity.
Definition: AbstractCache.h++:46
virtual bool loadItem(const K &key, T *item)=0
Called by get() when the cache does not contain an item with the requested key.
virtual ~StaticCache()
Destructor.
StaticCache(uint_t maxSize)
Construct a new StaticCache with the given maximum size.
Definition: AllocationMap.c++:25
An LRU cache implementation in which cache objects are recycled when they are removed from the cache...
Definition: StaticCache.h++:46