/tags/rel-1-3-29/SWIG/Lib/python/std_set.i
Swig | 58 lines | 46 code | 9 blank | 3 comment | 0 complexity | 9a62efde9cb5b7fa4ec7b7dc3e9c9ccc MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
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_sequence_iterator(set); 40 %swig_container_methods(set); 41 42 %extend { 43 void append(value_type x) { 44 self->insert(x); 45 } 46 47 bool __contains__(value_type x) { 48 return self->find(x) != self->end(); 49 } 50 51 value_type __getitem__(difference_type i) const throw (std::out_of_range) { 52 return *(swig::cgetpos(self, i)); 53 } 54 55 }; 56%enddef 57 58%include <std/std_set.i>