SourceXtractorPlusPlus  0.15
Please provide a description of the project.
TileManager.h
Go to the documentation of this file.
1 
17 /*
18  * TileManager.h
19  *
20  * Created on: Feb 23, 2018
21  * Author: mschefer
22  */
23 
24 #ifndef _SEFRAMEWORK_IMAGE_TILEMANAGER_H_
25 #define _SEFRAMEWORK_IMAGE_TILEMANAGER_H_
26 
27 #include <iostream>
28 #include <thread>
29 #include <list>
30 #include <unordered_map>
31 
32 #include <boost/thread/shared_mutex.hpp>
33 
34 #include <ElementsKernel/Logging.h>
35 
38 
39 namespace SourceXtractor {
40 
41 
42 struct TileKey {
45 
46  bool operator==(const TileKey& other) const;
47 
48  std::string getRepr() const;
49 };
50 
51 inline std::ostream& operator<<(std::ostream& out, const TileKey& tk) {
52  out << tk.getRepr();
53  return out;
54 }
55 
56 }
57 
58 namespace std {
59 
60 template<>
61 struct hash<SourceXtractor::TileKey> {
63  std::size_t local_hash = 0;
64  boost::hash_combine(local_hash, key.m_source);
65  boost::hash_combine(local_hash, key.m_tile_x);
66  boost::hash_combine(local_hash, key.m_tile_y);
67  return local_hash;
68  }
69 };
70 
71 }
72 
73 namespace SourceXtractor {
74 
75 class TileManager {
76 public:
77 
78  TileManager();
79 
80  virtual ~TileManager();
81 
82  // Actually not thread safe, call before starting the multi-threading
83  void setOptions(int tile_width, int tile_height, int max_memory);
84 
85  void flush();
86 
89 
91 
92  void saveAllTiles();
93 
94  int getTileWidth() const;
95 
96  int getTileHeight() const;
97 
98 private:
99 
101 
103 
104  void removeTile(TileKey tile_key);
105 
106  void removeExtraTiles();
107 
109 
113 
117 
118  boost::shared_mutex m_mutex;
119 };
120 
121 }
122 
123 
124 #endif /* _SEFRAMEWORK_IMAGE_TILEMANAGER_H_ */
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
std::unordered_map< const ImageSource *, std::shared_ptr< boost::mutex > > m_mutex_map
Definition: TileManager.h:115
std::shared_ptr< ImageTile > getTileForPixel(int x, int y, std::shared_ptr< const ImageSource > source)
boost::shared_mutex m_mutex
Definition: TileManager.h:118
std::list< TileKey > m_tile_list
Definition: TileManager.h:116
std::shared_ptr< ImageTile > tryTileFromCache(const TileKey &key)
Definition: TileManager.cpp:74
void removeTile(TileKey tile_key)
void addTile(TileKey key, std::shared_ptr< ImageTile > tile)
void setOptions(int tile_width, int tile_height, int max_memory)
Definition: TileManager.cpp:50
static std::shared_ptr< TileManager > getInstance()
std::unordered_map< TileKey, std::shared_ptr< ImageTile > > m_tile_map
Definition: TileManager.h:114
std::shared_ptr< boost::mutex > & getMutexForImageSource(const ImageSource *)
Definition: TileManager.cpp:90
std::ostream & operator<<(std::ostream &out, const TileKey &tk)
Definition: TileManager.h:51
STL namespace.
bool operator==(const TileKey &other) const
Definition: TileManager.cpp:31
std::shared_ptr< const ImageSource > m_source
Definition: TileManager.h:43
std::string getRepr() const
Definition: TileManager.cpp:35
std::size_t operator()(const SourceXtractor::TileKey &key) const
Definition: TileManager.h:62