Welcome to mirror list, hosted at ThFree Co, Russian Federation.

tile_cache.hpp « map - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 68b6941e7a14fc76518677d85592a0276c6bbd1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#pragma once

#include "tile.hpp"
#include "tiler.hpp"

#include "../graphics/resource_manager.hpp"

#include "../base/mru_cache.hpp"
#include "../base/mutex.hpp"

#include "../std/bind.hpp"

class ResourceManager;

class TileCache
{
public:

  struct Entry
  {
    Tile m_tile;
    shared_ptr<graphics::ResourceManager> m_rm;
    Entry();
    Entry(Tile const & tile, shared_ptr<graphics::ResourceManager> const & rm);
  };

  struct EntryValueTraits
  {
    static void Evict(Entry & val);
  };

private:

  my::MRUCache<Tiler::RectInfo, Entry, EntryValueTraits> m_cache;
  threads::Mutex m_lock;

  TileCache(TileCache const & src);
  TileCache const & operator=(TileCache const & src);

public:

  TileCache();
  /// lock for multithreaded access
  void Lock();
  /// unlock for multithreaded access
  void Unlock();
  /// get keys of values in cache
  set<Tiler::RectInfo> const & Keys() const;
  /// add tile to cache
  void AddTile(Tiler::RectInfo const & key, Entry const & entry);
  /// check, whether we have some tile in the cache
  bool HasTile(Tiler::RectInfo const & key);
  /// lock tile
  void LockTile(Tiler::RectInfo const & key);
  /// unlock tile
  void UnlockTile(Tiler::RectInfo const & key);
  /// lock count
  size_t LockCount(Tiler::RectInfo const & key);
  /// touch tile
  void TouchTile(Tiler::RectInfo const & key);
  /// get tile from the cache
  Tile const & GetTile(Tiler::RectInfo const & key);
  /// remove the specified tile from the cache
  void Remove(Tiler::RectInfo const & key);
  /// how much elements can fit in the tileCache
  int CanFit() const;
  /// how many unlocked elements do we have in tileCache
  int UnlockedWeight() const;
  /// how many locked elements do we have in tileCache
  int LockedWeight() const;
  /// the size of the cache
  int CacheSize() const;
  /// resize the cache
  void Resize(int maxWeight);
  /// free up to weight spaces evicting unlocked elements from cache
  void FreeRoom(int weight);
};