| 1 | /* -----------------------------------------------------------------------------\r |
| 2 | * Include this file in order for C/C++ enums to be wrapped by the so called\r |
| 3 | * typesafe enum pattern. Each enum has an equivalent C# class named after the\r |
| 4 | * enum and each enum item is a static instance of this class.\r |
| 5 | * ----------------------------------------------------------------------------- */\r |
| 6 | \r |
| 7 | // const enum SWIGTYPE & typemaps\r |
| 8 | %typemap(ctype) const enum SWIGTYPE & "int"\r |
| 9 | %typemap(imtype) const enum SWIGTYPE & "int"\r |
| 10 | %typemap(cstype) const enum SWIGTYPE & "$*csclassname"\r |
| 11 | \r |
| 12 | %typemap(in) const enum SWIGTYPE & ($*1_ltype temp)\r |
| 13 | %{ temp = ($*1_ltype)$input; \r |
| 14 | $1 = &temp; %}\r |
| 15 | %typemap(out) const enum SWIGTYPE & %{ $result = *$1; %}\r |
| 16 | \r |
| 17 | %typecheck(SWIG_TYPECHECK_POINTER) const enum SWIGTYPE & ""\r |
| 18 | \r |
| 19 | %typemap(throws, canthrow=1) const enum SWIGTYPE & %{\r |
| 20 | (void)$1;\r |
| 21 | SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, "C++ $1_type exception thrown");\r |
| 22 | return $null;\r |
| 23 | %}\r |
| 24 | \r |
| 25 | %typemap(csin) const enum SWIGTYPE & "$csinput.swigValue"\r |
| 26 | %typemap(csout, excode=SWIGEXCODE) const enum SWIGTYPE & {\r |
| 27 | $*csclassname ret = $*csclassname.swigToEnum($imcall);$excode\r |
| 28 | return ret;\r |
| 29 | }\r |
| 30 | \r |
| 31 | %typemap(csvarout, excode=SWIGEXCODE2) const enum SWIGTYPE & %{\r |
| 32 | get {\r |
| 33 | $*csclassname ret = $*csclassname.swigToEnum($imcall);$excode\r |
| 34 | return ret;\r |
| 35 | } %}\r |
| 36 | \r |
| 37 | \r |
| 38 | // enum SWIGTYPE typemaps\r |
| 39 | %typemap(ctype) enum SWIGTYPE "int"\r |
| 40 | %typemap(imtype) enum SWIGTYPE "int"\r |
| 41 | %typemap(cstype) enum SWIGTYPE "$csclassname"\r |
| 42 | \r |
| 43 | %typemap(in) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}\r |
| 44 | %typemap(out) enum SWIGTYPE %{ $result = $1; %}\r |
| 45 | \r |
| 46 | %typecheck(SWIG_TYPECHECK_POINTER) enum SWIGTYPE ""\r |
| 47 | \r |
| 48 | %typemap(throws, canthrow=1) enum SWIGTYPE %{\r |
| 49 | (void)$1;\r |
| 50 | SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, "C++ $1_type exception thrown");\r |
| 51 | return $null;\r |
| 52 | %}\r |
| 53 | \r |
| 54 | %typemap(csin) enum SWIGTYPE "$csinput.swigValue"\r |
| 55 | %typemap(csout, excode=SWIGEXCODE) enum SWIGTYPE {\r |
| 56 | $csclassname ret = $csclassname.swigToEnum($imcall);$excode\r |
| 57 | return ret;\r |
| 58 | }\r |
| 59 | \r |
| 60 | %typemap(csvarout, excode=SWIGEXCODE2) enum SWIGTYPE %{\r |
| 61 | get {\r |
| 62 | $csclassname ret = $csclassname.swigToEnum($imcall);$excode\r |
| 63 | return ret;\r |
| 64 | } %}\r |
| 65 | \r |
| 66 | %typemap(csbase) enum SWIGTYPE ""\r |
| 67 | %typemap(csclassmodifiers) enum SWIGTYPE "public sealed class"\r |
| 68 | %typemap(cscode) enum SWIGTYPE ""\r |
| 69 | %typemap(csimports) enum SWIGTYPE ""\r |
| 70 | %typemap(csinterfaces) enum SWIGTYPE ""\r |
| 71 | \r |
| 72 | /*\r |
| 73 | * The swigToEnum method is used to find the C# enum from a C++ enum integer value. The default one here takes \r |
| 74 | * advantage of the fact that most enums do not have initial values specified, so the lookup is fast. If initial\r |
| 75 | * values are specified then a lengthy linear search through all possible enums might occur. Specific typemaps could be\r |
| 76 | * written to possibly optimise this lookup by taking advantage of characteristics peculiar to the targeted enum.\r |
| 77 | * The special variable, $enumvalues, is replaced with a comma separated list of all the enum values.\r |
| 78 | */\r |
| 79 | %typemap(csbody) enum SWIGTYPE %{\r |
| 80 | public readonly int swigValue;\r |
| 81 | \r |
| 82 | public static $csclassname swigToEnum(int swigValue) {\r |
| 83 | if (swigValue < swigValues.Length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)\r |
| 84 | return swigValues[swigValue];\r |
| 85 | for (int i = 0; i < swigValues.Length; i++)\r |
| 86 | if (swigValues[i].swigValue == swigValue)\r |
| 87 | return swigValues[i];\r |
| 88 | throw new System.ArgumentOutOfRangeException("No enum $csclassname with value " + swigValue);\r |
| 89 | }\r |
| 90 | \r |
| 91 | public override string ToString() {\r |
| 92 | return swigName;\r |
| 93 | }\r |
| 94 | \r |
| 95 | private $csclassname(string swigName) {\r |
| 96 | this.swigName = swigName;\r |
| 97 | this.swigValue = swigNext++;\r |
| 98 | }\r |
| 99 | \r |
| 100 | private $csclassname(string swigName, int swigValue) {\r |
| 101 | this.swigName = swigName;\r |
| 102 | this.swigValue = swigValue;\r |
| 103 | swigNext = swigValue+1;\r |
| 104 | }\r |
| 105 | \r |
| 106 | private static $csclassname[] swigValues = { $enumvalues };\r |
| 107 | private static int swigNext = 0;\r |
| 108 | private readonly string swigName;\r |
| 109 | %}\r |
| 110 | \r |
| 111 | %csenum(typesafe);\r |
| 112 | \r |