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 list_usage_wrap.cpp list_usage.i
12 * 2. python setup.py build
16 * \example list_usage.i
18 * A simple SWIG interface for a Python extension module that shows the
19 * mds_utils::python::List usage.
21 * \remarks Here I've used SWIG for convenience only. The
22 * mds_utils::python::List 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/list.i"
33 #include <mds_utils/python/conversion.hpp>
34 #include <mds_utils/python/list.hpp>
35 #include <mds_utils/python/sequence_iterator.hpp>
36 #include <boost/fusion/container/vector.hpp>
39 namespace mdspy = mds_utils::python;
45 // Tests the call to List::set(mds_utils::python::Obj)
46 PyObject* create_list(mds_utils::python::Obj o) {
54 cout << "Built list length: " << t.len() << endl;
56 PyObject *pret(t.transfer());
62 // Tests the call to List::set(const seq_T&)
63 PyObject* create_from_fusion() {
65 namespace fus = boost::fusion;
69 fus::vector<int,double,std::string>
78 // Tests the List::set(FwIt,FwIt) method
79 PyObject* create_from_seq(mds_utils::python::Obj o) {
81 mdspy::PySequenceIterator<mdspy::Obj>
93 // Like the previous one, but returning directly a mds_utils::python::List
94 // This tests the output typemap
95 mds_utils::python::List create_from_seq2(mds_utils::python::Obj o) {
97 mdspy::PySequenceIterator<mdspy::Obj>
108 // Test for element access with operator []
109 mds_utils::python::Obj access_element(mds_utils::python::List l,long i) {
113 // Test for element assignment through operator []
114 void set_element(mds_utils::python::List l,long i,mds_utils::python::Obj v) {
118 // Test the append method
119 void append_element(mds_utils::python::List l,mds_utils::python::Obj v) {
123 // Test directly appending a basic type
124 void append_double(mds_utils::python::List l) {
129 // Test the insert method
130 void insert_element(mds_utils::python::List l,long i,mds_utils::python::Obj v) {
135 // Test the del method
136 void del_element(mds_utils::python::List l,long i) {
141 // Test the sort method
142 void sort_list(mds_utils::python::List l) {
147 // Test the reverse method
148 void reverse_list(mds_utils::python::List l) {
153 // Tests the copy-constructor
154 // This function does not actually duplicate the list
155 // It simply creates another Python object pointing to the same
157 mds_utils::python::List dup_list(mds_utils::python::List l) {
158 mdspy::List retval(l);
163 // Tests the copy-assignment
164 // This function does not actually duplicate the list
165 // It simply creates another Python object pointing to the same
167 mds_utils::python::List dup_list2(mds_utils::python::List l) {