2 /* xapian-headers.i
: Getting SWIG to parse Xapian's C
++ headers.
4 * Copyright
2004,2006,2011,2012,2013,2014,2015,2016,2019,2020 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
=;
59 %define STANDARD_IGNORES
(NS
, CLASS
)
60 %ignore NS
::CLASS
::internal
;
61 %ignore NS
::CLASS
::CLASS
(Internal
*);
62 %ignore NS
::CLASS
::CLASS
(Internal
&);
63 %ignore NS
::CLASS
::operator
=;
64 %ignore NS
::CLASS
::CLASS
(const CLASS
&);
69 /* In C#
, next and prev return the iterator object.
*/
70 #define INC_OR_DEC
(METHOD
, OP
, NS
, CLASS
, RET_TYPE
) NS
::CLASS METHOD
() { return OP
(*self
); }
71 #elif defined SWIGJAVA
72 /* In Java
, next and prev return the result of dereferencing the iterator.
*/
73 #define INC_OR_DEC
(METHOD
, OP
, NS
, CLASS
, RET_TYPE
) RET_TYPE METHOD
() { return
*(OP
(*self
)); }
75 /* Otherwise
, next and prev return void.
*/
76 #define INC_OR_DEC
(METHOD
, OP
, NS
, CLASS
, RET_TYPE
) void METHOD
() { OP
(*self
); }
80 /* In Perl
, use inc
() and dec
() instead of next
() and prev
().
*/
81 #define NEXT_METHOD inc
82 #define PREV_METHOD dec
83 #define OPERATOR_EQ
(NS
, CLASS
) bool equal
(const NS
::CLASS
& o) const { return *self == o; }
84 #define OPERATOR_NE
(NS
, CLASS
) bool nequal
(const NS
::CLASS
& o) const { return *self != o; }
86 #define NEXT_METHOD next
87 #define PREV_METHOD prev
88 #define OPERATOR_EQ
(NS
, CLASS
) bool equals
(const NS
::CLASS
& o) const { return *self == o; }
89 #define OPERATOR_NE
(NS
, CLASS
)
92 /* For other languages
, SWIG already renames operator
() suitably.
*/
93 #if defined SWIGJAVA || defined SWIGPHP || defined SWIGTCL
94 %rename
(apply
) *::operator
();
95 #elif defined SWIGCSHARP
96 %rename
(Apply
) *::operator
();
99 /* We use
%ignore and
%extend rather than
%rename on operator
* so that any
100 * pattern rename used to match local naming conventions applies to
103 %define INPUT_ITERATOR_METHODS
(NS
, CLASS
, RET_TYPE
, DEREF_METHOD
)
104 STANDARD_IGNORES
(NS
, CLASS
)
105 %ignore NS
::CLASS
::operator
++;
106 %ignore NS
::CLASS
::operator
*;
108 OPERATOR_EQ
(NS
, CLASS
)
109 OPERATOR_NE
(NS
, CLASS
)
110 RET_TYPE DEREF_METHOD
() const
{ return
**self
; }
111 INC_OR_DEC
(NEXT_METHOD
, ++, NS
, CLASS
, RET_TYPE
)
115 %define RANDOM_ACCESS_ITERATOR_METHODS
(NS
, CLASS
, RET_TYPE
, DEREF_METHOD
)
116 INPUT_ITERATOR_METHODS
(NS
, CLASS
, RET_TYPE
, DEREF_METHOD
)
117 %ignore NS
::CLASS
::operator--
;
118 %ignore NS
::CLASS
::operator
+=;
119 %ignore NS
::CLASS
::operator-
=;
120 %ignore NS
::CLASS
::operator
+;
121 %ignore NS
::CLASS
::operator-
;
123 INC_OR_DEC
(PREV_METHOD
, --, NS
, CLASS
, RET_TYPE
)
127 %define CONSTANT
(TYPE, NS
, NAME)
129 %constant
TYPE NAME = NS
::NAME;
132 /* Ignore these for all classes
: */
140 %ignore difference_type
;
141 %ignore iterator_category
;
146 %ignore const_iterator
;
148 %ignore unserialise
(const char
**, const char
*);
151 /* These methods won't throw exceptions.
*/
152 %exception Xapian
::major_version
"$action"
153 %exception Xapian
::minor_version
"$action"
154 %exception Xapian
::revision
"$action"
155 %exception Xapian
::version_string
"$action"
156 // For XAPIAN_DOCID_BASE_TYPE and XAPIAN_TERMCOUNT_BASE_TYPE
:
157 %import
<xapian
/version.h
>
160 // Disable errors about not including headers individually.
161 #define XAPIAN_IN_XAPIAN_H
163 /* We don't wrap the version macros
- they're useful for compile time checks
164 * in C
++ code
, but for a scripting language
, the version functions tell us
165 * the version of Xapian we're actually using
, which is more interesting than
166 * the one the bindings were built against.
168 /* %include
<xapian
/version.h
> */
170 CONSTANT
(Xapian
::valueno
, Xapian
, BAD_VALUENO
);
172 /* Types are needed by most of the other headers.
*/
173 %include
<xapian
/types.h
>
175 CONSTANT
(int
, Xapian
, DB_CREATE
);
176 CONSTANT
(int
, Xapian
, DB_CREATE_OR_OPEN
);
177 CONSTANT
(int
, Xapian
, DB_CREATE_OR_OVERWRITE
);
178 CONSTANT
(int
, Xapian
, DB_OPEN
);
179 CONSTANT
(int
, Xapian
, DB_NO_SYNC
);
180 CONSTANT
(int
, Xapian
, DB_FULL_SYNC
);
181 CONSTANT
(int
, Xapian
, DB_DANGEROUS
);
182 CONSTANT
(int
, Xapian
, DB_NO_TERMLIST
);
183 CONSTANT
(int
, Xapian
, DB_BACKEND_CHERT
);
184 CONSTANT
(int
, Xapian
, DB_BACKEND_GLASS
);
185 CONSTANT
(int
, Xapian
, DB_BACKEND_INMEMORY
);
186 CONSTANT
(int
, Xapian
, DB_BACKEND_STUB
);
187 CONSTANT
(int
, Xapian
, DB_RETRY_LOCK
);
188 CONSTANT
(int
, Xapian
, DBCHECK_SHORT_TREE
);
189 CONSTANT
(int
, Xapian
, DBCHECK_FULL_TREE
);
190 CONSTANT
(int
, Xapian
, DBCHECK_SHOW_FREELIST
);
191 CONSTANT
(int
, Xapian
, DBCHECK_SHOW_STATS
);
192 CONSTANT
(int
, Xapian
, DBCHECK_FIX
);
193 CONSTANT
(int
, Xapian
, DBCOMPACT_MULTIPASS
);
194 CONSTANT
(int
, Xapian
, DBCOMPACT_NO_RENUMBER
);
195 CONSTANT
(int
, Xapian
, DBCOMPACT_SINGLE_FILE
);
196 CONSTANT
(int
, Xapian
, DOC_ASSUME_VALID
);
197 %include
<xapian
/constants.h
>
199 /* The Error subclasses are handled separately for languages where we wrap
201 /* %include
<xapian
/error.h
> */
203 /* ErrorHandler isn't currently wrapped.
*/
204 /* %include
<xapian
/errorhandler.h
> */
206 INPUT_ITERATOR_METHODS
(Xapian
, PositionIterator
, Xapian
::termpos
, get_termpos
)
207 %include
<xapian
/positioniterator.h
>
209 %ignore Xapian
::DocIDWrapper
;
210 INPUT_ITERATOR_METHODS
(Xapian
, PostingIterator
, Xapian
::docid
, get_docid
)
211 %include
<xapian
/postingiterator.h
>
213 INPUT_ITERATOR_METHODS
(Xapian
, TermIterator
, std
::string
, get_term
)
214 %include
<xapian
/termiterator.h
>
216 INPUT_ITERATOR_METHODS
(Xapian
, ValueIterator
, std
::string
, get_value
)
217 %include
<xapian
/valueiterator.h
>
219 STANDARD_IGNORES
(Xapian
, Document
)
220 %include
<xapian
/document.h
>
222 STANDARD_IGNORES
(Xapian
, Registry
)
223 %include
<xapian
/registry.h
>
225 STANDARD_IGNORES
(Xapian
, Query
)
226 %ignore Xapian
::Query
::Internal
;
227 %ignore operator Query
;
228 %ignore
*::operator
&(const Xapian::Query &, const Xapian::InvertedQuery_ &);
229 %ignore
*::operator~
;
230 %ignore
*::operator
&=;
231 %ignore
::operator
&=;
232 %ignore
*::operator|
=;
233 %ignore
*::operator^
=;
234 %ignore
*::operator
*=;
235 %ignore
*::operator
/=;
236 %ignore
*::operator
&;
237 %ignore
*::operator|
;
238 %ignore
*::operator^
;
239 %ignore
*::operator
*;
240 %ignore
*::operator
/;
241 %ignore Xapian
::Query
::LEAF_TERM
;
242 %ignore Xapian
::Query
::LEAF_POSTING_SOURCE
;
243 %ignore Xapian
::Query
::LEAF_MATCH_ALL
;
244 %ignore Xapian
::Query
::LEAF_MATCH_NOTHING
;
246 %warnfilter
(SWIGWARN_TYPE_UNDEFINED_CLASS
) Xapian
::Query
::Internal
;
247 #if defined SWIGCSHARP || defined SWIGJAVA || defined SWIGPERL || \
248 defined SWIGPYTHON || defined SWIGRUBY
249 // C#
, Java
, Perl
, Python and Ruby wrap these
"by hand" to give a nicer API
250 // than SWIG gives by default.
251 %ignore Xapian
::Query
::MatchAll
;
252 %ignore Xapian
::Query
::MatchNothing
;
254 #ifndef XAPIAN_MIXED_SUBQUERIES_BY_ITERATOR_TYPEMAP
255 %ignore Query
(op op_
, XapianSWIGQueryItor qbegin
, XapianSWIGQueryItor qend
,
256 Xapian
::termcount parameter
= 0);
258 %include
<xapian
/query.h
>
260 // Suppress warning that Xapian
::Internal
::intrusive_base is unknown.
261 %warnfilter
(SWIGWARN_TYPE_UNDEFINED_CLASS
) Xapian
::StemImplementation
;
262 SUBCLASSABLE_ONLY
(Xapian
, StemImplementation
)
263 #ifndef XAPIAN_SWIG_DIRECTORS
264 %ignore Xapian
::Stem
::Stem
(Xapian
::StemImplementation
*);
266 STANDARD_IGNORES
(Xapian
, Stem
)
267 %ignore Xapian
::Stem
::Stem
();
268 %include
<xapian
/stem.h
>
270 STANDARD_IGNORES
(Xapian
, TermGenerator
)
271 %ignore Xapian
::TermGenerator
::operator
=;
272 /* Ignore forms which use Utf8Iterator
, as we don't wrap that class.
*/
273 %ignore Xapian
::TermGenerator
::index_text
(const Xapian
::Utf8Iterator
&);
274 %ignore Xapian
::TermGenerator
::index_text
(const Xapian
::Utf8Iterator
&, Xapian::termcount);
275 %ignore Xapian
::TermGenerator
::index_text
(const Xapian
::Utf8Iterator
&, Xapian::termcount, const std::string &);
276 %ignore Xapian
::TermGenerator
::index_text_without_positions
(const Xapian
::Utf8Iterator
&);
277 %ignore Xapian
::TermGenerator
::index_text_without_positions
(const Xapian
::Utf8Iterator
&, Xapian::termcount);
278 %ignore Xapian
::TermGenerator
::index_text_without_positions
(const Xapian
::Utf8Iterator
&, Xapian::termcount, const std::string &);
279 %ignore Xapian
::TermGenerator
::TermGenerator
(const TermGenerator
&);
280 %include
<xapian
/termgenerator.h
>
282 STANDARD_IGNORES
(Xapian
, MSet
)
284 // For compatibility with the original JNI wrappers.
285 %rename
("getElement") Xapian
::MSet
::operator
[];
287 %ignore Xapian
::MSet
::operator
[];
289 %extend Xapian
::MSet
{
290 Xapian
::docid get_docid
(Xapian
::doccount i
) const
{
294 Xapian
::Document get_document
(Xapian
::doccount i
) const
{
295 return
(*self
)[i
].get_document
();
298 Xapian
::MSetIterator get_hit
(Xapian
::doccount i
) const
{
302 int get_document_percentage
(Xapian
::doccount i
) const
{
303 return self-
>convert_to_percent
((*self
)[i
]);
307 RANDOM_ACCESS_ITERATOR_METHODS
(Xapian
, MSetIterator
, Xapian
::docid
, get_docid
)
309 %include
<xapian
/mset.h
>
311 STANDARD_IGNORES
(Xapian
, ESet
)
312 %ignore Xapian
::ESet
::operator
[];
314 RANDOM_ACCESS_ITERATOR_METHODS
(Xapian
, ESetIterator
, std
::string
, get_term
)
316 %include
<xapian
/eset.h
>
318 STANDARD_IGNORES
(Xapian
, RSet
)
320 STANDARD_IGNORES
(Xapian
, Enquire
)
322 SUBCLASSABLE
(Xapian
, MatchDecider
)
324 #ifdef XAPIAN_TERMITERATOR_PAIR_OUTPUT_TYPEMAP
325 /* Instantiating the template we're going to use avoids SWIG wrapping uses
326 * of it in SwigValueWrapper.
328 %template
() std
::pair
<Xapian
::TermIterator
, Xapian
::TermIterator
>;
330 %extend Xapian
::Enquire
{
331 /* This returns start and end iterators
, then a typemap iterates between
332 * those and returns an array of strings in the target language.
334 std
::pair
<Xapian
::TermIterator
, Xapian
::TermIterator
>
335 get_matching_terms
(const Xapian
::MSetIterator
& item) const {
336 return std
::make_pair
($self-
>get_matching_terms_begin
(item
),
337 $self-
>get_matching_terms_end
(item
));
342 /* We don't wrap ErrorHandler
, so ignore the optional ErrorHandler parameter.
344 %ignore Enquire
(const Database
&, ErrorHandler *);
346 %include
<xapian
/enquire.h
>
348 SUBCLASSABLE
(Xapian
, ExpandDecider
)
349 // Suppress warning that Xapian
::Internal
::opt_intrusive_base is unknown.
350 %warnfilter
(SWIGWARN_TYPE_UNDEFINED_CLASS
) Xapian
::ExpandDecider
;
351 %ignore Xapian
::ExpandDeciderAnd
::ExpandDeciderAnd
(const ExpandDecider
*, const ExpandDecider
*);
352 /* FIXME
: %extend ExpandDeciderFilterTerms so it can be constructed from an
353 * array of strings
(or whatever the equivalent is in the target language
).
355 %ignore Xapian
::ExpandDeciderFilterTerms
;
356 %include
<xapian
/expanddecider.h
>
358 SUBCLASSABLE
(Xapian
, KeyMaker
)
359 // Suppress warning that Xapian
::Internal
::opt_intrusive_base is unknown.
360 %warnfilter
(SWIGWARN_TYPE_UNDEFINED_CLASS
) Xapian
::KeyMaker
;
361 %include
<xapian
/keymaker.h
>
363 %extend Xapian
::SimpleStopper
{
364 /** Load stop words from a text file
(one word per line
).
*/
365 SimpleStopper
(const std
::string
&file) {
366 ifstream in_file
(file.c_str
());
367 if
(!in_file.is_open
())
368 throw Xapian
::InvalidArgumentError
("Stopword file not found: " + file
);
369 istream_iterator
<std
::string
> in_iter
(in_file
);
370 istream_iterator
<std
::string
> eof
;
371 return new Xapian
::SimpleStopper
(in_iter
, eof
);
375 SUBCLASSABLE
(Xapian
, FieldProcessor
)
376 // Suppress warning that Xapian
::Internal
::opt_intrusive_base is unknown.
377 %warnfilter
(SWIGWARN_TYPE_UNDEFINED_CLASS
) Xapian
::Stopper
;
378 SUBCLASSABLE
(Xapian
, RangeProcessor
)
379 SUBCLASSABLE
(Xapian
, Stopper
)
380 SUBCLASSABLE
(Xapian
, ValueRangeProcessor
)
381 // Suppress warning that Xapian
::Internal
::opt_intrusive_base is unknown.
382 %warnfilter
(SWIGWARN_TYPE_UNDEFINED_CLASS
) Xapian
::RangeProcessor
;
383 %warnfilter
(SWIGWARN_TYPE_UNDEFINED_CLASS
) Xapian
::ValueRangeProcessor
;
384 %warnfilter
(SWIGWARN_TYPE_UNDEFINED_CLASS
) Xapian
::FieldProcessor
;
385 STANDARD_IGNORES
(Xapian
, QueryParser
)
386 %ignore Xapian
::QueryParser
::QueryParser
(const QueryParser
&);
387 CONSTANT
(int
, Xapian
, RP_SUFFIX
);
388 CONSTANT
(int
, Xapian
, RP_REPEATED
);
389 CONSTANT
(int
, Xapian
, RP_DATE_PREFER_MDY
);
390 %include
<xapian
/queryparser.h
>
392 %include
<xapian
/valuesetmatchdecider.h
>
394 /* Xapian
::Weight isn't usefully subclassable via the bindings
, as clone
()
395 * needs to be implemented for it to be usable for weighting a search. But
396 * there are several supplied weighting schemes implemented in C
++ which can
397 * usefully be used via the bindings so we wrap those.
399 STANDARD_IGNORES
(Xapian
, Weight
)
400 /* The copy constructor isn't implemented
, but is protected rather than
401 * private to work around a compiler bug
, so we ignore it explicitly.
403 %ignore Xapian
::Weight
::Weight
(const Weight
&);
404 %ignore Xapian
::Weight
::clone
;
405 %ignore Xapian
::Weight
::serialise
;
406 %ignore Xapian
::Weight
::unserialise
;
407 %include
<xapian
/weight.h
>
409 /* We don't wrap Xapian's Unicode support as other languages usually already
410 * have their own Unicode support.
*/
411 /* %include
<xapian
/unicode.h
> */
413 SUBCLASSABLE
(Xapian
, Compactor
)
414 %include
<xapian
/compactor.h
>
416 SUBCLASSABLE
(Xapian
, PostingSource
)
417 // Suppress warning that Xapian
::Internal
::opt_intrusive_base is unknown.
418 %warnfilter
(SWIGWARN_TYPE_UNDEFINED_CLASS
) Xapian
::PostingSource
;
419 SUBCLASSABLE
(Xapian
, ValuePostingSource
)
420 SUBCLASSABLE
(Xapian
, ValueWeightPostingSource
)
421 %ignore Xapian
::PostingSource
::unserialise_with_registry
;
422 %include
<xapian
/postingsource.h
>
424 // Suppress warning that Xapian
::Internal
::intrusive_base is unknown.
425 %warnfilter
(SWIGWARN_TYPE_UNDEFINED_CLASS
) Xapian
::MatchSpy
;
426 SUBCLASSABLE
(Xapian
, MatchSpy
)
427 %ignore Xapian
::MatchSpy
::serialise_results
;
428 %include
<xapian
/matchspy.h
>
430 SUBCLASSABLE
(Xapian
, LatLongMetric
)
431 INPUT_ITERATOR_METHODS
(Xapian
, LatLongCoordsIterator
, LatLongCoord
, get_coord
)
432 %ignore Xapian
::LatLongCoord
::operator
<;
433 %include
<xapian
/geospatial.h
>
435 STANDARD_IGNORES
(Xapian
, Database
)
436 STANDARD_IGNORES
(Xapian
, WritableDatabase
)
437 %ignore Xapian
::WritableDatabase
::WritableDatabase
(Database
::Internal
*);
438 %ignore Xapian
::Database
::check
(const std
::string
&, int, std::ostream *);
439 %ignore Xapian
::Database
::check
(int fd
, int
, std
::ostream
*);
440 %include
<xapian
/database.h
>
441 %extend Xapian
::Database
{
442 static size_t check
(const std
::string
&path, int opts = 0) {
443 return Xapian
::Database
::check
(path
, opts
, opts ?
&std::cout : NULL);
447 #if defined SWIGCSHARP || defined SWIGJAVA
449 /* xapian
/dbfactory.h is currently wrapped via fake class declarations in
450 * fake_dbfactory.i for C# and Java.
*/
454 #ifdef XAPIAN_BINDINGS_SKIP_DEPRECATED_DB_FACTORIES
455 %ignore Xapian
::InMemory
::open
;
456 %ignore Xapian
::Chert
::open
;
457 %ignore Xapian
::Auto
::open_stub
;
460 %rename
("inmemory_open") Xapian
::InMemory
::open
;
462 /* SWIG Tcl wrappers don't call destructors for classes returned by factory
463 * functions
, so we don't wrap them so users are forced to use the
464 * WritableDatabase ctor instead.
*/
466 %ignore Xapian
::Chert
::open
(const std
::string
&dir, int action, int block_size = 8192);
469 %rename
("chert_open") Xapian
::Chert
::open
;
472 /* PHP renames this to auto_open_stub
() in php
/php.i.
*/
473 %rename
("open_stub") Xapian
::Auto
::open_stub
;
478 %rename
("remote_open") Xapian
::Remote
::open
;
479 %rename
("remote_open_writable") Xapian
::Remote
::open_writable
;
481 %include
<xapian
/dbfactory.h
>