PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/octave/std_common.i

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