| 1 | /* |
| 2 | Sets |
| 3 | */ |
| 4 | |
| 5 | %fragment("StdSetTraits","header",fragment="StdSequenceTraits") |
| 6 | %{ |
| 7 | namespace swig { |
| 8 | template <class PySeq, class T> |
| 9 | inline void |
| 10 | assign(const PySeq& pyseq, std::set<T>* seq) { |
| 11 | #ifdef SWIG_STD_NOINSERT_TEMPLATE_STL |
| 12 | typedef typename PySeq::value_type value_type; |
| 13 | typename PySeq::const_iterator it = pyseq.begin(); |
| 14 | for (;it != pyseq.end(); ++it) { |
| 15 | seq->insert(seq->end(),(value_type)(*it)); |
| 16 | } |
| 17 | #else |
| 18 | seq->insert(pyseq.begin(), pyseq.end()); |
| 19 | #endif |
| 20 | } |
| 21 | |
| 22 | template <class T> |
| 23 | struct traits_asptr<std::set<T> > { |
| 24 | static int asptr(PyObject *obj, std::set<T> **s) { |
| 25 | return traits_asptr_stdseq<std::set<T> >::asptr(obj, s); |
| 26 | } |
| 27 | }; |
| 28 | |
| 29 | template <class T> |
| 30 | struct traits_from<std::set<T> > { |
| 31 | static PyObject *from(const std::set<T>& vec) { |
| 32 | return traits_from_stdseq<std::set<T> >::from(vec); |
| 33 | } |
| 34 | }; |
| 35 | } |
| 36 | %} |
| 37 | |
| 38 | %define %swig_set_methods(set...) |
| 39 | %swig_container_methods(set); |
| 40 | |
| 41 | %extend { |
| 42 | void append(value_type x) { |
| 43 | self->insert(x); |
| 44 | } |
| 45 | |
| 46 | bool __contains__(value_type x) { |
| 47 | return self->find(x) != self->end(); |
| 48 | } |
| 49 | |
| 50 | value_type __getitem__(difference_type i) const throw (std::out_of_range) { |
| 51 | return *(swig::cgetpos(self, i)); |
| 52 | } |
| 53 | }; |
| 54 | %enddef |
| 55 | |
| 56 | %include <std/std_set.i> |