Michele De Stefano's C++ Utilities
sequence_iterator_example.i
1 // sequence_iterator_example.i
2 //
3 // Copyright (c) 2012 - Michele De Stefano (micdestefano@users.sourceforge.net)
4 //
5 // Distributed under the MIT License (See accompanying file LICENSE)
6 
7 /*
8  * Instructions for generating and building the extension:
9  *
10  * 1. swig -c++ -Wall -python -I../../../include -o sequence_iterator_example_wrap.cpp sequence_iterator_example.i
11  *
12  * 2. python setup.py build
13  */
14 
15 
16 /**
17  * \example sequence_iterator_example.i
18  *
19  * A simple SWIG interface for a Python extension module that shows the
20  * mds_utils::python::PySequenceIterator usage.
21  *
22  * \remarks Here I've used SWIG for convenience only. The
23  * mds_utils::python::PySequenceIterator does not impose you
24  * this choice.
25  */
26 
27 
28 %module sequence_iterator_test
29 
30 // Include the following interface files for having the proper typemaps
31 %include "mds_utils/python/common.i"
32 
33 %{
34 #include <mds_utils/python/sequence_iterator.hpp>
35 
36 /*
37  * The source code of the following two files is into the
38  * "examples/python" directory.
39  */
40 #include "print_seq.hpp"
41 #include "incr_seq.hpp"
42 
43  using namespace mds_utils::python;
44 %}
45 
46 template<class InIt>
47 void print_seq(InIt,InIt);
48 
49 template<class InIt>
50 void incr_seq(InIt,InIt);
51 
52 
53 %typemap(in) (PySequenceIterator<double>,PySequenceIterator<double>) {
54  try {
55  $1 = PySequenceIterator<double>($input);
56  $2 = PySequenceIterator<double>($input,true);
57  } catch (std::exception& e) {
58  PyErr_SetString(PyExc_RuntimeError,e.what());
59  SWIG_fail;
60  }
61 }
62 
63 %typemap(in) (PySequenceIterator< std::complex<double> >,PySequenceIterator< std::complex<double> >) {
64  try {
65  $1 = PySequenceIterator< std::complex<double> >($input);
66  $2 = PySequenceIterator< std::complex<double> >($input,true);
67  } catch (std::exception& e) {
68  PyErr_SetString(PyExc_RuntimeError,e.what());
69  SWIG_fail;
70  }
71 }
72 
73 
74 %template(print_seq_d) print_seq< PySequenceIterator<double> >;
75 
76 %template(print_seq_cplx) print_seq< PySequenceIterator< std::complex<double> > >;
77 
78 %template(incr_seq_d) incr_seq< PySequenceIterator<double> >;
79 
80 %template(incr_seq_cplx) incr_seq< PySequenceIterator< std::complex<double> > >;
81 
82