%module tclnotmuch
%{
/* Includes the header in the wrapper code */
#include <notmuch.h>
%}

/* Need this to get the value returned from some functions */
/* Might there be cases where "long" is not the right thing to choose? */
%typedef long time_t;

/* strip off the existing prefix*/
%rename("%(strip:[notmuch_])s") "";

/* specific changes: */
/*   for notmuch_database_open (and _create) to deal with the opaque pointer argument*/
%typemap(in,numinputs=0) notmuch_database_t **database (notmuch_database_t *temp)
{
    $1 = &temp;
}

/*   for notmuch_database_open (and _create) to return the correct pointer (or NULL) */
/*      (actually just notmuch_database_t *, which can be used to call other API functions) */
%typemap(argout) notmuch_database_t **database
{
    %append_output(SWIG_NewPointerObj(SWIG_as_voidptr(*$1), $*1_descriptor, SWIG_POINTER_OWN));
}

/*   for notmuch_database_get_directory to deal with the opaque pointer argument*/
%typemap(in,numinputs=0) notmuch_directory_t **directory (notmuch_directory_t *temp)
{
    $1 = &temp;
}

/*   for notmuch_database_get_directory to return the correct pointer (or NULL) */
/*      (actually just notmuch_directory_t *, which can be used to call other API functions) */
%typemap(argout) notmuch_directory_t **directory
{
    %append_output(SWIG_NewPointerObj(SWIG_as_voidptr(*$1), $*1_descriptor, SWIG_POINTER_OWN));
}

/*   for notmuch_database_add_message, notmuch_database_find_message, */
/*      notmuch_database_find_message_by_filename to deal with the opaque pointer argument*/
%typemap(in,numinputs=0) notmuch_message_t **message (notmuch_message_t *temp)
{
    $1 = &temp;
}

/*   for notmuch_database_add_message, notmuch_database_find_message, */
/*      notmuch_database_find_message_by_filename to return the correct pointer (or NULL) */
/*      (actually just notmuch_message_t *, which can be used to call other API functions) */
%typemap(argout) notmuch_message_t **message
{
    %append_output(SWIG_NewPointerObj(SWIG_as_voidptr(*$1), $*1_descriptor, SWIG_POINTER_OWN));
}



/* Parse the header file to generate wrappers */
%include <notmuch.h>
