3 // Copyright (c) 2014 - Michele De Stefano (micdestefano@users.sourceforge.net)
5 // Distributed under the MIT License (See accompanying file LICENSE)
8 * Instructions for generating and building the extension:
10 * 1. swig -c++ -Wall -python -I../../../include -o tuple_usage_wrap.cpp tuple_usage.i
12 * 2. python setup.py build
16 * \example tuple_usage.i
18 * A simple SWIG interface for a Python extension module that shows the
19 * mds_utils::python::Tuple usage.
21 * \remarks Here I've used SWIG for convenience only. The
22 * mds_utils::python::Tuple class does not impose you
28 // Include the following interface files for having the proper typemaps
29 %include "mds_utils/python/common.i"
30 %include "mds_utils/python/tuple.i"
34 #include <mds_utils/python/conversion.hpp>
35 #include <mds_utils/python/tuple.hpp>
36 #include <mds_utils/python/sequence_iterator.hpp>
37 #include <boost/fusion/container/vector.hpp>
40 namespace mdspy = mds_utils::python;
46 // Tests the call to Tuple::set(mdspy::Obj)
47 PyObject* create_tuple(mds_utils::python::Obj o) {
55 cout << "Built tuple length: " << t.len() << endl;
57 PyObject *pret(t.transfer());
63 // Tests the call to Tuple::set(const seq_T&)
64 PyObject* create_from_fusion() {
66 namespace fus = boost::fusion;
70 fus::vector<int,double,std::string>
79 // Tests the Tuple::set(FwIt,FwIt) method
80 PyObject* create_from_seq(mds_utils::python::Obj o) {
82 mdspy::PySequenceIterator<mdspy::Obj>
94 // Like the previous one, but returning directly a mdspy::Tuple
95 // This tests the output typemap
96 mds_utils::python::Tuple create_from_seq2(mds_utils::python::Obj o) {
98 mdspy::PySequenceIterator<mdspy::Obj>
109 // Test for element access with operator []
110 mds_utils::python::Obj access_element(mds_utils::python::Obj o,long i) {
116 // This shows that the assignment to an element of the tuple fails
117 void set_element(mds_utils::python::Obj o,long i,mds_utils::python::Obj v) {