|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef CPIX_WRAPPERTRAITSDB_H |
|
19 #define CPIX_WRAPPERTRAITSDB_H |
|
20 |
|
21 |
|
22 |
|
23 /** |
|
24 * Compile time type association between wrapper class and |
|
25 * wrapped clucene class. |
|
26 * |
|
27 * This struct is to be specialized for specific wrapper class - |
|
28 * native clucene class pairs. These will be found, in general, in the |
|
29 * implementation source files. |
|
30 */ |
|
31 template<typename WRP_CLASS> |
|
32 struct WrapperTraits |
|
33 { |
|
34 // All this struct ("CONCEPT") is to provide a typedef with name |
|
35 // NativeClass, telling what the native class associated to the |
|
36 // wrapper class is. |
|
37 // |
|
38 // typedef ??? NativeClass; |
|
39 |
|
40 }; |
|
41 |
|
42 |
|
43 enum |
|
44 { |
|
45 NOT_REFCOUNTED = 0, |
|
46 LUCENE_REFCOUNTED = 1, |
|
47 CPIX_REFCOUNTED = 2 |
|
48 }; |
|
49 |
|
50 |
|
51 /** |
|
52 * To enable correct release of native lucene types based on whether |
|
53 * they are refcounted or not. |
|
54 */ |
|
55 template<typename WRP_CLASS> |
|
56 struct RefCountTraits |
|
57 { |
|
58 enum |
|
59 { |
|
60 /** |
|
61 * This value here tells if a native is refcounted |
|
62 * *always* (derived with LUCENE_REFBASE macro). If it is |
|
63 * not, the value is NOT_REFCOUNTED (0), as in the case of |
|
64 * most lucene classes. For the reference counted clucene |
|
65 * classes use value LUCENE_REFCOUNTED (1). For Cpix:: |
|
66 * reference counted classes (deriving from |
|
67 * RefCountedBase) use value CPIX_REFCOUNTED (2). |
|
68 * |
|
69 * (it seems like that: index/Term, store/Directory and |
|
70 * storey/FSDirectory are such classes, so far). |
|
71 */ |
|
72 REFCOUNTED = NOT_REFCOUNTED |
|
73 }; |
|
74 }; |
|
75 |
|
76 |
|
77 /** |
|
78 * Yields the native pointer based on the wrapper instance (does the |
|
79 * reinterpret casting itself). For a NULL pointer wrapper instance it |
|
80 * yields a NULL pointer native instance. |
|
81 */ |
|
82 template<typename WRP_CLASS> |
|
83 typename WrapperTraits<WRP_CLASS>::NativeClass * Cast2Native(WRP_CLASS * p) |
|
84 { |
|
85 typedef typename WrapperTraits<WRP_CLASS>::NativeClass NativeClass; |
|
86 |
|
87 NativeClass |
|
88 * rv = NULL; |
|
89 |
|
90 if (p != NULL) |
|
91 { |
|
92 rv = reinterpret_cast<NativeClass*>(p->ptr_); |
|
93 } |
|
94 |
|
95 return rv; |
|
96 } |
|
97 |
|
98 |
|
99 /******************************************************* |
|
100 * Forward declarations |
|
101 */ |
|
102 namespace lucene { namespace analysis { |
|
103 class SnowballAnalyzer; |
|
104 } |
|
105 } |
|
106 namespace Cpix { |
|
107 class CustomAnalyzer; |
|
108 class SystemAnalyzer; |
|
109 } |
|
110 |
|
111 |
|
112 |
|
113 /******************************************************* |
|
114 * Wrapper Traits "Database" |
|
115 */ |
|
116 |
|
117 |
|
118 |
|
119 template<> |
|
120 struct WrapperTraits<cpix_InitParams> |
|
121 { |
|
122 typedef Cpix::InitParams NativeClass; |
|
123 }; |
|
124 |
|
125 |
|
126 template<> |
|
127 struct WrapperTraits<cpix_IdxDb> |
|
128 { |
|
129 typedef Cpix::IIdxDb NativeClass; |
|
130 }; |
|
131 |
|
132 |
|
133 template<> |
|
134 struct WrapperTraits<cpix_IdxSearcher> |
|
135 { |
|
136 typedef Cpix::IIdxDb NativeClass; |
|
137 }; |
|
138 |
|
139 |
|
140 |
|
141 // Conceptually, simple analyzer and snowball analyzers are both |
|
142 // analyzers, and hence they are represented by cpix_Analyzer to the |
|
143 // clients. The only thing we do here is to make sure that Create() |
|
144 // template function (cpixutils.h) works properly. |
|
145 struct cpix_SimpleAnalyzer : public cpix_Analyzer { }; |
|
146 |
|
147 struct cpix_SnowballAnalyzer : public cpix_Analyzer { }; |
|
148 |
|
149 struct cpix_CustomAnalyzer : public cpix_Analyzer { }; |
|
150 |
|
151 struct cpix_SystemAnalyzer : public cpix_Analyzer { }; |
|
152 |
|
153 |
|
154 template<> |
|
155 struct WrapperTraits<cpix_Analyzer> |
|
156 { |
|
157 // OBS typedef lucene::analysis::Analyzer NativeClass; |
|
158 |
|
159 // all native instances wrapped by cpix_Analyzer are actually |
|
160 // Cpix::SystemAnalyzer instances |
|
161 typedef Cpix::SystemAnalyzer NativeClass; |
|
162 }; |
|
163 |
|
164 |
|
165 template<> |
|
166 struct RefCountTraits<cpix_Analyzer> |
|
167 { |
|
168 // Cpix::SystemAnalyzer is ref-counted (deriving from RefCountedBase) |
|
169 enum { REFCOUNTED = CPIX_REFCOUNTED }; |
|
170 }; |
|
171 |
|
172 |
|
173 template<> |
|
174 struct WrapperTraits<cpix_SimpleAnalyzer> |
|
175 { |
|
176 typedef lucene::analysis::SimpleAnalyzer NativeClass; |
|
177 }; |
|
178 |
|
179 |
|
180 template<> |
|
181 struct WrapperTraits<cpix_SnowballAnalyzer> |
|
182 { |
|
183 typedef lucene::analysis::SnowballAnalyzer NativeClass; |
|
184 }; |
|
185 |
|
186 template<> |
|
187 struct WrapperTraits<cpix_CustomAnalyzer> |
|
188 { |
|
189 typedef Cpix::CustomAnalyzer NativeClass; |
|
190 }; |
|
191 |
|
192 template<> |
|
193 struct WrapperTraits<cpix_SystemAnalyzer> |
|
194 { |
|
195 typedef Cpix::SystemAnalyzer NativeClass; |
|
196 }; |
|
197 |
|
198 |
|
199 struct cpix_MultiFieldQueryParser : public cpix_QueryParser { }; |
|
200 |
|
201 |
|
202 template<> |
|
203 struct WrapperTraits<cpix_QueryParser> |
|
204 { |
|
205 typedef lucene::queryParser::QueryParser NativeClass; |
|
206 }; |
|
207 |
|
208 |
|
209 template<> |
|
210 struct WrapperTraits<cpix_MultiFieldQueryParser> |
|
211 { |
|
212 typedef lucene::queryParser::MultiFieldQueryParser NativeClass; |
|
213 }; |
|
214 |
|
215 |
|
216 template<> |
|
217 struct WrapperTraits<cpix_BoostMap> |
|
218 { |
|
219 typedef lucene::queryParser::BoostMap NativeClass; |
|
220 }; |
|
221 |
|
222 |
|
223 // forward declaration |
|
224 namespace Cpix |
|
225 { |
|
226 class IQryType; |
|
227 class Field; |
|
228 class DocumentFieldIterator; |
|
229 class Document; |
|
230 } |
|
231 |
|
232 |
|
233 template<> |
|
234 struct WrapperTraits<cpix_Query> |
|
235 { |
|
236 typedef Cpix::IQryType NativeClass; |
|
237 }; |
|
238 |
|
239 |
|
240 template<> |
|
241 struct RefCountTraits<cpix_Query> |
|
242 { |
|
243 // Cpix::IQryType is ref-counted (derives from RefCountedBase) |
|
244 enum { REFCOUNTED = CPIX_REFCOUNTED }; |
|
245 }; |
|
246 |
|
247 |
|
248 template<> |
|
249 struct WrapperTraits<cpix_Hits> |
|
250 { |
|
251 typedef Cpix::IHits NativeClass; |
|
252 }; |
|
253 |
|
254 |
|
255 template<> |
|
256 struct RefCountTraits<cpix_Hits> |
|
257 { |
|
258 // Cpix::IHits is ref-counted (derives from RefCountedBase) |
|
259 enum { REFCOUNTED = CPIX_REFCOUNTED }; |
|
260 }; |
|
261 |
|
262 |
|
263 template<> |
|
264 struct WrapperTraits<cpix_Field> |
|
265 { |
|
266 typedef Cpix::Field NativeClass; |
|
267 }; |
|
268 |
|
269 |
|
270 template<> |
|
271 struct WrapperTraits<cpix_DocFieldEnum> |
|
272 { |
|
273 typedef Cpix::DocumentFieldIterator NativeClass; |
|
274 }; |
|
275 |
|
276 template<> |
|
277 struct WrapperTraits<cpix_Document> |
|
278 { |
|
279 typedef Cpix::Document NativeClass; |
|
280 }; |
|
281 |
|
282 |
|
283 template<> |
|
284 struct RefCountTraits<cpix_Document> |
|
285 { |
|
286 // Cpix::Document is ref-counted (derives from RefCountedBase) |
|
287 enum { REFCOUNTED = CPIX_REFCOUNTED }; |
|
288 }; |
|
289 |
|
290 |
|
291 template<> |
|
292 struct WrapperTraits<cpix_Term> |
|
293 { |
|
294 typedef lucene::index::Term NativeClass; |
|
295 |
|
296 }; |
|
297 |
|
298 template<> |
|
299 struct RefCountTraits<cpix_Term> |
|
300 { |
|
301 // Term is ref-counted |
|
302 enum { REFCOUNTED = LUCENE_REFCOUNTED }; |
|
303 }; |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 #endif // CPIX_WRAPPERTRAITSDB_H |