omindex.cc: Fix comment typo.
[xapian.git] / xapian-bindings / xapian-headers.i
blobb3f35a98be38e4be2f3659e92cb6b9057b6ba1e6
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 %include <xapian.h>
133 // Disable errors about not including headers individually.
134 #define XAPIAN_IN_XAPIAN_H
136 /* We don't wrap the version macros - they're useful for compile time checks
137 * in C++ code, but for a scripting language, the version functions tell us
138 * the version of Xapian we're actually using, which is more interesting than
139 * the one the bindings were built against.
141 /* %include <xapian/version.h> */
143 /* Types are needed by most of the other headers. */
144 %include <xapian/types.h>
146 CONSTANT(int, Xapian, DB_CREATE);
147 CONSTANT(int, Xapian, DB_CREATE_OR_OPEN);
148 CONSTANT(int, Xapian, DB_CREATE_OR_OVERWRITE);
149 CONSTANT(int, Xapian, DB_OPEN);
150 CONSTANT(int, Xapian, DB_NO_SYNC);
151 CONSTANT(int, Xapian, DB_FULL_SYNC);
152 CONSTANT(int, Xapian, DB_DANGEROUS);
153 CONSTANT(int, Xapian, DB_NO_TERMLIST);
154 CONSTANT(int, Xapian, DB_BACKEND_CHERT);
155 CONSTANT(int, Xapian, DB_BACKEND_GLASS);
156 CONSTANT(int, Xapian, DB_BACKEND_STUB);
157 CONSTANT(int, Xapian, DB_RETRY_LOCK);
158 CONSTANT(int, Xapian, DBCHECK_SHORT_TREE);
159 CONSTANT(int, Xapian, DBCHECK_FULL_TREE);
160 CONSTANT(int, Xapian, DBCHECK_SHOW_FREELIST);
161 CONSTANT(int, Xapian, DBCHECK_SHOW_BITMAP);
162 CONSTANT(int, Xapian, DBCHECK_SHOW_STATS);
163 CONSTANT(int, Xapian, DBCHECK_FIX);
164 %include <xapian/constants.h>
166 /* The Error subclasses are handled separately for languages where we wrap
167 * them. */
168 /* %include <xapian/error.h> */
170 /* ErrorHandler isn't currently wrapped. */
171 /* %include <xapian/errorhandler.h> */
173 INPUT_ITERATOR_METHODS(Xapian, PositionIterator, Xapian::termpos, get_termpos)
174 %include <xapian/positioniterator.h>
176 %ignore Xapian::DocIDWrapper;
177 INPUT_ITERATOR_METHODS(Xapian, PostingIterator, Xapian::docid, get_docid)
178 %include <xapian/postingiterator.h>
180 INPUT_ITERATOR_METHODS(Xapian, TermIterator, std::string, get_term)
181 %include <xapian/termiterator.h>
183 INPUT_ITERATOR_METHODS(Xapian, ValueIterator, std::string, get_value)
184 %include <xapian/valueiterator.h>
186 STANDARD_IGNORES(Xapian, Document)
187 %include <xapian/document.h>
189 STANDARD_IGNORES(Xapian, Registry)
190 %include <xapian/registry.h>
192 STANDARD_IGNORES(Xapian, Query)
193 %ignore Xapian::Query::Internal;
194 %ignore Xapian::InvertedQuery_;
195 %ignore operator Query;
196 %ignore *::operator&(const Xapian::Query &, const Xapian::InvertedQuery_ &);
197 %ignore *::operator~;
198 %ignore *::operator&=;
199 %ignore *::operator|=;
200 %ignore *::operator^=;
201 %ignore *::operator*=;
202 %ignore *::operator/=;
203 #if defined SWIGCSHARP || defined SWIGJAVA || defined SWIGLUA || defined SWIGPHP
204 %ignore *::operator&;
205 %ignore *::operator|;
206 %ignore *::operator^;
207 %ignore *::operator*;
208 %ignore *::operator/;
209 #endif
210 %ignore Xapian::Query::LEAF_TERM;
211 %ignore Xapian::Query::LEAF_POSTING_SOURCE;
212 %ignore Xapian::Query::LEAF_MATCH_ALL;
213 %ignore Xapian::Query::LEAF_MATCH_NOTHING;
215 %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::Query::Internal;
216 #if defined SWIGCSHARP || defined SWIGJAVA || defined SWIGPERL || \
217 defined SWIGPYTHON || defined SWIGRUBY
218 // C#, Java, Perl, Python and Ruby wrap these "by hand" to give a nicer API
219 // than SWIG gives by default.
220 %ignore Xapian::Query::MatchAll;
221 %ignore Xapian::Query::MatchNothing;
222 #endif
223 #ifndef XAPIAN_MIXED_SUBQUERIES_BY_ITERATOR_TYPEMAP
224 %ignore Query(op op_, XapianSWIGQueryItor qbegin, XapianSWIGQueryItor qend,
225 Xapian::termcount parameter = 0);
226 #endif
227 %include <xapian/query.h>
229 // Suppress warning that Xapian::Internal::intrusive_base is unknown.
230 %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::StemImplementation;
231 SUBCLASSABLE_ONLY(Xapian, StemImplementation)
232 #ifndef XAPIAN_SWIG_DIRECTORS
233 %ignore Xapian::Stem::Stem(Xapian::StemImplementation *);
234 #endif
235 STANDARD_IGNORES(Xapian, Stem)
236 %ignore Xapian::Stem::Stem();
237 %include <xapian/stem.h>
239 STANDARD_IGNORES(Xapian, TermGenerator)
240 %ignore Xapian::TermGenerator::operator=;
241 /* Ignore forms which use Utf8Iterator, as we don't wrap that class. */
242 %ignore Xapian::TermGenerator::index_text(const Xapian::Utf8Iterator &);
243 %ignore Xapian::TermGenerator::index_text(const Xapian::Utf8Iterator &, Xapian::termcount);
244 %ignore Xapian::TermGenerator::index_text(const Xapian::Utf8Iterator &, Xapian::termcount, const std::string &);
245 %ignore Xapian::TermGenerator::index_text_without_positions(const Xapian::Utf8Iterator &);
246 %ignore Xapian::TermGenerator::index_text_without_positions(const Xapian::Utf8Iterator &, Xapian::termcount);
247 %ignore Xapian::TermGenerator::index_text_without_positions(const Xapian::Utf8Iterator &, Xapian::termcount, const std::string &);
248 %ignore Xapian::TermGenerator::TermGenerator(const TermGenerator &);
249 %include <xapian/termgenerator.h>
251 STANDARD_IGNORES(Xapian, MSet)
252 #ifdef SWIGJAVA
253 // For compatibility with the original JNI wrappers.
254 %rename("getElement") Xapian::MSet::operator[];
255 #else
256 %ignore Xapian::MSet::operator[];
257 #endif
258 %extend Xapian::MSet {
259 Xapian::docid get_docid(Xapian::doccount i) const {
260 return *(*self)[i];
263 Xapian::Document get_document(Xapian::doccount i) const {
264 return (*self)[i].get_document();
267 Xapian::MSetIterator get_hit(Xapian::doccount i) const {
268 return (*self)[i];
271 Xapian::percent get_document_percentage(Xapian::doccount i) const {
272 return self->convert_to_percent((*self)[i]);
275 STANDARD_IGNORES(Xapian, ESet)
276 %ignore Xapian::ESet::operator[];
277 STANDARD_IGNORES(Xapian, RSet)
279 STANDARD_IGNORES(Xapian, Enquire)
281 BIDIRECTIONAL_ITERATOR_METHODS(Xapian, MSetIterator, Xapian::docid, get_docid)
282 BIDIRECTIONAL_ITERATOR_METHODS(Xapian, ESetIterator, std::string, get_term)
284 SUBCLASSABLE(Xapian, MatchDecider)
286 #ifdef XAPIAN_TERMITERATOR_PAIR_OUTPUT_TYPEMAP
287 /* Instantiating the template we're going to use avoids SWIG wrapping uses
288 * of it in SwigValueWrapper.
290 %template() std::pair<Xapian::TermIterator, Xapian::TermIterator>;
292 %extend Xapian::Enquire {
293 /* This returns start and end iterators, then a typemap iterates between
294 * those and returns an array of strings in the target language.
296 std::pair<Xapian::TermIterator, Xapian::TermIterator>
297 get_matching_terms(const Xapian::MSetIterator & item) const {
298 return std::make_pair($self->get_matching_terms_begin(item),
299 $self->get_matching_terms_end(item));
302 #endif
304 /* We don't wrap ErrorHandler, so ignore the optional ErrorHandler parameter.
306 %ignore Enquire(const Database &, ErrorHandler *);
308 %include <xapian/enquire.h>
310 SUBCLASSABLE(Xapian, ExpandDecider)
311 %ignore Xapian::ExpandDeciderAnd::ExpandDeciderAnd(const ExpandDecider *, const ExpandDecider *);
312 /* FIXME: %extend ExpandDeciderFilterTerms so it can be constructed from an
313 * array of strings (or whatever the equivalent is in the target language).
315 %ignore Xapian::ExpandDeciderFilterTerms;
316 %include <xapian/expanddecider.h>
318 SUBCLASSABLE(Xapian, KeyMaker)
319 %include <xapian/keymaker.h>
321 %extend Xapian::SimpleStopper {
322 /** Load stop words from a text file (one word per line). */
323 SimpleStopper(const std::string &file) {
324 ifstream in_file(file.c_str());
325 if (!in_file.is_open())
326 throw Xapian::InvalidArgumentError("Stopword file not found: " + file);
327 istream_iterator<std::string> in_iter(in_file);
328 istream_iterator<std::string> eof;
329 return new Xapian::SimpleStopper(in_iter, eof);
333 SUBCLASSABLE(Xapian, FieldProcessor)
334 SUBCLASSABLE(Xapian, Stopper)
335 SUBCLASSABLE(Xapian, ValueRangeProcessor)
336 // Suppress warning that Xapian::Internal::opt_intrusive_base is unknown.
337 %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::ValueRangeProcessor;
338 %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::FieldProcessor;
339 STANDARD_IGNORES(Xapian, QueryParser)
340 %ignore Xapian::QueryParser::QueryParser(const QueryParser &);
341 %include <xapian/queryparser.h>
343 %include <xapian/valuesetmatchdecider.h>
345 /* Xapian::Weight isn't usefully subclassable via the bindings, as clone()
346 * needs to be implemented for it to be usable for weighting a search. But
347 * there are several supplied weighting schemes implemented in C++ which can
348 * usefully be used via the bindings so we wrap those.
350 STANDARD_IGNORES(Xapian, Weight)
351 /* The copy constructor isn't implemented, but is protected rather than
352 * private to work around a compiler bug, so we ignore it explicitly.
354 %ignore Xapian::Weight::Weight(const Weight &);
355 %ignore Xapian::Weight::clone;
356 %ignore Xapian::Weight::clone_;
357 %ignore Xapian::Weight::init_;
358 %ignore Xapian::Weight::get_sumpart_needs_doclength_;
359 %ignore Xapian::Weight::get_sumpart_needs_uniqueterms_;
360 %ignore Xapian::Weight::get_sumpart_needs_wdf_;
361 %ignore Xapian::Weight::serialise;
362 %ignore Xapian::Weight::unserialise;
363 %include <xapian/weight.h>
365 /* We don't wrap Xapian's Unicode support as other languages usually already
366 * have their own Unicode support. */
367 /* %include <xapian/unicode.h> */
369 SUBCLASSABLE(Xapian, Compactor)
370 %include <xapian/compactor.h>
372 SUBCLASSABLE(Xapian, PostingSource)
373 %ignore Xapian::PostingSource::register_matcher_;
374 %ignore Xapian::PostingSource::unserialise_with_registry;
375 %include <xapian/postingsource.h>
377 // Suppress warning that Xapian::Internal::intrusive_base is unknown.
378 %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::MatchSpy;
379 SUBCLASSABLE(Xapian, MatchSpy)
380 %ignore Xapian::MatchSpy::serialise_results;
381 %include <xapian/matchspy.h>
383 SUBCLASSABLE(Xapian, LatLongMetric)
384 INPUT_ITERATOR_METHODS(Xapian, LatLongCoordsIterator, LatLongCoord, get_coord)
385 %ignore Xapian::LatLongCoord::operator<;
386 %include <xapian/geospatial.h>
388 STANDARD_IGNORES(Xapian, Database)
389 STANDARD_IGNORES(Xapian, WritableDatabase)
390 %ignore Xapian::WritableDatabase::WritableDatabase(Database::Internal *);
391 %ignore Xapian::Database::get_document_lazily_;
392 %ignore Xapian::Database::check(const std::string &, int, std::ostream *);
393 %include <xapian/database.h>
394 %extend Xapian::Database {
395 static size_t check(const std::string &path, int opts = 0) {
396 return Xapian::Database::check(path, opts, opts ? &std::cout : NULL);
400 STANDARD_IGNORES(Xapian, Snipper)
401 %include <xapian/snipper.h>
403 #if defined SWIGCSHARP || defined SWIGJAVA
405 /* xapian/dbfactory.h is currently wrapped via fake class declarations in
406 * fake_dbfactory.i for C# and Java. */
408 #else
410 #define XAPIAN_HAS_INMEMORY_BACKEND
411 %rename("inmemory_open") Xapian::InMemory::open;
413 #ifdef XAPIAN_BINDINGS_SKIP_DEPRECATED_DB_FACTORIES
414 %ignore Xapian::Chert::open;
415 %ignore Xapian::Auto::open_stub;
416 #else
418 /* SWIG Tcl wrappers don't call destructors for classes returned by factory
419 * functions, so we don't wrap them so users are forced to use the
420 * WritableDatabase ctor instead. */
421 #ifdef SWIGTCL
422 %ignore Xapian::Chert::open(const std::string &dir, int action, int block_size = 8192);
423 #endif
425 #define XAPIAN_HAS_CHERT_BACKEND
426 %rename("chert_open") Xapian::Chert::open;
428 #ifndef SWIGPHP
429 /* PHP renames this to auto_open_stub() in php/php.i. */
430 %rename("open_stub") Xapian::Auto::open_stub;
431 #endif
433 #endif
435 #define XAPIAN_HAS_REMOTE_BACKEND
436 %rename("remote_open") Xapian::Remote::open;
437 %rename("remote_open_writable") Xapian::Remote::open_writable;
439 %include <xapian/dbfactory.h>
441 #endif