PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/cpp_enum.i

#
Swig | 54 lines | 38 code | 13 blank | 3 comment | 0 complexity | a90823ad8329c6218844f46fe388a8a4 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /*
  2. The primary purpose of this testcase is to ensure that enums used along with the 'enum' keyword compile under c++.
  3. */
  4. %module cpp_enum
  5. %inline %{
  6. enum SOME_ENUM {ENUM_ONE, ENUM_TWO};
  7. struct StructWithEnums {
  8. StructWithEnums() : some_enum(ENUM_ONE) {};
  9. enum SOME_ENUM some_enum;
  10. void enum_test1(enum SOME_ENUM param1, enum SOME_ENUM* param2, enum SOME_ENUM& param3) {};
  11. void enum_test2(SOME_ENUM param1, SOME_ENUM* param2, SOME_ENUM& param3) {};
  12. SOME_ENUM enum_test3() { return ENUM_ONE; };
  13. enum SOME_ENUM enum_test4() { return ENUM_TWO; };
  14. SOME_ENUM* enum_test5() { return &some_enum; };
  15. enum SOME_ENUM* enum_test6() { return &some_enum; };
  16. SOME_ENUM& enum_test7() { return some_enum; };
  17. enum SOME_ENUM& enum_test8() { return some_enum; };
  18. };
  19. struct Foo
  20. {
  21. enum {Hi, Hello } hola;
  22. Foo()
  23. : hola(Hello)
  24. {
  25. }
  26. };
  27. extern "C"
  28. {
  29. enum {Hi, Hello } hi;
  30. }
  31. %}
  32. // Using true and false in enums is legal in C++. Quoting the standard:
  33. // [dcl.enum]
  34. // ... The constant-expression shall be of integral or enumeration type.
  35. // [basic.fundamental]
  36. // ... Types bool, char, wchar_t, and the signed and unsigned integer
  37. // types are collectively called integral types.
  38. // So this shouldn't lead to a warning, at least in C++ mode.
  39. %inline %{
  40. typedef enum { PLAY = true, STOP = false } play_state;
  41. %}