alaCarte Maps
Renderer for OpenStreetMap tiles
cache.hpp
Go to the documentation of this file.
1 
21 #pragma once
22 #ifndef CACHE_HPP
23 #define CACHE_HPP
24 
25 #include "settings.hpp"
26 
27 #include <boost/thread/mutex.hpp>
28 #include <boost/unordered_map.hpp>
29 #include <boost/filesystem.hpp>
30 #include <list>
31 
33 #include "server/tile.hpp"
34 
35 class Configuration;
36 class Stylesheet;
37 
38 class Cache
39 {
40 public:
41 
45  typedef std::list<shared_ptr<Tile>> TileList;
46 
50  typedef std::pair<shared_ptr<Tile>, TileList::iterator> CacheElement;
51 
55  typedef boost::unordered_map<TileIdentifier, CacheElement> CacheOfOneStylesheet;
56 
60  typedef boost::unordered_map<string, shared_ptr<CacheOfOneStylesheet> > CacheContainer;
61 
62 
63  Cache(const shared_ptr<Configuration>& config);
64 
65  TESTABLE shared_ptr<Tile> getTile(const shared_ptr<TileIdentifier>& tl);
66  TESTABLE shared_ptr<Tile> getDefaultTile();
67  TESTABLE void deleteTiles(const string path);
68 
69 private:
70  shared_ptr<Configuration> Config;
71  boost::mutex GlobalCacheLock;
72  CacheContainer AllCaches;
73  TileList RecentlyUsedList;
74  shared_ptr<Tile> DefaultTile;
75  void readFile(const Tile::ImageType& image, const boost::filesystem::path& filename);
76  void writeFile(shared_ptr<Tile> tile, const boost::filesystem::path& filename);
77  const boost::filesystem::path getTilePath(const shared_ptr<TileIdentifier>& ti);
78 };
79 
80 #endif
void readFile(const Tile::ImageType &image, const boost::filesystem::path &filename)
Definition: cache.cpp:44
Cache(const shared_ptr< Configuration > &config)
This file is part of alaCarte.
Definition: cache.cpp:36
A Stylesheet parses a given MapCSS Stylesheet file and stores the defined rules.
Definition: stylesheet.hpp:39
const boost::filesystem::path getTilePath(const shared_ptr< TileIdentifier > &ti)
Definition: cache.cpp:80
boost::unordered_map< TileIdentifier, CacheElement > CacheOfOneStylesheet
HashMap with TileIdentifier as key and shared_ptr to Tiles as value.
Definition: cache.hpp:55
shared_ptr< Tile > DefaultTile
Definition: cache.hpp:74
TileList RecentlyUsedList
Definition: cache.hpp:73
TESTABLE shared_ptr< Tile > getDefaultTile()
Get the default tile used for error and such.
Definition: cache.cpp:182
std::list< shared_ptr< Tile > > TileList
A list that will store the last recently used tiles.
Definition: cache.hpp:45
TESTABLE void deleteTiles(const string path)
Deletes all cached Tiles of the Stylesheet with the given path.
Definition: cache.cpp:204
CacheContainer AllCaches
Definition: cache.hpp:72
boost::unordered_map< string, shared_ptr< CacheOfOneStylesheet > > CacheContainer
HashMap with path to MapCSS as key and shared_ptr to CacheOfOneStylesheet as value.
Definition: cache.hpp:60
static const char * config
Option to get the configuration filename (type: string)
shared_ptr< Configuration > Config
Definition: cache.hpp:70
Represents a set of options accessible via strings.
shared_ptr< std::vector< uint8_t > > ImageType
Definition: tile.hpp:33
#define TESTABLE
Definition: settings.hpp:85
std::pair< shared_ptr< Tile >, TileList::iterator > CacheElement
An element stored in the cache.
Definition: cache.hpp:50
boost::mutex GlobalCacheLock
Definition: cache.hpp:71
Definition: cache.hpp:38
void writeFile(shared_ptr< Tile > tile, const boost::filesystem::path &filename)
Definition: cache.cpp:60
TESTABLE shared_ptr< Tile > getTile(const shared_ptr< TileIdentifier > &tl)
Gets a Tile where the image data can be stored.
Definition: cache.cpp:97