namespace Xapian { int major_version(); const char * version_string(); }
>>> import xapian >>> xapian.major_version() 1 >>> xapian.version_string() '1.2.5'
Same syntax, different semantics:
void set_entry(const char * name, unsigned value);
>>> set_entry('answer', 42)
Same syntax, different semantics:
void set_entry(const char * name, unsigned value);
>>> set_entry('answer', 42)
void write_data(const char * ptr, unsigned len);
Same syntax, different semantics:
void set_entry(const char * name, unsigned value);
>>> set_entry('answer', 42)
void write_data(const char * ptr, unsigned len);
>>> write_data('hello\x00world', 11)
Same syntax, different semantics:
void set_entry(const char * name, unsigned value);
>>> set_entry('answer', 42)
void write_data(const char * ptr, unsigned len);
>>> data = 'hello\x00world' >>> write_data(data, len(data))
Same syntax, different semantics:
void set_entry(const char * name, unsigned value);
>>> set_entry('answer', 42)
void write_data(const char * ptr, unsigned len); %typemap(in) (const char * ptr, unsigned len) { $1 = PyString_AsString($input); $2 = PyString_Size($input); }
>>> write_data('hello\x00world')
namespace Xapian { class Stem { // [...] std::string get_description() const; }; }
>>> stem = xapian.Stem('en') >>> stem.get_description() 'Xapian::Stem(english)'
%rename(__str__) Xapian::Stem::get_description; namespace Xapian { class Stem { // [...] std::string get_description() const; }; }
>>> stem = xapian.Stem('en') >>> str(stem) 'Xapian::Stem(english)'
%rename(__str__) get_description; namespace Xapian { class Stem { // [...] std::string get_description() const; }; }
>>> stem = xapian.Stem('en') >>> str(stem) 'Xapian::Stem(english)'
%rename("%(regex/^mylib_//)s",$isfunction) "";
%rename("%(undercase)s",%$isfunction) ""; %rename("%(camelcase)s",%$isclass) "";
%ignore max_size;
%exception { [...] $action [...] }
%exception { try { $action } catch (std::range_error & e) { SWIG_exception(SWIG_IndexError, e.what()); } }
%exception { try { $action } catch (const Xapian::Error & e) { PyObject * o; o = SWIG_NewPointerObj(new Xapian::Error(e), SWIGTYPE_p_Xapian__Error, SWIG_POINTER_OWN); SWIG_Python_Raise(o, "Xapian::Error", SWIGTYPE_p_Xapian__Error); SWIG_fail; } }
static void SetPythonException() { try { throw; } catch (const Xapian::Error & e) { // Call SWIG_Python_Raise as before. } } %exception { try { $action } catch (...) { SetPythonException(); SWIG_fail; } }
%exception { $action if (result < 0) { SWIG_exception(SWIG_IndexError, strerror(errno)); } }
"Directors" allow wrapped classes to be subclassed, and virtual methods get routed as you'd hope.
%typemap(in) const vector<Xapian::Query> & (vector<Xapian::Query> v) { PyObject * fastseq = PySequence_Fast($input, "bad"); if (!fastseq) SWIG_fail; int num_items = PySequence_Fast_GET_SIZE(fastseq); v.reserve(num_items); for (int i = 0; i < num_items; ++i) { // Loop body on next slide... } $1 = &v; Py_DECREF(fastseq); }
PyObject *obj = PySequence_Fast_GET_ITEM(fastseq, i); if (PyString_Check(obj)) { char * p; Py_ssize_t len; (void)PyString_AsStringAndSize(obj, &p, &len); v.push_back(Xapian::Query(string(p, len))); } else { Xapian::Query *subqp = Xapian::get_py_query(obj); if (!subqp) SWIG_exception(SWIG_TypeError, "bad"); v.push_back(*subqp); }
%extend Xapian::Query { Query(Query::op op, const vector<Query> & v) { return new Xapian::Query(op, v.begin(), v.end()); } }
int decode(const char *s, int & width, int & height);
>>> decode(input) (10, 100)
i = matches.begin() while i != matches.end(): print i.get_docid() i.next()
for m in matches: print m.docid
%feature("autodoc"); %feature("autodoc", 0);
%feature("autodoc", "GetPosition() -> (x, y)") GetPosition; void GetPosition(int* OUTPUT, int* OUTPUT);
%feature("docstring", "This is some more info.") GetPosition;