Michele De Stefano's C++ Utilities
indexing_example.i
1 // indexing_example.i
2 //
3 // Copyright (c) 2014 - 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 indexing_example_wrap.cpp indexing_example.i
11  *
12  * 2. python setup.py build
13  */
14 
15 /**
16  * \example indexing_example.i
17  *
18  * A simple SWIG interface for a Python extension module that shows the
19  * mds_utils::python::support_random_access and
20  * mds_utils::python::support_random_getset_access usage.
21  *
22  * \remarks Here I've used SWIG for convenience only. The
23  * mds_utils::python::FileObj class does not impose you
24  * this choice.
25  */
26 
27 %module indexing_example
28 
29 %include "mds_utils/python/common.i"
30 %include "mds_utils/python/obj.i"
31 
32 %header %{
33 
34 #include "indexing_example.hpp"
35 
36 namespace mdspy = mds_utils::python;
37 
38 %}
39 
40 
41 class Dummy_Container {
42 
43 public:
44 
45  Dummy_Container();
46 
47 %extend {
48  // The following methods are created as extensions
49 
50  mds_utils::python::Obj __getitem__(mds_utils::python::Obj idx) {
51  return $self->py_get_item(idx);
52  }
53 
54  void __setitem__(mds_utils::python::Obj idx,mds_utils::python::Obj val) {
55  $self->py_set_item(idx,val);
56  }
57 }
58 
59 };