Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* ------------------------------------------------------------ |
2 | * Enums | |
3 | * ------------------------------------------------------------ */ | |
4 | ||
5 | /* --- Input typemaps --- */ | |
6 | %typemap(in) enum SWIGTYPE "$1 = ($1_ltype) NUM2INT($input);"; | |
7 | ||
8 | %typemap(in) const enum SWIGTYPE & ($*1_ltype temp) | |
9 | "temp = ($*1_ltype) NUM2INT($input); | |
10 | $1 = &temp;"; | |
11 | ||
12 | ||
13 | %typemap(directorout) enum SWIGTYPE "$result = ($1_ltype) NUM2INT($input);"; | |
14 | %typemap(directorout,warning=SWIG_WARN_TYPEMAP_THREAD_UNSAFE) const enum SWIGTYPE & | |
15 | %{ static $*1_ltype temp = ($*1_ltype) NUM2INT($input); | |
16 | $result = &temp; %} | |
17 | ||
18 | /* --- Output typemaps --- */ | |
19 | %typemap(out) enum SWIGTYPE "$result = INT2NUM($1);"; | |
20 | ||
21 | %typemap(out) const enum SWIGTYPE & "$result = INT2NUM((long) *($1));"; | |
22 | ||
23 | %typemap(directorin) enum SWIGTYPE "$input = INT2NUM($1);"; | |
24 | %typemap(directorin) const enum SWIGTYPE& "$input = INT2NUM($1);"; | |
25 | ||
26 | /* --- Variable Input --- */ | |
27 | ||
28 | %{ | |
29 | static void SWIG_AsVal(VALUE obj, int *val) | |
30 | { | |
31 | *val = (int) NUM2INT(obj); | |
32 | } | |
33 | %} | |
34 | ||
35 | %typemap(varin) enum SWIGTYPE { | |
36 | if (sizeof(int) != sizeof($1)) { | |
37 | rb_raise(rb_eTypeError, "enum variable '$name' can not be set."); | |
38 | } | |
39 | SWIG_AsVal($input, (int *)(void *) &$1); | |
40 | } | |
41 | ||
42 | /* --- Variable Output --- */ | |
43 | ||
44 | %typemap(varout) enum SWIGTYPE "$result = INT2NUM($1);"; | |
45 | ||
46 | /* --- Constants --- */ | |
47 | %typemap(constant) enum SWIGTYPE "rb_define_const($module,\"$symname\", INT2NUM($1));"; | |
48 | ||
49 | /* ------------------------------------------------------------ | |
50 | * Typechecking rules | |
51 | * ------------------------------------------------------------ */ | |
52 | ||
53 | %typecheck(SWIG_TYPECHECK_INTEGER) enum SWIGTYPE, const enum SWIGTYPE & | |
54 | { | |
55 | $1 = ((TYPE($input) == T_FIXNUM) || (TYPE($input) == T_BIGNUM)) ? 1 : 0; | |
56 | } | |
57 | ||
58 | /* ------------------------------------------------------------ | |
59 | * Exception handling | |
60 | * ------------------------------------------------------------ */ | |
61 | ||
62 | %typemap(throws) enum SWIGTYPE | |
63 | "(void)$1; rb_exc_raise(rb_exc_new3(rb_eRuntimeError, rb_obj_as_string(INT2NUM($1))));" | |
64 |