1 #ifndef OSMSCOUT_MAPTILECACHE_H 2 #define OSMSCOUT_MAPTILECACHE_H 42 typedef typename std::shared_ptr<T>
TRef;
63 typedef typename std::list<CacheEntry>
Cache;
66 typedef typename Cache::iterator CacheRef;
69 typedef typename std::map<TileKey,CacheRef> CacheIndex;
74 mutable CacheIndex tileIndex;
75 mutable Cache tileCache;
88 const GeoBox& boundingBox,
97 : cacheSize(cacheSize)
108 bool cleanupCache=cacheSize<this->cacheSize;
110 this->cacheSize=cacheSize;
124 if (tileCache.size()>cacheSize) {
125 auto currentEntry=tileCache.rbegin();
127 while (currentEntry!=tileCache.rend() &&
128 tileCache.size()>cacheSize) {
129 if (currentEntry->tile.use_count()==1) {
130 tileIndex.erase(currentEntry->id);
133 currentEntry=std::reverse_iterator<MapTileCache<T>::CacheRef>(tileCache.erase(currentEntry.base()));
149 typename std::map<TileId,MapTileCache<T>::CacheRef>::iterator existingEntry=tileIndex.find(key);
151 if (existingEntry!=tileIndex.end()) {
152 tileCache.splice(tileCache.begin(),tileCache,existingEntry->second);
153 existingEntry->second=tileCache.begin();
155 return existingEntry->second->tile;
168 typename std::map<TileId,MapTileCache<T>::CacheRef>::iterator existingEntry=tileIndex.find(key);
170 if (existingEntry==tileIndex.end()) {
176 tileCache.push_front(cacheEntry);
177 tileIndex[key]=tileCache.begin();
182 tileCache.splice(tileCache.begin(),tileCache,existingEntry->second);
183 existingEntry->second=tileCache.begin();
185 return existingEntry->second->tile;
194 const GeoBox& boundingBox,
201 TileIdBox box(
TileId::GetTile(magnification,boundingBox.GetMinCoord()),
204 for (
const auto& tileId : box) {
205 tiles.push_back(GetTile(
TileKey(magnification,tileId)));
void SetSize(size_t cacheSize)
Definition: MapTileCache.h:106
Definition: MapTileCache.h:39
MapTileCache(size_t cacheSize)
Definition: MapTileCache.h:96
Definition: MapTileCache.h:209
std::shared_ptr< MapTile > MapTileRef
Definition: MapTileCache.h:237
MapTileCache< T >::TRef GetCachedTile(const TileKey &key) const
Definition: MapTileCache.h:147
void CleanupCache()
Definition: MapTileCache.h:122
void GetTilesForBoundingBox(const Magnification &magnification, const GeoBox &boundingBox, std::list< typename MapTileCache< T >::TRef > &tiles) const
Definition: MapTileCache.h:193
#define OSMSCOUT_MAP_API
Definition: MapImportExport.h:45
MapTileCache< T >::TRef GetTile(const TileKey &key) const
Definition: MapTileCache.h:166
GeoBox GetBoundingBox() const
Definition: MapTileCache.h:231
TileKey GyetKe() const
Definition: MapTileCache.h:223
std::shared_ptr< T > TRef
Definition: MapTileCache.h:42
static TileId GetTile(const Magnification &magnification, const GeoCoord &coord)