Support: quest -f cjk_ngram
[xapian.git] / xapian-bindings / xapian-headers.i
blob4258f250f59b2393b162595296b9e23841c92b7b
1 %{
2 /* xapian-headers.i: Getting SWIG to parse Xapian's C++ headers.
4 * Copyright 2004,2006,2011,2012,2013,2014,2015 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
20 * USA
24 /* Ignore these functions: */
25 %ignore Xapian::iterator_rewind;
26 %ignore Xapian::iterator_valid;
27 %ignore Xapian::sortable_serialise_;
29 /* A class which can usefully be subclassed in the target language. */
30 %define SUBCLASSABLE(NS, CLASS)
31 %ignore NS::CLASS::clone;
32 %ignore NS::CLASS::serialise;
33 %ignore NS::CLASS::unserialise;
34 %#ifdef XAPIAN_SWIG_DIRECTORS
35 %feature(director) NS::CLASS;
36 %#endif
37 %enddef
39 /* A class which is only useful to wrap if the target language allows
40 * subclassing of wrapped classes (what SWIG calls "director support").
42 #ifdef XAPIAN_SWIG_DIRECTORS
43 #define SUBCLASSABLE_ONLY(NS, CLASS) SUBCLASSABLE(NS, CLASS)
44 #else
45 #define SUBCLASSABLE_ONLY(NS, CLASS) %ignore NS::CLASS;
46 #endif
48 #ifdef SWIGTCL
49 /* Tcl needs copy constructors it seems. */
50 %define STANDARD_IGNORES(NS, CLASS)
51 %ignore NS::CLASS::internal;
52 %ignore NS::CLASS::CLASS(Internal*);
53 %ignore NS::CLASS::CLASS(Internal&);
54 %ignore NS::CLASS::operator=;
55 %enddef
56 #else
57 %define STANDARD_IGNORES(NS, CLASS)
58 %ignore NS::CLASS::internal;
59 %ignore NS::CLASS::CLASS(Internal*);
60 %ignore NS::CLASS::CLASS(Internal&);
61 %ignore NS::CLASS::operator=;
62 %ignore NS::CLASS::CLASS(const CLASS &);
63 %enddef
64 #endif
66 #ifdef SWIGCSHARP
67 /* In C#, next and prev return the iterator object. */
68 #define INC_OR_DEC(METHOD, OP, NS, CLASS, RET_TYPE) NS::CLASS METHOD() { return OP(*self); }
69 #elif defined SWIGJAVA
70 /* In Java, next and prev return the result of dereferencing the iterator. */
71 #define INC_OR_DEC(METHOD, OP, NS, CLASS, RET_TYPE) RET_TYPE METHOD() { return *(OP(*self)); }
72 #else
73 /* Otherwise, next and prev return void. */
74 #define INC_OR_DEC(METHOD, OP, NS, CLASS, RET_TYPE) void METHOD() { OP(*self); }
75 #endif
77 /* For other languages, SWIG already renames operator() suitably. */
78 #if defined SWIGJAVA || defined SWIGPHP || defined SWIGTCL
79 %rename(apply) *::operator();
80 #elif defined SWIGCSHARP
81 %rename(Apply) *::operator();
82 #endif
84 /* We use %ignore and %extend rather than %rename on operator* so that any
85 * pattern rename used to match local naming conventions applies to
86 * DEREF_METHOD.
88 %define INPUT_ITERATOR_METHODS(NS, CLASS, RET_TYPE, DEREF_METHOD)
89 STANDARD_IGNORES(NS, CLASS)
90 %ignore NS::CLASS::operator++;
91 %ignore NS::CLASS::operator*;
92 %extend NS::CLASS {
93 bool equals(const NS::CLASS & o) const { return *self == o; }
94 RET_TYPE DEREF_METHOD() const { return **self; }
95 INC_OR_DEC(next, ++, NS, CLASS, RET_TYPE)
97 %enddef
99 %define BIDIRECTIONAL_ITERATOR_METHODS(NS, CLASS, RET_TYPE, DEREF_METHOD)
100 INPUT_ITERATOR_METHODS(NS, CLASS, RET_TYPE, DEREF_METHOD)
101 %ignore NS::CLASS::operator--;
102 %extend NS::CLASS {
103 INC_OR_DEC(prev, --, NS, CLASS, RET_TYPE)
105 %enddef
107 %define CONSTANT(TYPE, NS, NAME)
108 %ignore NS::NAME;
109 %constant TYPE NAME = NS::NAME;
110 %enddef
112 /* Ignore these for all classes: */
113 %ignore operator==;
114 %ignore operator!=;
115 %ignore difference_type;
116 %ignore iterator_category;
117 %ignore value_type;
118 %ignore max_size;
119 %ignore swap;
120 %ignore iterator;
121 %ignore const_iterator;
122 %ignore size_type;
123 %ignore unserialise(const char **, const char *);
124 %ignore release();
126 /* These methods won't throw exceptions. */
127 %exception Xapian::major_version "$action"
128 %exception Xapian::minor_version "$action"
129 %exception Xapian::revision "$action"
130 %exception Xapian::version_string "$action"
131 // For XAPIAN_DOCID_BASE_TYPE and XAPIAN_TERMCOUNT_BASE_TYPE:
132 %import <xapian/version.h>
133 %include <xapian.h>
135 // Disable errors about not including headers individually.
136 #define XAPIAN_IN_XAPIAN_H
138 /* We don't wrap the version macros - they're useful for compile time checks
139 * in C++ code, but for a scripting language, the version functions tell us
140 * the version of Xapian we're actually using, which is more interesting than
141 * the one the bindings were built against.
143 /* %include <xapian/version.h> */
145 /* Types are needed by most of the other headers. */
146 %include <xapian/types.h>
148 CONSTANT(int, Xapian, DB_CREATE);
149 CONSTANT(int, Xapian, DB_CREATE_OR_OPEN);
150 CONSTANT(int, Xapian, DB_CREATE_OR_OVERWRITE);
151 CONSTANT(int, Xapian, DB_OPEN);
152 CONSTANT(int, Xapian, DB_NO_SYNC);
153 CONSTANT(int, Xapian, DB_FULL_SYNC);
154 CONSTANT(int, Xapian, DB_DANGEROUS);
155 CONSTANT(int, Xapian, DB_NO_TERMLIST);
156 CONSTANT(int, Xapian, DB_BACKEND_CHERT);
157 CONSTANT(int, Xapian, DB_BACKEND_GLASS);
158 CONSTANT(int, Xapian, DB_BACKEND_STUB);
159 CONSTANT(int, Xapian, DB_RETRY_LOCK);
160 CONSTANT(int, Xapian, DBCHECK_SHORT_TREE);
161 CONSTANT(int, Xapian, DBCHECK_FULL_TREE);
162 CONSTANT(int, Xapian, DBCHECK_SHOW_FREELIST);
163 CONSTANT(int, Xapian, DBCHECK_SHOW_BITMAP);
164 CONSTANT(int, Xapian, DBCHECK_SHOW_STATS);
165 CONSTANT(int, Xapian, DBCHECK_FIX);
166 %include <xapian/constants.h>
168 /* The Error subclasses are handled separately for languages where we wrap
169 * them. */
170 /* %include <xapian/error.h> */
172 /* ErrorHandler isn't currently wrapped. */
173 /* %include <xapian/errorhandler.h> */
175 INPUT_ITERATOR_METHODS(Xapian, PositionIterator, Xapian::termpos, get_termpos)
176 %include <xapian/positioniterator.h>
178 %ignore Xapian::DocIDWrapper;
179 INPUT_ITERATOR_METHODS(Xapian, PostingIterator, Xapian::docid, get_docid)
180 %include <xapian/postingiterator.h>
182 INPUT_ITERATOR_METHODS(Xapian, TermIterator, std::string, get_term)
183 %include <xapian/termiterator.h>
185 INPUT_ITERATOR_METHODS(Xapian, ValueIterator, std::string, get_value)
186 %include <xapian/valueiterator.h>
188 STANDARD_IGNORES(Xapian, Document)
189 %include <xapian/document.h>
191 STANDARD_IGNORES(Xapian, Registry)
192 %include <xapian/registry.h>
194 STANDARD_IGNORES(Xapian, Query)
195 %ignore Xapian::Query::Internal;
196 %ignore Xapian::InvertedQuery_;
197 %ignore operator Query;
198 %ignore *::operator&(const Xapian::Query &, const Xapian::InvertedQuery_ &);
199 %ignore *::operator~;
200 %ignore *::operator&=;
201 %ignore *::operator|=;
202 %ignore *::operator^=;
203 %ignore *::operator*=;
204 %ignore *::operator/=;
205 #if defined SWIGCSHARP || defined SWIGJAVA || defined SWIGLUA || defined SWIGPHP
206 %ignore *::operator&;
207 %ignore *::operator|;
208 %ignore *::operator^;
209 %ignore *::operator*;
210 %ignore *::operator/;
211 #endif
212 %ignore Xapian::Query::LEAF_TERM;
213 %ignore Xapian::Query::LEAF_POSTING_SOURCE;
214 %ignore Xapian::Query::LEAF_MATCH_ALL;
215 %ignore Xapian::Query::LEAF_MATCH_NOTHING;
217 %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::Query::Internal;
218 #if defined SWIGCSHARP || defined SWIGJAVA || defined SWIGPERL || \
219 defined SWIGPYTHON || defined SWIGRUBY
220 // C#, Java, Perl, Python and Ruby wrap these "by hand" to give a nicer API
221 // than SWIG gives by default.
222 %ignore Xapian::Query::MatchAll;
223 %ignore Xapian::Query::MatchNothing;
224 #endif
225 #ifndef XAPIAN_MIXED_SUBQUERIES_BY_ITERATOR_TYPEMAP
226 %ignore Query(op op_, XapianSWIGQueryItor qbegin, XapianSWIGQueryItor qend,
227 Xapian::termcount parameter = 0);
228 #endif
229 %include <xapian/query.h>
231 // Suppress warning that Xapian::Internal::intrusive_base is unknown.
232 %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::StemImplementation;
233 SUBCLASSABLE_ONLY(Xapian, StemImplementation)
234 #ifndef XAPIAN_SWIG_DIRECTORS
235 %ignore Xapian::Stem::Stem(Xapian::StemImplementation *);
236 #endif
237 STANDARD_IGNORES(Xapian, Stem)
238 %ignore Xapian::Stem::Stem();
239 %include <xapian/stem.h>
241 STANDARD_IGNORES(Xapian, TermGenerator)
242 %ignore Xapian::TermGenerator::operator=;
243 /* Ignore forms which use Utf8Iterator, as we don't wrap that class. */
244 %ignore Xapian::TermGenerator::index_text(const Xapian::Utf8Iterator &);
245 %ignore Xapian::TermGenerator::index_text(const Xapian::Utf8Iterator &, Xapian::termcount);
246 %ignore Xapian::TermGenerator::index_text(const Xapian::Utf8Iterator &, Xapian::termcount, const std::string &);
247 %ignore Xapian::TermGenerator::index_text_without_positions(const Xapian::Utf8Iterator &);
248 %ignore Xapian::TermGenerator::index_text_without_positions(const Xapian::Utf8Iterator &, Xapian::termcount);
249 %ignore Xapian::TermGenerator::index_text_without_positions(const Xapian::Utf8Iterator &, Xapian::termcount, const std::string &);
250 %ignore Xapian::TermGenerator::TermGenerator(const TermGenerator &);
251 %include <xapian/termgenerator.h>
253 STANDARD_IGNORES(Xapian, MSet)
254 #ifdef SWIGJAVA
255 // For compatibility with the original JNI wrappers.
256 %rename("getElement") Xapian::MSet::operator[];
257 #else
258 %ignore Xapian::MSet::operator[];
259 #endif
260 %extend Xapian::MSet {
261 Xapian::docid get_docid(Xapian::doccount i) const {
262 return *(*self)[i];
265 Xapian::Document get_document(Xapian::doccount i) const {
266 return (*self)[i].get_document();
269 Xapian::MSetIterator get_hit(Xapian::doccount i) const {
270 return (*self)[i];
273 Xapian::percent get_document_percentage(Xapian::doccount i) const {
274 return self->convert_to_percent((*self)[i]);
277 STANDARD_IGNORES(Xapian, ESet)
278 %ignore Xapian::ESet::operator[];
279 STANDARD_IGNORES(Xapian, RSet)
281 STANDARD_IGNORES(Xapian, Enquire)
283 BIDIRECTIONAL_ITERATOR_METHODS(Xapian, MSetIterator, Xapian::docid, get_docid)
284 BIDIRECTIONAL_ITERATOR_METHODS(Xapian, ESetIterator, std::string, get_term)
286 SUBCLASSABLE(Xapian, MatchDecider)
288 #ifdef XAPIAN_TERMITERATOR_PAIR_OUTPUT_TYPEMAP
289 /* Instantiating the template we're going to use avoids SWIG wrapping uses
290 * of it in SwigValueWrapper.
292 %template() std::pair<Xapian::TermIterator, Xapian::TermIterator>;
294 %extend Xapian::Enquire {
295 /* This returns start and end iterators, then a typemap iterates between
296 * those and returns an array of strings in the target language.
298 std::pair<Xapian::TermIterator, Xapian::TermIterator>
299 get_matching_terms(const Xapian::MSetIterator & item) const {
300 return std::make_pair($self->get_matching_terms_begin(item),
301 $self->get_matching_terms_end(item));
304 #endif
306 /* We don't wrap ErrorHandler, so ignore the optional ErrorHandler parameter.
308 %ignore Enquire(const Database &, ErrorHandler *);
310 %include <xapian/enquire.h>
312 SUBCLASSABLE(Xapian, ExpandDecider)
313 %ignore Xapian::ExpandDeciderAnd::ExpandDeciderAnd(const ExpandDecider *, const ExpandDecider *);
314 /* FIXME: %extend ExpandDeciderFilterTerms so it can be constructed from an
315 * array of strings (or whatever the equivalent is in the target language).
317 %ignore Xapian::ExpandDeciderFilterTerms;
318 %include <xapian/expanddecider.h>
320 SUBCLASSABLE(Xapian, KeyMaker)
321 %include <xapian/keymaker.h>
323 %extend Xapian::SimpleStopper {
324 /** Load stop words from a text file (one word per line). */
325 SimpleStopper(const std::string &file) {
326 ifstream in_file(file.c_str());
327 if (!in_file.is_open())
328 throw Xapian::InvalidArgumentError("Stopword file not found: " + file);
329 istream_iterator<std::string> in_iter(in_file);
330 istream_iterator<std::string> eof;
331 return new Xapian::SimpleStopper(in_iter, eof);
335 SUBCLASSABLE(Xapian, FieldProcessor)
336 SUBCLASSABLE(Xapian, Stopper)
337 SUBCLASSABLE(Xapian, ValueRangeProcessor)
338 // Suppress warning that Xapian::Internal::opt_intrusive_base is unknown.
339 %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::ValueRangeProcessor;
340 %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::FieldProcessor;
341 STANDARD_IGNORES(Xapian, QueryParser)
342 %ignore Xapian::QueryParser::QueryParser(const QueryParser &);
343 %include <xapian/queryparser.h>
345 %include <xapian/valuesetmatchdecider.h>
347 /* Xapian::Weight isn't usefully subclassable via the bindings, as clone()
348 * needs to be implemented for it to be usable for weighting a search. But
349 * there are several supplied weighting schemes implemented in C++ which can
350 * usefully be used via the bindings so we wrap those.
352 STANDARD_IGNORES(Xapian, Weight)
353 /* The copy constructor isn't implemented, but is protected rather than
354 * private to work around a compiler bug, so we ignore it explicitly.
356 %ignore Xapian::Weight::Weight(const Weight &);
357 %ignore Xapian::Weight::clone;
358 %ignore Xapian::Weight::clone_;
359 %ignore Xapian::Weight::init_;
360 %ignore Xapian::Weight::get_sumpart_needs_doclength_;
361 %ignore Xapian::Weight::get_sumpart_needs_uniqueterms_;
362 %ignore Xapian::Weight::get_sumpart_needs_wdf_;
363 %ignore Xapian::Weight::serialise;
364 %ignore Xapian::Weight::unserialise;
365 %include <xapian/weight.h>
367 /* We don't wrap Xapian's Unicode support as other languages usually already
368 * have their own Unicode support. */
369 /* %include <xapian/unicode.h> */
371 SUBCLASSABLE(Xapian, Compactor)
372 %include <xapian/compactor.h>
374 SUBCLASSABLE(Xapian, PostingSource)
375 %ignore Xapian::PostingSource::register_matcher_;
376 %ignore Xapian::PostingSource::unserialise_with_registry;
377 %include <xapian/postingsource.h>
379 // Suppress warning that Xapian::Internal::intrusive_base is unknown.
380 %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::MatchSpy;
381 SUBCLASSABLE(Xapian, MatchSpy)
382 %ignore Xapian::MatchSpy::serialise_results;
383 %include <xapian/matchspy.h>
385 SUBCLASSABLE(Xapian, LatLongMetric)
386 INPUT_ITERATOR_METHODS(Xapian, LatLongCoordsIterator, LatLongCoord, get_coord)
387 %ignore Xapian::LatLongCoord::operator<;
388 %include <xapian/geospatial.h>
390 STANDARD_IGNORES(Xapian, Database)
391 STANDARD_IGNORES(Xapian, WritableDatabase)
392 %ignore Xapian::WritableDatabase::WritableDatabase(Database::Internal *);
393 %ignore Xapian::Database::get_document_lazily_;
394 %ignore Xapian::Database::check(const std::string &, int, std::ostream *);
395 %ignore Xapian::Database::check(int fd, int, std::ostream *);
396 %include <xapian/database.h>
397 %extend Xapian::Database {
398 static size_t check(const std::string &path, int opts = 0) {
399 return Xapian::Database::check(path, opts, opts ? &std::cout : NULL);
403 STANDARD_IGNORES(Xapian, Snipper)
404 %include <xapian/snipper.h>
406 #if defined SWIGCSHARP || defined SWIGJAVA
408 /* xapian/dbfactory.h is currently wrapped via fake class declarations in
409 * fake_dbfactory.i for C# and Java. */
411 #else
413 %rename("inmemory_open") Xapian::InMemory::open;
415 #ifdef XAPIAN_BINDINGS_SKIP_DEPRECATED_DB_FACTORIES
416 %ignore Xapian::Chert::open;
417 %ignore Xapian::Auto::open_stub;
418 #else
420 /* SWIG Tcl wrappers don't call destructors for classes returned by factory
421 * functions, so we don't wrap them so users are forced to use the
422 * WritableDatabase ctor instead. */
423 #ifdef SWIGTCL
424 %ignore Xapian::Chert::open(const std::string &dir, int action, int block_size = 8192);
425 #endif
427 %rename("chert_open") Xapian::Chert::open;
429 #ifndef SWIGPHP
430 /* PHP renames this to auto_open_stub() in php/php.i. */
431 %rename("open_stub") Xapian::Auto::open_stub;
432 #endif
434 #endif
436 %rename("remote_open") Xapian::Remote::open;
437 %rename("remote_open_writable") Xapian::Remote::open_writable;
439 %include <xapian/dbfactory.h>
441 #endif