1 %{ 2 /* xapian-headers.i: Getting SWIG to parse Xapian's C++ headers. 3 * 4 * Copyright 2004,2006,2011,2012,2013,2014,2015,2016,2019,2020 Olly Betts 5 * Copyright 2014 Assem Chelli 6 * 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. 11 * 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. 16 * 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 21 */ 22 %} 23 24 /* Ignore these functions: */ 25 %ignore Xapian::iterator_rewind; 26 %ignore Xapian::iterator_valid; 27 28 /* Ignore anything ending in an underscore, which is for internal use only: */ 29 %rename("$ignore", regexmatch$name="_$") ""; 30 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; 38 %#endif 39 %enddef 40 41 /* A class which is only useful to wrap if the target language allows 42 * subclassing of wrapped classes (what SWIG calls "director support"). 43 */ 44 #ifdef XAPIAN_SWIG_DIRECTORS 45 #define SUBCLASSABLE_ONLY(NS, CLASS) SUBCLASSABLE(NS, CLASS) 46 #else 47 #define SUBCLASSABLE_ONLY(NS, CLASS) %ignore NS::CLASS; 48 #endif 49 50 #ifdef SWIGTCL 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 %enddef 58 #else 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 &); 65 %enddef 66 #endif 67 68 #ifdef SWIGCSHARP 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)); } 74 #else 75 /* Otherwise, next and prev return void. */ 76 #define INC_OR_DEC(METHOD, OP, NS, CLASS, RET_TYPE) void METHOD() { OP(*self); } 77 #endif 78 79 #ifdef SWIGPERL 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; } 85 #else 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) 90 #endif 91 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(); 97 #endif 98 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 101 * DEREF_METHOD. 102 */ 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*; 107 %extend NS::CLASS { OPERATOR_EQ(NS,CLASS)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) 112 } 113 %enddef 114 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-; 122 %extend NS::CLASS { 123 INC_OR_DEC(PREV_METHOD, --, NS, CLASS, RET_TYPE) 124 } 125 %enddef 126 127 %define CONSTANT(TYPE, NS, NAME) 128 %ignore NS::NAME; 129 %constant TYPE NAME = NS::NAME; 130 %enddef 131 132 /* Ignore these for all classes: */ 133 %ignore operator==; 134 %ignore operator!=; 135 %ignore operator<; 136 %ignore operator>; 137 %ignore operator<=; 138 %ignore operator>=; 139 %ignore operator+; 140 %ignore difference_type; 141 %ignore iterator_category; 142 %ignore value_type; 143 %ignore max_size; 144 %ignore swap; 145 %ignore iterator; 146 %ignore const_iterator; 147 %ignore size_type; 148 %ignore unserialise(const char **, const char *); 149 %ignore release(); 150 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> 158 %include <xapian.h> 159 160 // Disable errors about not including headers individually. 161 #define XAPIAN_IN_XAPIAN_H 162 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. 167 */ 168 /* %include <xapian/version.h> */ 169 170 CONSTANT(Xapian::valueno, Xapian, BAD_VALUENO); 171 172 /* Types are needed by most of the other headers. */ 173 %include <xapian/types.h> 174 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> 198 199 /* The Error subclasses are handled separately for languages where we wrap 200 * them. */ 201 /* %include <xapian/error.h> */ 202 203 /* ErrorHandler isn't currently wrapped. */ 204 /* %include <xapian/errorhandler.h> */ 205 206 INPUT_ITERATOR_METHODS(Xapian, PositionIterator, Xapian::termpos, get_termpos) 207 %include <xapian/positioniterator.h> 208 209 %ignore Xapian::DocIDWrapper; 210 INPUT_ITERATOR_METHODS(Xapian, PostingIterator, Xapian::docid, get_docid) 211 %include <xapian/postingiterator.h> 212 213 INPUT_ITERATOR_METHODS(Xapian, TermIterator, std::string, get_term) 214 %include <xapian/termiterator.h> 215 216 INPUT_ITERATOR_METHODS(Xapian, ValueIterator, std::string, get_value) 217 %include <xapian/valueiterator.h> 218 219 STANDARD_IGNORES(Xapian, Document) 220 %include <xapian/document.h> 221 222 STANDARD_IGNORES(Xapian, Registry) 223 %include <xapian/registry.h> 224 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; 245 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; 253 #endif 254 #ifndef XAPIAN_MIXED_SUBQUERIES_BY_ITERATOR_TYPEMAP 255 %ignore Query(op op_, XapianSWIGQueryItor qbegin, XapianSWIGQueryItor qend, 256 Xapian::termcount parameter = 0); 257 #endif 258 %include <xapian/query.h> 259 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 *); 265 #endif 266 STANDARD_IGNORES(Xapian, Stem) 267 %ignore Xapian::Stem::Stem(); 268 %include <xapian/stem.h> 269 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> 281 282 STANDARD_IGNORES(Xapian, MSet) 283 #ifdef SWIGJAVA 284 // For compatibility with the original JNI wrappers. 285 %rename("getElement") Xapian::MSet::operator[]; 286 #else 287 %ignore Xapian::MSet::operator[]; 288 #endif 289 %extend Xapian::MSet { get_docid(Xapian::doccount i)290 Xapian::docid get_docid(Xapian::doccount i) const { 291 return *(*self)[i]; 292 } 293 get_document(Xapian::doccount i)294 Xapian::Document get_document(Xapian::doccount i) const { 295 return (*self)[i].get_document(); 296 } 297 get_hit(Xapian::doccount i)298 Xapian::MSetIterator get_hit(Xapian::doccount i) const { 299 return (*self)[i]; 300 } 301 get_document_percentage(Xapian::doccount i)302 int get_document_percentage(Xapian::doccount i) const { 303 return self->convert_to_percent((*self)[i]); 304 } 305 } 306 307 RANDOM_ACCESS_ITERATOR_METHODS(Xapian, MSetIterator, Xapian::docid, get_docid) 308 309 %include <xapian/mset.h> 310 311 STANDARD_IGNORES(Xapian, ESet) 312 %ignore Xapian::ESet::operator[]; 313 314 RANDOM_ACCESS_ITERATOR_METHODS(Xapian, ESetIterator, std::string, get_term) 315 316 %include <xapian/eset.h> 317 318 STANDARD_IGNORES(Xapian, RSet) 319 320 STANDARD_IGNORES(Xapian, Enquire) 321 322 SUBCLASSABLE(Xapian, MatchDecider) 323 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. 327 */ 328 %template() std::pair<Xapian::TermIterator, Xapian::TermIterator>; 329 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. 333 */ 334 std::pair<Xapian::TermIterator, Xapian::TermIterator> get_matching_terms(const Xapian::MSetIterator & item)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)); 338 } 339 } 340 #endif 341 342 /* We don't wrap ErrorHandler, so ignore the optional ErrorHandler parameter. 343 */ 344 %ignore Enquire(const Database &, ErrorHandler *); 345 346 %include <xapian/enquire.h> 347 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). 354 */ 355 %ignore Xapian::ExpandDeciderFilterTerms; 356 %include <xapian/expanddecider.h> 357 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> 362 363 %extend Xapian::SimpleStopper { 364 /** Load stop words from a text file (one word per line). */ SimpleStopper(const std::string & file)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); 372 } 373 } 374 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> 391 392 %include <xapian/valuesetmatchdecider.h> 393 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. 398 */ 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. 402 */ 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> 408 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> */ 412 413 SUBCLASSABLE(Xapian, Compactor) 414 %include <xapian/compactor.h> 415 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> 423 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> 429 430 SUBCLASSABLE(Xapian, LatLongMetric) 431 INPUT_ITERATOR_METHODS(Xapian, LatLongCoordsIterator, LatLongCoord, get_coord) 432 %ignore Xapian::LatLongCoord::operator<; 433 %include <xapian/geospatial.h> 434 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); 444 } 445 } 446 447 #if defined SWIGCSHARP || defined SWIGJAVA 448 449 /* xapian/dbfactory.h is currently wrapped via fake class declarations in 450 * fake_dbfactory.i for C# and Java. */ 451 452 #else 453 454 #ifdef XAPIAN_BINDINGS_SKIP_DEPRECATED_DB_FACTORIES 455 %ignore Xapian::InMemory::open; 456 %ignore Xapian::Chert::open; 457 %ignore Xapian::Auto::open_stub; 458 #else 459 460 %rename("inmemory_open") Xapian::InMemory::open; 461 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. */ 465 #ifdef SWIGTCL 466 %ignore Xapian::Chert::open(const std::string &dir, int action, int block_size = 8192); 467 #endif 468 469 %rename("chert_open") Xapian::Chert::open; 470 471 #ifndef SWIGPHP 472 /* PHP renames this to auto_open_stub() in php/php.i. */ 473 %rename("open_stub") Xapian::Auto::open_stub; 474 #endif 475 476 #endif 477 478 %rename("remote_open") Xapian::Remote::open; 479 %rename("remote_open_writable") Xapian::Remote::open_writable; 480 481 %include <xapian/dbfactory.h> 482 483 #endif 484