Changing from boost multi_index MRU to ATL style MRU.
[xy_vsfilter.git] / src / subtitles / cache_manager.h
blobd21562614193ff3252ce54e126914f3e7c55885c
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"
9 #include "mru_cache.h"
11 class TextInfoCacheKey
13 public:
14 CStringW m_str;
15 FwSTSStyle m_style;
16 bool operator==(const TextInfoCacheKey& key)const;
18 friend class TextInfoCacheKeyTraits;
21 class CWordCacheKey
23 public:
24 CWordCacheKey(const CWord& word);
25 CWordCacheKey(const CWordCacheKey& key);
26 CWordCacheKey(const FwSTSStyle& style, const CStringW& str, int ktype, int kstart, int kend);
27 bool operator==(const CWordCacheKey& key)const;
28 bool operator==(const CWord& key)const;
30 CStringW m_str;
31 FwSTSStyle m_style;
32 int m_ktype, m_kstart, m_kend;
34 friend class CWordCacheKeyTraits;
37 class PathDataCacheKey
39 public:
40 PathDataCacheKey(const CWord& word):m_str(word.m_str),m_style(word.m_style){}
41 PathDataCacheKey(const PathDataCacheKey& key):m_str(key.m_str),m_style(key.m_style){}
42 PathDataCacheKey(const FwSTSStyle& style, const CStringW& str):m_str(str),m_style(style){}
43 bool operator==(const PathDataCacheKey& key)const
45 return m_str==key.m_str && ( m_style==key.m_style || CompareSTSStyle(m_style, key.m_style) );
47 bool operator==(const CWord& key)const
49 return m_str==key.m_str && ( m_style==key.m_style || CompareSTSStyle(m_style.get(), key.m_style.get()) );
52 static bool CompareSTSStyle(const STSStyle& lhs, const STSStyle& rhs);
53 protected:
54 CStringW m_str;
55 FwSTSStyle m_style;
57 friend class PathDataCacheKeyTraits;
60 class ScanLineDataCacheKey: public PathDataCacheKey
62 public:
63 ScanLineDataCacheKey(const CWord& word, const POINT& org):PathDataCacheKey(word),m_org(org) { }
64 ScanLineDataCacheKey(const ScanLineDataCacheKey& key):PathDataCacheKey(key),m_org(key.m_org) { }
65 ScanLineDataCacheKey(const FwSTSStyle& style, const CStringW& str, const POINT& org)
66 :PathDataCacheKey(style, str),m_org(org) { }
67 bool operator==(const ScanLineDataCacheKey& key)const;
69 POINT m_org;
71 friend class ScanLineDataCacheKeyTraits;
74 class OverlayNoBlurKey: public ScanLineDataCacheKey
76 public:
77 OverlayNoBlurKey(const CWord& word, const POINT& p, const POINT& org):ScanLineDataCacheKey(word,org),m_p(p) { }
78 OverlayNoBlurKey(const OverlayNoBlurKey& key):ScanLineDataCacheKey(key),m_p(key.m_p) { }
79 OverlayNoBlurKey(const FwSTSStyle& style, const CStringW& str, const POINT& p, const POINT& org)
80 :ScanLineDataCacheKey(style, str, org),m_p(p) { }
81 bool operator==(const OverlayNoBlurKey& key)const;
83 POINT m_p;
86 class OverlayKey: public OverlayNoBlurKey
88 public:
89 OverlayKey(const CWord& word, const POINT& p, const POINT& org):OverlayNoBlurKey(word, p, org) { }
90 OverlayKey(const OverlayKey& key):OverlayNoBlurKey(key){ }
92 bool operator==(const OverlayKey& key)const;
94 friend class OverlayKeyTraits;
97 std::size_t hash_value(const CWord& key);
99 class TextInfoCacheKeyTraits:public CElementTraits<TextInfoCacheKey>
101 public:
102 static ULONG Hash(const TextInfoCacheKey& key);
105 class CWordCacheKeyTraits:public CElementTraits<CWordCacheKey>
107 public:
108 static ULONG Hash(const CWordCacheKey& key);
111 class PathDataCacheKeyTraits:public CElementTraits<PathDataCacheKey>
113 public:
114 static ULONG Hash(const PathDataCacheKey& key);
117 class ScanLineDataCacheKeyTraits:public CElementTraits<ScanLineDataCacheKey>
119 public:
120 static ULONG Hash(const ScanLineDataCacheKey& key);
123 class OverlayNoBlurKeyTraits:public CElementTraits<OverlayNoBlurKey>
125 public:
126 static ULONG Hash(const OverlayNoBlurKey& key);
129 class OverlayKeyTraits:public CElementTraits<OverlayKey>
131 public:
132 static ULONG Hash(const OverlayKey& key);
135 typedef EnhancedXyMru<
136 TextInfoCacheKey,
137 CText::SharedPtrTextInfo,
138 TextInfoCacheKeyTraits
139 > TextInfoMruCache;
141 typedef EnhancedXyMru<
142 CStringW,
143 CRenderedTextSubtitle::SharedPtrConstAssTagList,
144 CStringElementTraits<CStringW>
145 > AssTagListMruCache;
147 typedef EnhancedXyMru<CWordCacheKey, SharedPtrCWord, CWordCacheKeyTraits> CWordMruCache;
149 typedef EnhancedXyMru<PathDataCacheKey, SharedPtrConstPathData, PathDataCacheKeyTraits> PathDataMruCache;
151 typedef EnhancedXyMru<ScanLineDataCacheKey, SharedPtrConstScanLineData, ScanLineDataCacheKeyTraits> ScanLineDataMruCache;
153 typedef EnhancedXyMru<OverlayNoBlurKey, SharedPtrOverlay, OverlayNoBlurKeyTraits> OverlayNoBlurMruCache;
155 typedef EnhancedXyMru<OverlayKey, SharedPtrOverlay, OverlayKeyTraits> OverlayMruCache;
157 class CacheManager
159 public:
160 static const int TEXT_INFO_CACHE_ITEM_NUM = 2048;
161 static const int ASS_TAG_LIST_CACHE_ITEM_NUM = 256;
162 static const int SUBPIXEL_VARIANCE_CACHE_ITEM_NUM = 256;
163 static const int OVERLAY_CACHE_ITEM_NUM = 256;
165 static const int OVERLAY_NO_BLUR_CACHE_ITEM_NUM = 256;
166 static const int SCAN_LINE_DATA_CACHE_ITEM_NUM = 256;
167 static const int PATH_CACHE_ITEM_NUM = 256;
168 static const int WORD_CACHE_ITEM_NUM = 512;
170 static TextInfoMruCache* GetTextInfoCache();
171 static AssTagListMruCache* GetAssTagListMruCache();
172 static OverlayMruCache* GetSubpixelVarianceCache();
173 static OverlayMruCache* GetOverlayMruCache();
174 static OverlayNoBlurMruCache* GetOverlayNoBlurMruCache();
175 static ScanLineDataMruCache* GetScanLineDataMruCache();
176 static PathDataMruCache* GetPathDataMruCache();
177 static CWordMruCache* GetCWordMruCache();
178 private:
179 static TextInfoMruCache* s_text_info_cache;
180 static AssTagListMruCache* s_ass_tag_list_cache;
181 static OverlayMruCache* s_subpixel_variance_cache;
182 static OverlayMruCache* s_overlay_mru_cache;
183 static OverlayNoBlurMruCache* s_overlay_no_blur_mru_cache;
184 static PathDataMruCache* s_path_data_mru_cache;
185 static ScanLineDataMruCache* s_scan_line_data_mru_cache;
186 static CWordMruCache* s_word_mru_cache;
189 #endif // end of __CACHE_MANAGER_H_310C134F_844C_4590_A4D2_AD30165AF10A__