Home | History | Annotate | Download | only in python
      1 %include <pycontainer.swg>
      2 
      3 
      4 %fragment("StdCarrayTraits","header",fragment="StdSequenceTraits")
      5 {
      6 namespace swig {
      7   template <class T, size_t S>
      8   struct traits_asptr<std::carray<T, S> >  {
      9     static int asptr(PyObject *obj, std::carray<T, S> **array) {
     10       return traits_asptr_stdseq<std::carray<T, S> >::asptr(obj, array);
     11     }
     12   };
     13 }
     14 }
     15 
     16 %warnfilter(SWIGWARN_IGNORE_OPERATOR_INDEX) std::carray::operator[];
     17 
     18 %extend std::carray {
     19   %fragment(SWIG_Traits_frag(std::carray<_Type, _Size >), "header",
     20 	    fragment="SwigPyIterator_T",
     21 	    fragment=SWIG_Traits_frag(_Type),
     22 	    fragment="StdCarrayTraits") {
     23     namespace swig {
     24       template <>  struct traits<std::carray<_Type, _Size > > {
     25 	typedef pointer_category category;
     26 	static const char* type_name() {
     27 	  return "std::carray<" #_Type "," #_Size " >";
     28 	}
     29       };
     30     }
     31   }
     32 
     33   %typemaps_asptr(SWIG_TYPECHECK_VECTOR, swig::asptr,
     34 		  SWIG_Traits_frag(std::carray<_Type, _Size >),
     35 		  std::carray<_Type, _Size >);
     36 
     37   %typemap(out,noblock=1) iterator, const_iterator {
     38     $result = SWIG_NewPointerObj(swig::make_output_iterator((const $type &)$1),
     39 				 swig::SwigPyIterator::descriptor(),SWIG_POINTER_OWN);
     40   }
     41 
     42   inline size_t __len__() const { return self->size(); }
     43 
     44   inline const _Type& __getitem__(size_t i) const { return (*self)[i]; }
     45 
     46   inline void __setitem__(size_t i, const _Type& v) { (*self)[i] = v; }
     47 
     48 
     49   swig::SwigPyIterator* __iter__(PyObject **PYTHON_SELF) {
     50     return swig::make_output_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
     51   }
     52 }
     53 
     54 %include <std/std_carray.swg>
     55