Wrap new constant to fix python testsuite
[xapian.git] / xapian-bindings / xapian-headers.i
bloba69a1c90f992ae948ef1c7c808f1b3d936e81f9a
1 %{
2 /* xapian-headers.i: Getting SWIG to parse Xapian's C++ headers.
4 * Copyright 2004,2006,2011,2012,2013,2014,2015,2016 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 RANDOM_ACCESS_ITERATOR_METHODS(NS, CLASS, RET_TYPE, DEREF_METHOD)
100 INPUT_ITERATOR_METHODS(NS, CLASS, RET_TYPE, DEREF_METHOD)
101 %ignore NS::CLASS::operator--;
102 %ignore NS::CLASS::operator+=;
103 %ignore NS::CLASS::operator-=;
104 %ignore NS::CLASS::operator+;
105 %ignore NS::CLASS::operator-;
106 %extend NS::CLASS {
107 INC_OR_DEC(prev, --, NS, CLASS, RET_TYPE)
109 %enddef
111 %define CONSTANT(TYPE, NS, NAME)
112 %ignore NS::NAME;
113 %constant TYPE NAME = NS::NAME;
114 %enddef
116 /* Ignore these for all classes: */
117 %ignore operator==;
118 %ignore operator!=;
119 %ignore operator<;
120 %ignore operator>;
121 %ignore operator<=;
122 %ignore operator>=;
123 %ignore operator+;
124 %ignore difference_type;
125 %ignore iterator_category;
126 %ignore value_type;
127 %ignore max_size;
128 %ignore swap;
129 %ignore iterator;
130 %ignore const_iterator;
131 %ignore size_type;
132 %ignore unserialise(const char **, const char *);
133 %ignore release();
135 /* These methods won't throw exceptions. */
136 %exception Xapian::major_version "$action"
137 %exception Xapian::minor_version "$action"
138 %exception Xapian::revision "$action"
139 %exception Xapian::version_string "$action"
140 // For XAPIAN_DOCID_BASE_TYPE and XAPIAN_TERMCOUNT_BASE_TYPE:
141 %import <xapian/version.h>
142 %include <xapian.h>
144 // Disable errors about not including headers individually.
145 #define XAPIAN_IN_XAPIAN_H
147 /* We don't wrap the version macros - they're useful for compile time checks
148 * in C++ code, but for a scripting language, the version functions tell us
149 * the version of Xapian we're actually using, which is more interesting than
150 * the one the bindings were built against.
152 /* %include <xapian/version.h> */
154 /* Types are needed by most of the other headers. */
155 %include <xapian/types.h>
157 CONSTANT(int, Xapian, DB_CREATE);
158 CONSTANT(int, Xapian, DB_CREATE_OR_OPEN);
159 CONSTANT(int, Xapian, DB_CREATE_OR_OVERWRITE);
160 CONSTANT(int, Xapian, DB_OPEN);
161 CONSTANT(int, Xapian, DB_NO_SYNC);
162 CONSTANT(int, Xapian, DB_FULL_SYNC);
163 CONSTANT(int, Xapian, DB_DANGEROUS);
164 CONSTANT(int, Xapian, DB_NO_TERMLIST);
165 CONSTANT(int, Xapian, DB_BACKEND_CHERT);
166 CONSTANT(int, Xapian, DB_BACKEND_GLASS);
167 CONSTANT(int, Xapian, DB_BACKEND_INMEMORY);
168 CONSTANT(int, Xapian, DB_BACKEND_STUB);
169 CONSTANT(int, Xapian, DB_RETRY_LOCK);
170 CONSTANT(int, Xapian, DBCHECK_SHORT_TREE);
171 CONSTANT(int, Xapian, DBCHECK_FULL_TREE);
172 CONSTANT(int, Xapian, DBCHECK_SHOW_FREELIST);
173 CONSTANT(int, Xapian, DBCHECK_SHOW_STATS);
174 CONSTANT(int, Xapian, DBCHECK_FIX);
175 CONSTANT(int, Xapian, DBCOMPACT_MULTIPASS);
176 CONSTANT(int, Xapian, DBCOMPACT_NO_RENUMBER);
177 CONSTANT(int, Xapian, DBCOMPACT_SINGLE_FILE);
178 CONSTANT(int, Xapian, DOC_ASSUME_VALID);
179 %include <xapian/constants.h>
181 /* The Error subclasses are handled separately for languages where we wrap
182 * them. */
183 /* %include <xapian/error.h> */
185 /* ErrorHandler isn't currently wrapped. */
186 /* %include <xapian/errorhandler.h> */
188 INPUT_ITERATOR_METHODS(Xapian, PositionIterator, Xapian::termpos, get_termpos)
189 %include <xapian/positioniterator.h>
191 %ignore Xapian::DocIDWrapper;
192 INPUT_ITERATOR_METHODS(Xapian, PostingIterator, Xapian::docid, get_docid)
193 %include <xapian/postingiterator.h>
195 INPUT_ITERATOR_METHODS(Xapian, TermIterator, std::string, get_term)
196 %include <xapian/termiterator.h>
198 INPUT_ITERATOR_METHODS(Xapian, ValueIterator, std::string, get_value)
199 %include <xapian/valueiterator.h>
201 STANDARD_IGNORES(Xapian, Document)
202 %include <xapian/document.h>
204 STANDARD_IGNORES(Xapian, Registry)
205 %include <xapian/registry.h>
207 STANDARD_IGNORES(Xapian, Query)
208 %ignore Xapian::Query::Internal;
209 %ignore Xapian::InvertedQuery_;
210 %ignore operator Query;
211 %ignore *::operator&(const Xapian::Query &, const Xapian::InvertedQuery_ &);
212 %ignore *::operator~;
213 %ignore *::operator&=;
214 %ignore *::operator|=;
215 %ignore *::operator^=;
216 %ignore *::operator*=;
217 %ignore *::operator/=;
218 #if defined SWIGCSHARP || defined SWIGJAVA || defined SWIGLUA || defined SWIGPHP
219 %ignore *::operator&;
220 %ignore *::operator|;
221 %ignore *::operator^;
222 %ignore *::operator*;
223 %ignore *::operator/;
224 #endif
225 %ignore Xapian::Query::LEAF_TERM;
226 %ignore Xapian::Query::LEAF_POSTING_SOURCE;
227 %ignore Xapian::Query::LEAF_MATCH_ALL;
228 %ignore Xapian::Query::LEAF_MATCH_NOTHING;
230 %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::Query::Internal;
231 #if defined SWIGCSHARP || defined SWIGJAVA || defined SWIGPERL || \
232 defined SWIGPYTHON || defined SWIGRUBY
233 // C#, Java, Perl, Python and Ruby wrap these "by hand" to give a nicer API
234 // than SWIG gives by default.
235 %ignore Xapian::Query::MatchAll;
236 %ignore Xapian::Query::MatchNothing;
237 #endif
238 #ifndef XAPIAN_MIXED_SUBQUERIES_BY_ITERATOR_TYPEMAP
239 %ignore Query(op op_, XapianSWIGQueryItor qbegin, XapianSWIGQueryItor qend,
240 Xapian::termcount parameter = 0);
241 #endif
242 %include <xapian/query.h>
244 // Suppress warning that Xapian::Internal::intrusive_base is unknown.
245 %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::StemImplementation;
246 SUBCLASSABLE_ONLY(Xapian, StemImplementation)
247 #ifndef XAPIAN_SWIG_DIRECTORS
248 %ignore Xapian::Stem::Stem(Xapian::StemImplementation *);
249 #endif
250 STANDARD_IGNORES(Xapian, Stem)
251 %ignore Xapian::Stem::Stem();
252 %include <xapian/stem.h>
254 STANDARD_IGNORES(Xapian, TermGenerator)
255 %ignore Xapian::TermGenerator::operator=;
256 /* Ignore forms which use Utf8Iterator, as we don't wrap that class. */
257 %ignore Xapian::TermGenerator::index_text(const Xapian::Utf8Iterator &);
258 %ignore Xapian::TermGenerator::index_text(const Xapian::Utf8Iterator &, Xapian::termcount);
259 %ignore Xapian::TermGenerator::index_text(const Xapian::Utf8Iterator &, Xapian::termcount, const std::string &);
260 %ignore Xapian::TermGenerator::index_text_without_positions(const Xapian::Utf8Iterator &);
261 %ignore Xapian::TermGenerator::index_text_without_positions(const Xapian::Utf8Iterator &, Xapian::termcount);
262 %ignore Xapian::TermGenerator::index_text_without_positions(const Xapian::Utf8Iterator &, Xapian::termcount, const std::string &);
263 %ignore Xapian::TermGenerator::TermGenerator(const TermGenerator &);
264 %include <xapian/termgenerator.h>
266 STANDARD_IGNORES(Xapian, MSet)
267 #ifdef SWIGJAVA
268 // For compatibility with the original JNI wrappers.
269 %rename("getElement") Xapian::MSet::operator[];
270 #else
271 %ignore Xapian::MSet::operator[];
272 #endif
273 %extend Xapian::MSet {
274 Xapian::docid get_docid(Xapian::doccount i) const {
275 return *(*self)[i];
278 Xapian::Document get_document(Xapian::doccount i) const {
279 return (*self)[i].get_document();
282 Xapian::MSetIterator get_hit(Xapian::doccount i) const {
283 return (*self)[i];
286 Xapian::percent get_document_percentage(Xapian::doccount i) const {
287 return self->convert_to_percent((*self)[i]);
291 RANDOM_ACCESS_ITERATOR_METHODS(Xapian, MSetIterator, Xapian::docid, get_docid)
293 %include <xapian/mset.h>
295 STANDARD_IGNORES(Xapian, ESet)
296 %ignore Xapian::ESet::operator[];
298 RANDOM_ACCESS_ITERATOR_METHODS(Xapian, ESetIterator, std::string, get_term)
300 %include <xapian/eset.h>
302 STANDARD_IGNORES(Xapian, RSet)
304 STANDARD_IGNORES(Xapian, Enquire)
306 SUBCLASSABLE(Xapian, MatchDecider)
308 #ifdef XAPIAN_TERMITERATOR_PAIR_OUTPUT_TYPEMAP
309 /* Instantiating the template we're going to use avoids SWIG wrapping uses
310 * of it in SwigValueWrapper.
312 %template() std::pair<Xapian::TermIterator, Xapian::TermIterator>;
314 %extend Xapian::Enquire {
315 /* This returns start and end iterators, then a typemap iterates between
316 * those and returns an array of strings in the target language.
318 std::pair<Xapian::TermIterator, Xapian::TermIterator>
319 get_matching_terms(const Xapian::MSetIterator & item) const {
320 return std::make_pair($self->get_matching_terms_begin(item),
321 $self->get_matching_terms_end(item));
324 #endif
326 /* We don't wrap ErrorHandler, so ignore the optional ErrorHandler parameter.
328 %ignore Enquire(const Database &, ErrorHandler *);
330 %include <xapian/enquire.h>
332 SUBCLASSABLE(Xapian, ExpandDecider)
333 // Suppress warning that Xapian::Internal::opt_intrusive_base is unknown.
334 %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::ExpandDecider;
335 %ignore Xapian::ExpandDeciderAnd::ExpandDeciderAnd(const ExpandDecider *, const ExpandDecider *);
336 /* FIXME: %extend ExpandDeciderFilterTerms so it can be constructed from an
337 * array of strings (or whatever the equivalent is in the target language).
339 %ignore Xapian::ExpandDeciderFilterTerms;
340 %include <xapian/expanddecider.h>
342 SUBCLASSABLE(Xapian, KeyMaker)
343 // Suppress warning that Xapian::Internal::opt_intrusive_base is unknown.
344 %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::KeyMaker;
345 %include <xapian/keymaker.h>
347 %extend Xapian::SimpleStopper {
348 /** Load stop words from a text file (one word per line). */
349 SimpleStopper(const std::string &file) {
350 ifstream in_file(file.c_str());
351 if (!in_file.is_open())
352 throw Xapian::InvalidArgumentError("Stopword file not found: " + file);
353 istream_iterator<std::string> in_iter(in_file);
354 istream_iterator<std::string> eof;
355 return new Xapian::SimpleStopper(in_iter, eof);
359 SUBCLASSABLE(Xapian, FieldProcessor)
360 // Suppress warning that Xapian::Internal::opt_intrusive_base is unknown.
361 %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::Stopper;
362 SUBCLASSABLE(Xapian, RangeProcessor)
363 SUBCLASSABLE(Xapian, Stopper)
364 SUBCLASSABLE(Xapian, ValueRangeProcessor)
365 // Suppress warning that Xapian::Internal::opt_intrusive_base is unknown.
366 %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::RangeProcessor;
367 %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::ValueRangeProcessor;
368 %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::FieldProcessor;
369 STANDARD_IGNORES(Xapian, QueryParser)
370 %ignore Xapian::QueryParser::QueryParser(const QueryParser &);
371 CONSTANT(int, Xapian, RP_SUFFIX);
372 CONSTANT(int, Xapian, RP_REPEATED);
373 CONSTANT(int, Xapian, RP_DATE_PREFER_MDY);
374 %include <xapian/queryparser.h>
376 %include <xapian/valuesetmatchdecider.h>
378 /* Xapian::Weight isn't usefully subclassable via the bindings, as clone()
379 * needs to be implemented for it to be usable for weighting a search. But
380 * there are several supplied weighting schemes implemented in C++ which can
381 * usefully be used via the bindings so we wrap those.
383 STANDARD_IGNORES(Xapian, Weight)
384 /* The copy constructor isn't implemented, but is protected rather than
385 * private to work around a compiler bug, so we ignore it explicitly.
387 %ignore Xapian::Weight::Weight(const Weight &);
388 %ignore Xapian::Weight::clone;
389 %ignore Xapian::Weight::clone_;
390 %ignore Xapian::Weight::init_;
391 %ignore Xapian::Weight::get_sumpart_needs_doclength_;
392 %ignore Xapian::Weight::get_sumpart_needs_uniqueterms_;
393 %ignore Xapian::Weight::get_sumpart_needs_wdf_;
394 %ignore Xapian::Weight::serialise;
395 %ignore Xapian::Weight::unserialise;
396 %include <xapian/weight.h>
398 /* We don't wrap Xapian's Unicode support as other languages usually already
399 * have their own Unicode support. */
400 /* %include <xapian/unicode.h> */
402 SUBCLASSABLE(Xapian, Compactor)
403 %include <xapian/compactor.h>
405 SUBCLASSABLE(Xapian, PostingSource)
406 // Suppress warning that Xapian::Internal::opt_intrusive_base is unknown.
407 %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::PostingSource;
408 SUBCLASSABLE(Xapian, ValuePostingSource)
409 SUBCLASSABLE(Xapian, ValueWeightPostingSource)
410 %ignore Xapian::PostingSource::register_matcher_;
411 %ignore Xapian::PostingSource::unserialise_with_registry;
412 %include <xapian/postingsource.h>
414 // Suppress warning that Xapian::Internal::intrusive_base is unknown.
415 %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::MatchSpy;
416 SUBCLASSABLE(Xapian, MatchSpy)
417 %ignore Xapian::MatchSpy::serialise_results;
418 %include <xapian/matchspy.h>
420 SUBCLASSABLE(Xapian, LatLongMetric)
421 INPUT_ITERATOR_METHODS(Xapian, LatLongCoordsIterator, LatLongCoord, get_coord)
422 %ignore Xapian::LatLongCoord::operator<;
423 %include <xapian/geospatial.h>
425 STANDARD_IGNORES(Xapian, Database)
426 STANDARD_IGNORES(Xapian, WritableDatabase)
427 %ignore Xapian::WritableDatabase::WritableDatabase(Database::Internal *);
428 %ignore Xapian::Database::get_document_lazily_;
429 %ignore Xapian::Database::check(const std::string &, int, std::ostream *);
430 %ignore Xapian::Database::check(int fd, int, std::ostream *);
431 %include <xapian/database.h>
432 %extend Xapian::Database {
433 static size_t check(const std::string &path, int opts = 0) {
434 return Xapian::Database::check(path, opts, opts ? &std::cout : NULL);
438 #if defined SWIGCSHARP || defined SWIGJAVA
440 /* xapian/dbfactory.h is currently wrapped via fake class declarations in
441 * fake_dbfactory.i for C# and Java. */
443 #else
445 #ifdef XAPIAN_BINDINGS_SKIP_DEPRECATED_DB_FACTORIES
446 %ignore Xapian::InMemory::open;
447 %ignore Xapian::Auto::open_stub;
448 #else
450 %rename("inmemory_open") Xapian::InMemory::open;
452 #ifndef SWIGPHP
453 /* PHP renames this to auto_open_stub() in php/php.i. */
454 %rename("open_stub") Xapian::Auto::open_stub;
455 #endif
457 #endif
459 %rename("remote_open") Xapian::Remote::open;
460 %rename("remote_open_writable") Xapian::Remote::open_writable;
462 %include <xapian/dbfactory.h>
464 #endif