PageRenderTime 33ms CodeModel.GetById 29ms app.highlight 2ms RepoModel.GetById 1ms 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
 1/*
 2The primary purpose of this testcase is to ensure that enums used along with the 'enum' keyword compile under c++.
 3*/
 4
 5%module cpp_enum
 6
 7%inline %{
 8
 9enum SOME_ENUM {ENUM_ONE, ENUM_TWO};
10
11struct StructWithEnums {
12    StructWithEnums() : some_enum(ENUM_ONE) {};
13    enum SOME_ENUM some_enum;
14    void enum_test1(enum SOME_ENUM param1, enum SOME_ENUM* param2, enum SOME_ENUM& param3) {};
15    void enum_test2(SOME_ENUM param1, SOME_ENUM* param2, SOME_ENUM& param3) {};
16
17    SOME_ENUM enum_test3() { return ENUM_ONE; };
18    enum SOME_ENUM enum_test4() { return ENUM_TWO; };
19
20    SOME_ENUM* enum_test5() { return &some_enum; };
21    enum SOME_ENUM* enum_test6() { return &some_enum; };
22
23    SOME_ENUM& enum_test7() { return some_enum; };
24    enum SOME_ENUM& enum_test8() { return some_enum; };
25};
26
27 struct Foo
28 {   
29   enum {Hi, Hello } hola;
30   
31   Foo() 
32     : hola(Hello)
33   {
34   }
35 };
36
37extern "C"
38{
39 enum {Hi, Hello } hi;
40}
41
42%}
43
44// Using true and false in enums is legal in C++. Quoting the standard:
45// [dcl.enum]
46//     ... The constant-expression shall be of integral or enumeration type.
47// [basic.fundamental]
48//     ... Types bool, char, wchar_t, and the signed and unsigned integer
49//     types are collectively called integral types.
50// So this shouldn't lead to a warning, at least in C++ mode.
51%inline %{
52typedef enum { PLAY = true, STOP = false } play_state;
53%}
54