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 dict_usage_wrap.cpp dict_usage.i
12 * 2. python setup.py build
16 * \example dict_usage.i
18 * A simple SWIG interface for a Python extension module that shows the
19 * mds_utils::python::Dictionary usage.
21 * \remarks Here I've used SWIG for convenience only. The
22 * mds_utils::python::Dictionary class does not impose you
28 // Include the following interface files for having the proper typemaps
29 %include "std_string.i"
30 %include "mds_utils/python/common.i"
31 %include "mds_utils/python/list.i"
32 %include "mds_utils/python/dictionary.i"
35 #include <mds_utils/python/conversion.hpp>
36 #include <mds_utils/python/dictionary.hpp>
39 namespace mdspy = mds_utils::python;
45 // Tests the copy of the dictionary
46 mds_utils::python::Dictionary copy_dict(mds_utils::python::Dictionary d) {
48 mdspy::Dictionary out;
55 // Tests the clear method
56 void clear_dict(mds_utils::python::Dictionary d) {
60 // Tests the contains method
61 bool dict_contains(mds_utils::python::Dictionary d,mds_utils::python::Obj key) {
62 return d.contains(key);
65 // Tests the contains method, with integer key
66 bool dict_contains_int_key(mds_utils::python::Dictionary d,int key) {
67 return d.contains(key);
70 // Tests the contains method, with string key
71 bool dict_contains_str_key(mds_utils::python::Dictionary d,std::string key) {
72 return d.contains(key);
75 // Tests the set_item method
76 void dict_set_item(mds_utils::python::Dictionary d,mds_utils::python::Obj key,mds_utils::python::Obj val) {
80 // Tests the set_item method, with string key and integer value
81 void dict_set_item_str_int(mds_utils::python::Dictionary d,std::string key,int val) {
85 // Tests the del_item method
86 void dict_del_item(mds_utils::python::Dictionary d,mds_utils::python::Obj key) {
91 // Tests the get_item method
92 mds_utils::python::Obj dict_get_item(mds_utils::python::Dictionary d,mds_utils::python::Obj key) {
93 return d.get_item(key);
96 // Tests the items method
97 mds_utils::python::List dict_items(mds_utils::python::Dictionary d) {
101 // Tests the keys method
102 mds_utils::python::List dict_keys(mds_utils::python::Dictionary d) {
106 // Tests the values method
107 mds_utils::python::List dict_values(mds_utils::python::Dictionary d) {
111 // Tests the len method
112 size_t dict_len(mds_utils::python::Dictionary d) {
117 // Tests the update method
118 void dict_update(mds_utils::python::Dictionary a,mds_utils::python::Dictionary b) {