Add parsed data cache.
[xy_vsfilter.git] / src / subtitles / cache_manager.h
blobfa8bb2d9199d365c8f9f1e1f43b274958ca14b68
1 /************************************************************************/
2 /* author: xy */
3 /* date: 20110926 */
4 /************************************************************************/
5 #ifndef __CACHE_MANAGER_H_310C134F_844C_4590_A4D2_AD30165AF10A__
6 #define __CACHE_MANAGER_H_310C134F_844C_4590_A4D2_AD30165AF10A__
8 #include "RTS.h"
10 class CWordCacheKey
12 public:
13 CWordCacheKey(const CWord& word);
14 CWordCacheKey(const CWordCacheKey& key);
15 CWordCacheKey(const FwSTSStyle& style, const CStringW& str, int ktype, int kstart, int kend);
16 bool operator==(const CWordCacheKey& key)const;
17 bool operator==(const CWord& key)const;
19 CStringW m_str;
20 FwSTSStyle m_style;
21 int m_ktype, m_kstart, m_kend;
24 class PathDataCacheKey
26 public:
27 PathDataCacheKey(const CWord& word):m_str(word.m_str),m_style(word.m_style){}
28 PathDataCacheKey(const PathDataCacheKey& key):m_str(key.m_str),m_style(key.m_style){}
29 PathDataCacheKey(const FwSTSStyle& style, const CStringW& str):m_str(str),m_style(style){}
30 bool operator==(const PathDataCacheKey& key)const
32 return m_str==key.m_str && ( m_style==key.m_style || CompareSTSStyle(m_style, key.m_style) );
34 bool operator==(const CWord& key)const
36 return m_str==key.m_str && ( m_style==key.m_style || CompareSTSStyle(m_style.get(), key.m_style.get()) );
39 static bool CompareSTSStyle(const STSStyle& lhs, const STSStyle& rhs);
40 protected:
41 CStringW m_str;
42 FwSTSStyle m_style;
44 friend std::size_t hash_value(const PathDataCacheKey& key);
47 class ScanLineDataCacheKey: public PathDataCacheKey
49 public:
50 ScanLineDataCacheKey(const CWord& word, const POINT& org):PathDataCacheKey(word),m_org(org) { }
51 ScanLineDataCacheKey(const ScanLineDataCacheKey& key):PathDataCacheKey(key),m_org(key.m_org) { }
52 ScanLineDataCacheKey(const FwSTSStyle& style, const CStringW& str, const POINT& org)
53 :PathDataCacheKey(style, str),m_org(org) { }
54 bool operator==(const ScanLineDataCacheKey& key)const;
56 POINT m_org;
59 class OverlayNoBlurKey: public ScanLineDataCacheKey
61 public:
62 OverlayNoBlurKey(const CWord& word, const POINT& p, const POINT& org):ScanLineDataCacheKey(word,org),m_p(p) { }
63 OverlayNoBlurKey(const OverlayNoBlurKey& key):ScanLineDataCacheKey(key),m_p(key.m_p) { }
64 OverlayNoBlurKey(const FwSTSStyle& style, const CStringW& str, const POINT& p, const POINT& org)
65 :ScanLineDataCacheKey(style, str, org),m_p(p) { }
66 bool operator==(const OverlayNoBlurKey& key)const;
68 POINT m_p;
71 class OverlayKey: public OverlayNoBlurKey
73 public:
74 OverlayKey(const CWord& word, const POINT& p, const POINT& org):OverlayNoBlurKey(word, p, org) { }
75 OverlayKey(const OverlayKey& key):OverlayNoBlurKey(key){ }
77 bool operator==(const OverlayKey& key)const;
79 friend std::size_t hash_value(const OverlayKey& key);
82 std::size_t hash_value(const CWord& key);
83 std::size_t hash_value(const PathDataCacheKey& key);
84 std::size_t hash_value(const ScanLineDataCacheKey& key);
85 std::size_t hash_value(const OverlayNoBlurKey& key);
86 std::size_t hash_value(const OverlayKey& key);
87 std::size_t hash_value(const CWordCacheKey& key);
89 //shouldn't use std::pair, or else VC complaining error C2440
90 //typedef std::pair<OverlayKey, SharedPtrOverlay> OverlayMruItem;
91 struct AssTagListMruItem
93 CStringW script;
94 CRenderedTextSubtitle::SharedPtrConstAssTagList tag_list;
97 struct OverlayMruItem
99 OverlayMruItem(const OverlayKey& overlay_key_, const SharedPtrOverlay& overlay_):overlay_key(overlay_key_),overlay(overlay_){}
101 OverlayKey overlay_key;
102 SharedPtrOverlay overlay;
105 struct CWordMruItem
107 CWordMruItem(const CWordCacheKey& word_key_, const SharedPtrCWord& word_):word_key(word_key_),word(word_){}
109 CWordCacheKey word_key;
110 SharedPtrCWord word;
113 struct PathDataMruItem
115 PathDataMruItem(const PathDataCacheKey& path_data_key_, const SharedPtrConstPathData& path_data_):
116 path_data_key(path_data_key_),path_data(path_data_){}
118 PathDataCacheKey path_data_key;
119 SharedPtrConstPathData path_data;
122 struct ScanLineDataMruItem
124 ScanLineDataMruItem(const ScanLineDataCacheKey& scan_line_data_key_, const SharedPtrConstScanLineData& scan_line_data_):
125 scan_line_data_key(scan_line_data_key_),scan_line_data(scan_line_data_){}
127 ScanLineDataCacheKey scan_line_data_key;
128 SharedPtrConstScanLineData scan_line_data;
131 struct OverlayNoBlurMruItem
133 OverlayNoBlurMruItem(const OverlayNoBlurKey& key_, const SharedPtrOverlay& overlay_)
134 :key(key_),overlay(overlay_){}
136 OverlayNoBlurKey key;
137 SharedPtrOverlay overlay;
140 typedef enhanced_mru_list<
141 AssTagListMruItem,
142 boost::multi_index::member<AssTagListMruItem,
143 CStringW,
144 &AssTagListMruItem::script
146 > AssTagListMruCache;
148 typedef enhanced_mru_list<
149 OverlayMruItem,
150 boost::multi_index::member<OverlayMruItem,
151 OverlayKey,
152 &OverlayMruItem::overlay_key
154 > OverlayMruCache;
156 typedef enhanced_mru_list<
157 CWordMruItem,
158 boost::multi_index::member<CWordMruItem,
159 CWordCacheKey,
160 &CWordMruItem::word_key
162 > CWordMruCache;
164 typedef enhanced_mru_list<
165 PathDataMruItem,
166 boost::multi_index::member<PathDataMruItem,
167 PathDataCacheKey,
168 &PathDataMruItem::path_data_key
170 > PathDataMruCache;
172 typedef enhanced_mru_list<
173 ScanLineDataMruItem,
174 boost::multi_index::member<ScanLineDataMruItem,
175 ScanLineDataCacheKey,
176 &ScanLineDataMruItem::scan_line_data_key
178 > ScanLineDataMruCache;
180 typedef enhanced_mru_list<
181 OverlayNoBlurMruItem,
182 boost::multi_index::member<OverlayNoBlurMruItem,
183 OverlayNoBlurKey,
184 &OverlayNoBlurMruItem::key
186 > OverlayNoBlurMruCache;
188 class CacheManager
190 public:
191 static const int ASS_TAG_LIST_CACHE_ITEM_NUM = 256;
192 static const int SUBPIXEL_VARIANCE_CACHE_ITEM_NUM = 256;
193 static const int OVERLAY_CACHE_ITEM_NUM = 256;
195 static const int OVERLAY_NO_BLUR_CACHE_ITEM_NUM = 256;
196 static const int SCAN_LINE_DATA_CACHE_ITEM_NUM = 256;
197 static const int PATH_CACHE_ITEM_NUM = 256;
198 static const int WORD_CACHE_ITEM_NUM = 512;
200 static AssTagListMruCache* GetAssTagListMruCache();
201 static OverlayMruCache* GetSubpixelVarianceCache();
202 static OverlayMruCache* GetOverlayMruCache();
203 static OverlayNoBlurMruCache* GetOverlayNoBlurMruCache();
204 static ScanLineDataMruCache* GetScanLineDataMruCache();
205 static PathDataMruCache* GetPathDataMruCache();
206 static CWordMruCache* GetCWordMruCache();
207 private:
208 static AssTagListMruCache* s_ass_tag_list_cache;
209 static OverlayMruCache* s_subpixel_variance_cache;
210 static OverlayMruCache* s_overlay_mru_cache;
211 static OverlayNoBlurMruCache* s_overlay_no_blur_mru_cache;
212 static PathDataMruCache* s_path_data_mru_cache;
213 static ScanLineDataMruCache* s_scan_line_data_mru_cache;
214 static CWordMruCache* s_word_mru_cache;
217 #endif // end of __CACHE_MANAGER_H_310C134F_844C_4590_A4D2_AD30165AF10A__