2 /* xapian-headers.i
: Getting SWIG to parse Xapian's C
++ headers.
4 * Copyright
2004,2006,2011,2012,2013,2014,2015,2016,2017 Olly Betts
5 * Copyright
2014 Assem Chelli
7 * This program is free software
; you can redistribute it and
/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation
; either version
2 of the
10 * License
, or
(at your option
) any later version.
12 * This program is distributed in the hope that it will be useful
,
13 * but WITHOUT
ANY WARRANTY
; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program
; if not
, write to the Free Software
19 * Foundation
, Inc.
, 51 Franklin St
, Fifth Floor
, Boston
, MA
02110-1301
24 /* Ignore these functions
: */
25 %ignore Xapian
::iterator_rewind
;
26 %ignore Xapian
::iterator_valid
;
28 /* Ignore anything ending in an underscore
, which is for internal use only
: */
29 %rename
("$ignore", regexmatch$name
="_$") "";
31 /* A class which can usefully be subclassed in the target language.
*/
32 %define SUBCLASSABLE
(NS
, CLASS
)
33 %ignore NS
::CLASS
::clone
;
34 %ignore NS
::CLASS
::serialise
;
35 %ignore NS
::CLASS
::unserialise
;
36 %#ifdef XAPIAN_SWIG_DIRECTORS
37 %feature
(director
) NS
::CLASS
;
41 /* A class which is only useful to wrap if the target language allows
42 * subclassing of wrapped classes
(what SWIG calls
"director support").
44 #ifdef XAPIAN_SWIG_DIRECTORS
45 #define SUBCLASSABLE_ONLY
(NS
, CLASS
) SUBCLASSABLE
(NS
, CLASS
)
47 #define SUBCLASSABLE_ONLY
(NS
, CLASS
) %ignore NS
::CLASS
;
51 /* Tcl needs copy constructors it seems.
*/
52 %define STANDARD_IGNORES
(NS
, CLASS
)
53 %ignore NS
::CLASS
::internal
;
54 %ignore NS
::CLASS
::CLASS
(Internal
*);
55 %ignore NS
::CLASS
::CLASS
(Internal
&);
56 %ignore NS
::CLASS
::operator
=;
57 %ignore NS
::CLASS
::CLASS
(CLASS
&&);
60 %define STANDARD_IGNORES
(NS
, CLASS
)
61 %ignore NS
::CLASS
::internal
;
62 %ignore NS
::CLASS
::CLASS
(Internal
*);
63 %ignore NS
::CLASS
::CLASS
(Internal
&);
64 %ignore NS
::CLASS
::operator
=;
65 %ignore NS
::CLASS
::CLASS
(const CLASS
&);
66 %ignore NS
::CLASS
::CLASS
(CLASS
&&);
71 /* In C#
, next and prev return the iterator object.
*/
72 #define INC_OR_DEC
(METHOD
, OP
, NS
, CLASS
, RET_TYPE
) NS
::CLASS METHOD
() { return OP
(*self
); }
73 #elif defined SWIGJAVA
74 /* In Java
, next and prev return the result of dereferencing the iterator.
*/
75 #define INC_OR_DEC
(METHOD
, OP
, NS
, CLASS
, RET_TYPE
) RET_TYPE METHOD
() { return
*(OP
(*self
)); }
77 /* Otherwise
, next and prev return void.
*/
78 #define INC_OR_DEC
(METHOD
, OP
, NS
, CLASS
, RET_TYPE
) void METHOD
() { OP
(*self
); }
81 /* For other languages
, SWIG already renames operator
() suitably.
*/
82 #if defined SWIGJAVA || defined SWIGPHP || defined SWIGTCL
83 %rename
(apply
) *::operator
();
84 #elif defined SWIGCSHARP
85 %rename
(Apply
) *::operator
();
88 /* We use
%ignore and
%extend rather than
%rename on operator
* so that any
89 * pattern rename used to match local naming conventions applies to
92 %define INPUT_ITERATOR_METHODS
(NS
, CLASS
, RET_TYPE
, DEREF_METHOD
)
93 STANDARD_IGNORES
(NS
, CLASS
)
94 %ignore NS
::CLASS
::operator
++;
95 %ignore NS
::CLASS
::operator
*;
97 bool equals
(const NS
::CLASS
& o) const { return *self == o; }
98 RET_TYPE DEREF_METHOD
() const
{ return
**self
; }
99 INC_OR_DEC
(next
, ++, NS
, CLASS
, RET_TYPE
)
103 %define RANDOM_ACCESS_ITERATOR_METHODS
(NS
, CLASS
, RET_TYPE
, DEREF_METHOD
)
104 INPUT_ITERATOR_METHODS
(NS
, CLASS
, RET_TYPE
, DEREF_METHOD
)
105 %ignore NS
::CLASS
::operator--
;
106 %ignore NS
::CLASS
::operator
+=;
107 %ignore NS
::CLASS
::operator-
=;
108 %ignore NS
::CLASS
::operator
+;
109 %ignore NS
::CLASS
::operator-
;
111 INC_OR_DEC
(prev
, --, NS
, CLASS
, RET_TYPE
)
115 %define CONSTANT
(TYPE, NS
, NAME)
117 %constant
TYPE NAME = NS
::NAME;
120 /* Ignore these for all classes
: */
128 %ignore difference_type
;
129 %ignore iterator_category
;
134 %ignore const_iterator
;
136 %ignore unserialise
(const char
**, const char
*);
139 /* These methods won't throw exceptions.
*/
140 %exception Xapian
::major_version
"$action"
141 %exception Xapian
::minor_version
"$action"
142 %exception Xapian
::revision
"$action"
143 %exception Xapian
::version_string
"$action"
144 // For XAPIAN_DOCID_BASE_TYPE and XAPIAN_TERMCOUNT_BASE_TYPE
:
145 %import
<xapian
/version.h
>
148 // Disable errors about not including headers individually.
149 #define XAPIAN_IN_XAPIAN_H
151 /* We don't wrap the version macros
- they're useful for compile time checks
152 * in C
++ code
, but for a scripting language
, the version functions tell us
153 * the version of Xapian we're actually using
, which is more interesting than
154 * the one the bindings were built against.
156 /* %include
<xapian
/version.h
> */
158 /* Types are needed by most of the other headers.
*/
159 %include
<xapian
/types.h
>
161 CONSTANT
(int
, Xapian
, DB_CREATE
);
162 CONSTANT
(int
, Xapian
, DB_CREATE_OR_OPEN
);
163 CONSTANT
(int
, Xapian
, DB_CREATE_OR_OVERWRITE
);
164 CONSTANT
(int
, Xapian
, DB_OPEN
);
165 CONSTANT
(int
, Xapian
, DB_NO_SYNC
);
166 CONSTANT
(int
, Xapian
, DB_FULL_SYNC
);
167 CONSTANT
(int
, Xapian
, DB_DANGEROUS
);
168 CONSTANT
(int
, Xapian
, DB_NO_TERMLIST
);
169 CONSTANT
(int
, Xapian
, DB_BACKEND_CHERT
);
170 CONSTANT
(int
, Xapian
, DB_BACKEND_GLASS
);
171 CONSTANT
(int
, Xapian
, DB_BACKEND_HONEY
);
172 CONSTANT
(int
, Xapian
, DB_BACKEND_INMEMORY
);
173 CONSTANT
(int
, Xapian
, DB_BACKEND_STUB
);
174 CONSTANT
(int
, Xapian
, DB_RETRY_LOCK
);
175 CONSTANT
(int
, Xapian
, DBCHECK_SHORT_TREE
);
176 CONSTANT
(int
, Xapian
, DBCHECK_FULL_TREE
);
177 CONSTANT
(int
, Xapian
, DBCHECK_SHOW_FREELIST
);
178 CONSTANT
(int
, Xapian
, DBCHECK_SHOW_STATS
);
179 CONSTANT
(int
, Xapian
, DBCHECK_FIX
);
180 CONSTANT
(int
, Xapian
, DBCOMPACT_MULTIPASS
);
181 CONSTANT
(int
, Xapian
, DBCOMPACT_NO_RENUMBER
);
182 CONSTANT
(int
, Xapian
, DBCOMPACT_SINGLE_FILE
);
183 CONSTANT
(int
, Xapian
, DOC_ASSUME_VALID
);
184 %include
<xapian
/constants.h
>
186 /* The Error subclasses are handled separately for languages where we wrap
188 /* %include
<xapian
/error.h
> */
190 INPUT_ITERATOR_METHODS
(Xapian
, PositionIterator
, Xapian
::termpos
, get_termpos
)
191 %include
<xapian
/positioniterator.h
>
193 %ignore Xapian
::DocIDWrapper
;
194 INPUT_ITERATOR_METHODS
(Xapian
, PostingIterator
, Xapian
::docid
, get_docid
)
195 %include
<xapian
/postingiterator.h
>
197 INPUT_ITERATOR_METHODS
(Xapian
, TermIterator
, std
::string
, get_term
)
198 %include
<xapian
/termiterator.h
>
200 INPUT_ITERATOR_METHODS
(Xapian
, ValueIterator
, std
::string
, get_value
)
201 %include
<xapian
/valueiterator.h
>
203 STANDARD_IGNORES
(Xapian
, Document
)
204 %include
<xapian
/document.h
>
206 STANDARD_IGNORES
(Xapian
, Registry
)
207 %include
<xapian
/registry.h
>
209 STANDARD_IGNORES
(Xapian
, Query
)
210 %ignore Xapian
::Query
::Internal
;
211 %ignore operator Query
;
212 %ignore
*::operator
&(const Xapian::Query &, const Xapian::InvertedQuery_ &);
213 %ignore
*::operator~
;
214 %ignore
*::operator
&=;
215 %ignore
*::operator|
=;
216 %ignore
*::operator^
=;
217 %ignore
*::operator
*=;
218 %ignore
*::operator
/=;
219 #if defined SWIGCSHARP || defined SWIGJAVA || defined SWIGLUA || defined SWIGPHP
220 %ignore
*::operator
&;
221 %ignore
*::operator|
;
222 %ignore
*::operator^
;
223 %ignore
*::operator
*;
224 %ignore
*::operator
/;
226 %ignore Xapian
::Query
::LEAF_TERM
;
227 %ignore Xapian
::Query
::LEAF_POSTING_SOURCE
;
228 %ignore Xapian
::Query
::LEAF_MATCH_ALL
;
229 %ignore Xapian
::Query
::LEAF_MATCH_NOTHING
;
231 %warnfilter
(SWIGWARN_TYPE_UNDEFINED_CLASS
) Xapian
::Query
::Internal
;
232 #if defined SWIGCSHARP || defined SWIGJAVA || defined SWIGPERL || \
233 defined SWIGPYTHON || defined SWIGRUBY
234 // C#
, Java
, Perl
, Python and Ruby wrap these
"by hand" to give a nicer API
235 // than SWIG gives by default.
236 %ignore Xapian
::Query
::MatchAll
;
237 %ignore Xapian
::Query
::MatchNothing
;
239 #ifndef XAPIAN_MIXED_SUBQUERIES_BY_ITERATOR_TYPEMAP
240 %ignore Query
(op op_
, XapianSWIGQueryItor qbegin
, XapianSWIGQueryItor qend
,
241 Xapian
::termcount parameter
= 0);
243 %include
<xapian
/query.h
>
245 // Suppress warning that Xapian
::Internal
::intrusive_base is unknown.
246 %warnfilter
(SWIGWARN_TYPE_UNDEFINED_CLASS
) Xapian
::StemImplementation
;
247 SUBCLASSABLE_ONLY
(Xapian
, StemImplementation
)
248 #ifndef XAPIAN_SWIG_DIRECTORS
249 %ignore Xapian
::Stem
::Stem
(Xapian
::StemImplementation
*);
251 STANDARD_IGNORES
(Xapian
, Stem
)
252 %ignore Xapian
::Stem
::Stem
();
253 %include
<xapian
/stem.h
>
255 STANDARD_IGNORES
(Xapian
, TermGenerator
)
256 %ignore Xapian
::TermGenerator
::operator
=;
257 /* Ignore forms which use Utf8Iterator
, as we don't wrap that class.
*/
258 %ignore Xapian
::TermGenerator
::index_text
(const Xapian
::Utf8Iterator
&);
259 %ignore Xapian
::TermGenerator
::index_text
(const Xapian
::Utf8Iterator
&, Xapian::termcount);
260 %ignore Xapian
::TermGenerator
::index_text
(const Xapian
::Utf8Iterator
&, Xapian::termcount, const std::string &);
261 %ignore Xapian
::TermGenerator
::index_text_without_positions
(const Xapian
::Utf8Iterator
&);
262 %ignore Xapian
::TermGenerator
::index_text_without_positions
(const Xapian
::Utf8Iterator
&, Xapian::termcount);
263 %ignore Xapian
::TermGenerator
::index_text_without_positions
(const Xapian
::Utf8Iterator
&, Xapian::termcount, const std::string &);
264 %ignore Xapian
::TermGenerator
::TermGenerator
(const TermGenerator
&);
265 %include
<xapian
/termgenerator.h
>
267 STANDARD_IGNORES
(Xapian
, MSet
)
269 // For compatibility with the original JNI wrappers.
270 %rename
("getElement") Xapian
::MSet
::operator
[];
272 %ignore Xapian
::MSet
::operator
[];
274 %extend Xapian
::MSet
{
275 Xapian
::docid get_docid
(Xapian
::doccount i
) const
{
279 Xapian
::Document get_document
(Xapian
::doccount i
) const
{
280 return
(*self
)[i
].get_document
();
283 Xapian
::MSetIterator get_hit
(Xapian
::doccount i
) const
{
287 int get_document_percentage
(Xapian
::doccount i
) const
{
288 return self-
>convert_to_percent
((*self
)[i
]);
292 RANDOM_ACCESS_ITERATOR_METHODS
(Xapian
, MSetIterator
, Xapian
::docid
, get_docid
)
294 %include
<xapian
/mset.h
>
296 STANDARD_IGNORES
(Xapian
, ESet
)
297 %ignore Xapian
::ESet
::operator
[];
299 RANDOM_ACCESS_ITERATOR_METHODS
(Xapian
, ESetIterator
, std
::string
, get_term
)
301 %include
<xapian
/eset.h
>
303 STANDARD_IGNORES
(Xapian
, RSet
)
305 %include
<xapian
/rset.h
>
307 SUBCLASSABLE
(Xapian
, MatchDecider
)
309 %include
<xapian
/matchdecider.h
>
311 STANDARD_IGNORES
(Xapian
, Enquire
)
313 #ifdef XAPIAN_TERMITERATOR_PAIR_OUTPUT_TYPEMAP
314 /* Instantiating the template we're going to use avoids SWIG wrapping uses
315 * of it in SwigValueWrapper.
317 %template
() std
::pair
<Xapian
::TermIterator
, Xapian
::TermIterator
>;
319 %extend Xapian
::Enquire
{
320 /* This returns start and end iterators
, then a typemap iterates between
321 * those and returns an array of strings in the target language.
323 std
::pair
<Xapian
::TermIterator
, Xapian
::TermIterator
>
324 get_matching_terms
(const Xapian
::MSetIterator
& item) const {
325 return std
::make_pair
($self-
>get_matching_terms_begin
(item
),
326 $self-
>get_matching_terms_end
(item
));
331 %include
<xapian
/enquire.h
>
333 SUBCLASSABLE
(Xapian
, ExpandDecider
)
334 // Suppress warning that Xapian
::Internal
::opt_intrusive_base is unknown.
335 %warnfilter
(SWIGWARN_TYPE_UNDEFINED_CLASS
) Xapian
::ExpandDecider
;
336 %ignore Xapian
::ExpandDeciderAnd
::ExpandDeciderAnd
(const ExpandDecider
*, const ExpandDecider
*);
337 /* FIXME
: %extend ExpandDeciderFilterTerms so it can be constructed from an
338 * array of strings
(or whatever the equivalent is in the target language
).
340 %ignore Xapian
::ExpandDeciderFilterTerms
;
341 %include
<xapian
/expanddecider.h
>
343 SUBCLASSABLE
(Xapian
, KeyMaker
)
344 // Suppress warning that Xapian
::Internal
::opt_intrusive_base is unknown.
345 %warnfilter
(SWIGWARN_TYPE_UNDEFINED_CLASS
) Xapian
::KeyMaker
;
346 %include
<xapian
/keymaker.h
>
348 %extend Xapian
::SimpleStopper
{
349 /** Load stop words from a text file
(one word per line
).
*/
350 SimpleStopper
(const std
::string
&file) {
351 ifstream in_file
(file.c_str
());
352 if
(!in_file.is_open
())
353 throw Xapian
::InvalidArgumentError
("Stopword file not found: " + file
);
354 istream_iterator
<std
::string
> in_iter
(in_file
);
355 istream_iterator
<std
::string
> eof
;
356 return new Xapian
::SimpleStopper
(in_iter
, eof
);
360 SUBCLASSABLE
(Xapian
, FieldProcessor
)
361 // Suppress warning that Xapian
::Internal
::opt_intrusive_base is unknown.
362 %warnfilter
(SWIGWARN_TYPE_UNDEFINED_CLASS
) Xapian
::Stopper
;
363 SUBCLASSABLE
(Xapian
, RangeProcessor
)
364 SUBCLASSABLE
(Xapian
, Stopper
)
365 SUBCLASSABLE
(Xapian
, ValueRangeProcessor
)
366 // Suppress warning that Xapian
::Internal
::opt_intrusive_base is unknown.
367 %warnfilter
(SWIGWARN_TYPE_UNDEFINED_CLASS
) Xapian
::RangeProcessor
;
368 %warnfilter
(SWIGWARN_TYPE_UNDEFINED_CLASS
) Xapian
::ValueRangeProcessor
;
369 %warnfilter
(SWIGWARN_TYPE_UNDEFINED_CLASS
) Xapian
::FieldProcessor
;
370 STANDARD_IGNORES
(Xapian
, QueryParser
)
371 %ignore Xapian
::QueryParser
::QueryParser
(const QueryParser
&);
372 CONSTANT
(int
, Xapian
, RP_SUFFIX
);
373 CONSTANT
(int
, Xapian
, RP_REPEATED
);
374 CONSTANT
(int
, Xapian
, RP_DATE_PREFER_MDY
);
375 %include
<xapian
/queryparser.h
>
377 %include
<xapian
/valuesetmatchdecider.h
>
379 /* Xapian
::Weight isn't usefully subclassable via the bindings
, as clone
()
380 * needs to be implemented for it to be usable for weighting a search. But
381 * there are several supplied weighting schemes implemented in C
++ which can
382 * usefully be used via the bindings so we wrap those.
384 STANDARD_IGNORES
(Xapian
, Weight
)
385 /* The copy constructor isn't implemented
, but is protected rather than
386 * private to work around a compiler bug
, so we ignore it explicitly.
388 %ignore Xapian
::Weight
::Weight
(const Weight
&);
389 %ignore Xapian
::Weight
::clone
;
390 %ignore Xapian
::Weight
::serialise
;
391 %ignore Xapian
::Weight
::unserialise
;
392 %include
<xapian
/weight.h
>
394 /* We don't wrap Xapian's Unicode support as other languages usually already
395 * have their own Unicode support.
*/
396 /* %include
<xapian
/unicode.h
> */
398 SUBCLASSABLE
(Xapian
, Compactor
)
399 %include
<xapian
/compactor.h
>
401 SUBCLASSABLE
(Xapian
, PostingSource
)
402 // Suppress warning that Xapian
::Internal
::opt_intrusive_base is unknown.
403 %warnfilter
(SWIGWARN_TYPE_UNDEFINED_CLASS
) Xapian
::PostingSource
;
404 SUBCLASSABLE
(Xapian
, ValuePostingSource
)
405 SUBCLASSABLE
(Xapian
, ValueWeightPostingSource
)
406 %ignore Xapian
::PostingSource
::unserialise_with_registry
;
407 %include
<xapian
/postingsource.h
>
409 // Suppress warning that Xapian
::Internal
::intrusive_base is unknown.
410 %warnfilter
(SWIGWARN_TYPE_UNDEFINED_CLASS
) Xapian
::MatchSpy
;
411 SUBCLASSABLE
(Xapian
, MatchSpy
)
412 %ignore Xapian
::MatchSpy
::serialise_results
;
413 %include
<xapian
/matchspy.h
>
415 SUBCLASSABLE
(Xapian
, LatLongMetric
)
416 INPUT_ITERATOR_METHODS
(Xapian
, LatLongCoordsIterator
, LatLongCoord
, get_coord
)
417 %ignore Xapian
::LatLongCoord
::operator
<;
418 %include
<xapian
/geospatial.h
>
420 STANDARD_IGNORES
(Xapian
, Database
)
421 STANDARD_IGNORES
(Xapian
, WritableDatabase
)
422 %ignore Xapian
::WritableDatabase
::WritableDatabase
(Database
::Internal
*);
423 %ignore Xapian
::Database
::check
(const std
::string
&, int, std::ostream *);
424 %ignore Xapian
::Database
::check
(int fd
, int
, std
::ostream
*);
425 %include
<xapian
/database.h
>
426 %extend Xapian
::Database
{
427 static size_t check
(const std
::string
&path, int opts = 0) {
428 return Xapian
::Database
::check
(path
, opts
, opts ?
&std::cout : NULL);
432 #if defined SWIGCSHARP || defined SWIGJAVA
434 /* C# and Java don't allow functions outside a class so we can't use SWIG's
435 * %nspace feature here. Instead we pretend to SWIG that the C
++
436 * Xapian
::Remote namespace is actually a Xapian
::Remote class with public
437 * static functions. The code SWIG generates will work fine
, and we get
438 * xapian.Remote.open
() in Java and Xapian.Remote.open
() in C#.
444 // Private constructor and destructor so SWIG doesn't try to call them.
448 static Database open
(const std
::string
&host,
450 unsigned timeout
= 10000,
451 unsigned connect_timeout
= 10000);
453 static WritableDatabase open_writable
(const std
::string
&host,
455 unsigned timeout
= 0,
456 unsigned connect_timeout
= 10000,
459 static Database open
(const std
::string
&program,
460 const std
::string
&args,
461 unsigned timeout
= 10000);
463 static WritableDatabase open_writable
(const std
::string
&program,
464 const std
::string
&args,
465 unsigned timeout
= 0,
473 %rename
("remote_open") Xapian
::Remote
::open
;
474 %rename
("remote_open_writable") Xapian
::Remote
::open_writable
;
476 %include
<xapian
/dbfactory.h
>