%fragment("StdTraits","header",fragment="StdTraitsCommon") { namespace swig { // Traits that provides the from method template struct traits_from_ptr { static SwigSciObject from(Type *val, int owner = 0) { return SWIG_OK; //SWIG_NewPointerObj(val, type_info(), owner); } }; template struct traits_from { static SwigSciObject from(const Type& val) { return traits_from_ptr::from(new Type(val), 1); } }; template struct traits_from { static SwigSciObject from(Type* val) { return traits_from_ptr::from(val, 0); } }; template struct traits_from { static SwigSciObject from(const Type* val) { return traits_from_ptr::from(const_cast(val), 0); } }; template inline SwigSciObject from(const Type& val) { return traits_from::from(val); } template inline SwigSciObject from_ptr(Type* val, int owner) { return traits_from_ptr::from(val, owner); } // Traits that provides the asval/as/check method template struct traits_asptr { static int asptr(const SwigSciObject& obj, Type **val) { Type *p = 0; swig_type_info *descriptor = type_info(); int res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR; if (SWIG_IsOK(res)) { if (val) *val = p; } return res; } }; template inline int asptr(const SwigSciObject& obj, Type **vptr) { return traits_asptr::asptr(obj, vptr); } template struct traits_asval { static int asval(const SwigSciObject& obj, Type *val) { if (val) { Type *p = 0; int res = traits_asptr::asptr(obj, &p); if (!SWIG_IsOK(res)) return res; if (p) { typedef typename noconst_traits::noconst_type noconst_type; *(const_cast(val)) = *p; if (SWIG_IsNewObj(res)){ %delete(p); res = SWIG_DelNewMask(res); } return res; } else { return SWIG_ERROR; } } else { return traits_asptr::asptr(obj, (Type **)(0)); } } }; template struct traits_asval { static int asval(const SwigSciObject& obj, Type **val) { if (val) { typedef typename noconst_traits::noconst_type noconst_type; noconst_type *p = 0; int res = traits_asptr::asptr(obj, &p); if (SWIG_IsOK(res)) { *(const_cast(val)) = p; } return res; } else { return traits_asptr::asptr(obj, (Type **)(0)); } } }; template inline int asval(const SwigSciObject& obj, Type *val) { return traits_asval::asval(obj, val); } template struct traits_as { static Type as(const SwigSciObject& obj) { Type v; int res = asval(obj, &v); if (SWIG_IsOK(res)) { return v; } else { %type_error(swig::type_name()); throw std::invalid_argument("bad type"); } } }; template struct traits_as { static Type as(const SwigSciObject& obj) { Type *v = 0; int res = traits_asptr::asptr(obj, &v); if (SWIG_IsOK(res) && v) { if (SWIG_IsNewObj(res)) { Type r(*v); %delete(v); return r; } else { return *v; } } else { %type_error(swig::type_name()); throw std::invalid_argument("bad type"); } } }; template struct traits_as { static Type* as(const SwigSciObject& obj) { Type *v = 0; int res = traits_asptr::asptr(obj, &v); if (SWIG_IsOK(res)) { return v; } else { %type_error(swig::type_name()); throw std::invalid_argument("bad type"); } } }; template inline Type as(const SwigSciObject& obj) { return traits_as::category>::as(obj); } template struct traits_check { static bool check(const SwigSciObject& obj) { int res = asval(obj, (Type *)(0)); return SWIG_IsOK(res) ? true : false; } }; template struct traits_check { static bool check(const SwigSciObject& obj) { int res = asptr(obj, (Type **)(0)); return SWIG_IsOK(res) ? true : false; } }; template inline bool check(const SwigSciObject& obj) { return traits_check::category>::check(obj); } } } %define %specialize_std_container(Type,Check,As,From) %{ namespace swig { template <> struct traits_asval { typedef Type value_type; static int asval(const SwigSciObject& obj, value_type *val) { if (Check(obj)) { if (val) *val = As(obj); return SWIG_OK; } return SWIG_ERROR; } }; template <> struct traits_from { typedef Type value_type; static SwigSciObject from(const value_type& val) { return From(val); } }; template <> struct traits_check { static int check(const SwigSciObject& obj) { int res = Check(obj); return obj && res ? res : 0; } }; } %} %enddef #define specialize_std_vector(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From) #define specialize_std_list(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From) #define specialize_std_deque(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From) #define specialize_std_set(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From) #define specialize_std_multiset(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)