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