1 %include <std/std_except.i> 2 %include <rubystdcommon.swg> 3 %include <rubystdautodoc.swg> 4 5 6 /* 7 Generate the traits for a 'primitive' type, such as 'double', 8 for which the SWIG_AsVal and SWIG_From methods are already defined. 9 */ 10 11 %define %traits_ptypen(Type...) 12 %fragment(SWIG_Traits_frag(Type),"header", 13 fragment=SWIG_AsVal_frag(Type), 14 fragment=SWIG_From_frag(Type), 15 fragment="StdTraits") { 16 namespace swig { 17 template <> struct traits<Type > { 18 typedef value_category category; 19 static const char* type_name() { return #Type; } 20 }; 21 template <> struct traits_asval<Type > { 22 typedef Type value_type; 23 static int asval(VALUE obj, value_type *val) { 24 return SWIG_AsVal(Type)(obj, val); 25 } 26 }; 27 template <> struct traits_from<Type > { 28 typedef Type value_type; 29 static VALUE from(const value_type& val) { 30 return SWIG_From(Type)(val); 31 } 32 }; 33 } 34 } 35 %enddef 36 37 /* Traits for enums. This is bit of a sneaky trick needed because a generic template specialization of enums 38 is not possible (unless using template meta-programming which SWIG doesn't support because of the explicit 39 instantiations required using %template). The STL containers define the 'front' method and the typemap 40 below is used whenever the front method is wrapped returning an enum. This typemap simply picks up the 41 standard enum typemap, but additionally drags in a fragment containing the traits_asval and traits_from 42 required in the generated code for enums. */ 43 44 %define %traits_enum(Type...) 45 %fragment("SWIG_Traits_enum_"{Type},"header", 46 fragment=SWIG_AsVal_frag(int), 47 fragment=SWIG_From_frag(int), 48 fragment="StdTraits") { 49 namespace swig { 50 template <> struct traits_asval<Type > { 51 typedef Type value_type; 52 static int asval(VALUE obj, value_type *val) { 53 return SWIG_AsVal(int)(obj, (int *)val); 54 } 55 }; 56 template <> struct traits_from<Type > { 57 typedef Type value_type; 58 static VALUE from(const value_type& val) { 59 return SWIG_From(int)((int)val); 60 } 61 }; 62 } 63 } 64 %typemap(out, fragment="SWIG_Traits_enum_"{Type}) const enum SWIGTYPE& front %{$typemap(out, const enum SWIGTYPE&)%} 65 %enddef 66 67 68 %include <std/std_common.i> 69 70 // 71 // Generates the traits for all the known primitive 72 // C++ types (int, double, ...) 73 // 74 %apply_cpptypes(%traits_ptypen); 75