PageRenderTime 51ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-25/SWIG/Examples/test-suite/java_enums.i

#
Swig | 56 lines | 44 code | 12 blank | 0 comment | 0 complexity | 9682f54ed383bbe0e2cf64721a115958 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. // This testcase uses the %javaconst directive to control how enums are initialised
  2. %module java_enums
  3. %include "enumtypeunsafe.swg"
  4. // Some pragmas to add in an interface to the module class
  5. %pragma(java) moduleinterfaces="Serializable"
  6. %pragma(java) moduleimports=%{
  7. import java.io.*; // For Serializable
  8. %}
  9. // Set default Java const code generation
  10. %javaconst(1);
  11. // Change the default generation so that these enums are generated into an interface instead of a class
  12. %typemap(javaclassmodifiers) enum stuff "public interface"
  13. %inline %{
  14. enum stuff { FIDDLE = 2*100, STICKS = 5+8, BONGO, DRUMS };
  15. %}
  16. // Check that the enum typemaps are working by using a short for the enums instead of int
  17. %javaconst(0); // will create compile errors in runme file if short typemaps not used
  18. namespace Space {
  19. %typemap(jtype) enum nonsense "short"
  20. %typemap(jstype) enum nonsense "short"
  21. %typemap(javain) enum nonsense "$javainput"
  22. %typemap(in) enum nonsense %{ $1 = (enum Space::nonsense)$input; %}
  23. %typemap(out) enum nonsense %{ $result = (jshort)$1; %}
  24. %typemap(jni) enum nonsense "jshort"
  25. %typemap(javaout) enum nonsense {
  26. return $jnicall;
  27. }
  28. }
  29. %inline %{
  30. namespace Space {
  31. enum nonsense { POPPYCOCK, JUNK };
  32. nonsense test1(nonsense n) { return n; }
  33. enum nonsense test2(enum nonsense n) { return n; }
  34. }
  35. %}
  36. // Test the %javaconstvalue directive for enums
  37. %{
  38. static const int FOUR = 4;
  39. %}
  40. %javaconst(1);
  41. %javaconstvalue(4) Quattro;
  42. %inline %{
  43. enum Numero { Quattro = FOUR };
  44. %}