File: cpp_enum.i

package info (click to toggle)
swig 3.0.10-1.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 40,672 kB
  • ctags: 18,134
  • sloc: cpp: 57,901; ansic: 26,762; java: 11,026; python: 8,544; cs: 6,999; makefile: 6,450; yacc: 5,649; sh: 5,201; ruby: 4,680; perl: 3,461; php: 1,880; lisp: 1,827; tcl: 1,068; ml: 747; xml: 115
file content (54 lines) | stat: -rw-r--r-- 1,375 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
The primary purpose of this testcase is to ensure that enums used along with the 'enum' keyword compile under c++.
*/

%module cpp_enum

%inline %{

enum SOME_ENUM {ENUM_ONE, ENUM_TWO};

struct StructWithEnums {
    StructWithEnums() : some_enum(ENUM_ONE) {};
    enum SOME_ENUM some_enum;
    void enum_test1(enum SOME_ENUM param1, enum SOME_ENUM* param2, enum SOME_ENUM& param3) {};
    void enum_test2(SOME_ENUM param1, SOME_ENUM* param2, SOME_ENUM& param3) {};

    SOME_ENUM enum_test3() { return ENUM_ONE; };
    enum SOME_ENUM enum_test4() { return ENUM_TWO; };

    SOME_ENUM* enum_test5() { return &some_enum; };
    enum SOME_ENUM* enum_test6() { return &some_enum; };

    SOME_ENUM& enum_test7() { return some_enum; };
    enum SOME_ENUM& enum_test8() { return some_enum; };
};

 struct Foo
 {   
   enum {Hi, Hello } hola;
   
   Foo() 
     : hola(Hello)
   {
   }
 };

extern "C"
{
 enum {Hi, Hello } hi;
}

%}

// Using true and false in enums is legal in C++. Quoting the standard:
// [dcl.enum]
//     ... The constant-expression shall be of integral or enumeration type.
// [basic.fundamental]
//     ... Types bool, char, wchar_t, and the signed and unsigned integer
//     types are collectively called integral types.
// So this shouldn't lead to a warning, at least in C++ mode.
%inline %{
typedef enum { PLAY = true, STOP = false } play_state;
%}