1 /* -----------------------------------------------------------------------------
2 * See the LICENSE file for information on copyright, usage and redistribution
3 * of SWIG, and the README file for authors - http://www.swig.org/release.html.
7 * Include this file in order for C/C++ enums to be wrapped by the so called
8 * typesafe enum pattern. Each enum has an equivalent C# class named after the
9 * enum and each enum item is a static instance of this class.
10 * ----------------------------------------------------------------------------- */
12 // const enum SWIGTYPE & typemaps
13 %typemap(ctype) const enum SWIGTYPE & "int"
14 %typemap(imtype) const enum SWIGTYPE & "int"
15 %typemap(cstype) const enum SWIGTYPE & "$*csclassname"
17 %typemap(in) const enum SWIGTYPE & ($*1_ltype temp)
18 %{ temp = ($*1_ltype)$input;
20 %typemap(out) const enum SWIGTYPE & %{ $result = *$1; %}
22 %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE &
23 %{ static $*1_ltype temp = ($*1_ltype)$input;
25 %typemap(directorin) const enum SWIGTYPE & "$input = $1_name;"
26 %typemap(csdirectorin) const enum SWIGTYPE & "$*csclassname.swigToEnum($iminput)"
27 %typemap(csdirectorout) const enum SWIGTYPE & "$cscall.swigValue"
29 %typecheck(SWIG_TYPECHECK_POINTER) const enum SWIGTYPE & ""
31 %typemap(throws, canthrow=1) const enum SWIGTYPE &
33 SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, "C++ $1_type exception thrown");
36 %typemap(csin) const enum SWIGTYPE & "$csinput.swigValue"
37 %typemap(csout, excode=SWIGEXCODE) const enum SWIGTYPE & {
38 $*csclassname ret = $*csclassname.swigToEnum($imcall);$excode
42 %typemap(csvarout, excode=SWIGEXCODE2) const enum SWIGTYPE & %{
44 $*csclassname ret = $*csclassname.swigToEnum($imcall);$excode
49 // enum SWIGTYPE typemaps
50 %typemap(ctype) enum SWIGTYPE "int"
51 %typemap(imtype) enum SWIGTYPE "int"
52 %typemap(cstype) enum SWIGTYPE "$csclassname"
54 %typemap(in) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}
55 %typemap(out) enum SWIGTYPE %{ $result = $1; %}
57 %typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %}
58 %typemap(directorin) enum SWIGTYPE "$input = $1;"
59 %typemap(csdirectorin) enum SWIGTYPE "$csclassname.swigToEnum($iminput)"
60 %typemap(csdirectorout) enum SWIGTYPE "$cscall.swigValue"
62 %typecheck(SWIG_TYPECHECK_POINTER) enum SWIGTYPE ""
64 %typemap(throws, canthrow=1) enum SWIGTYPE
66 SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, "C++ $1_type exception thrown");
69 %typemap(csin) enum SWIGTYPE "$csinput.swigValue"
70 %typemap(csout, excode=SWIGEXCODE) enum SWIGTYPE {
71 $csclassname ret = $csclassname.swigToEnum($imcall);$excode
75 %typemap(csvarout, excode=SWIGEXCODE2) enum SWIGTYPE %{
77 $csclassname ret = $csclassname.swigToEnum($imcall);$excode
81 %typemap(csbase) enum SWIGTYPE ""
82 %typemap(csclassmodifiers) enum SWIGTYPE "public sealed class"
83 %typemap(cscode) enum SWIGTYPE ""
84 %typemap(csimports) enum SWIGTYPE ""
85 %typemap(csinterfaces) enum SWIGTYPE ""
88 * The swigToEnum method is used to find the C# enum from a C++ enum integer value. The default one here takes
89 * advantage of the fact that most enums do not have initial values specified, so the lookup is fast. If initial
90 * values are specified then a lengthy linear search through all possible enums might occur. Specific typemaps could be
91 * written to possibly optimise this lookup by taking advantage of characteristics peculiar to the targeted enum.
92 * The special variable, $enumvalues, is replaced with a comma separated list of all the enum values.
94 %typemap(csbody) enum SWIGTYPE %{
95 public readonly int swigValue;
97 public static $csclassname swigToEnum(int swigValue) {
98 if (swigValue < swigValues.Length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
99 return swigValues[swigValue];
100 for (int i = 0; i < swigValues.Length; i++)
101 if (swigValues[i].swigValue == swigValue)
102 return swigValues[i];
103 throw new System.ArgumentOutOfRangeException("No enum $csclassname with value " + swigValue);
106 public override string ToString() {
110 private $csclassname(string swigName) {
111 this.swigName = swigName;
112 this.swigValue = swigNext++;
115 private $csclassname(string swigName, int swigValue) {
116 this.swigName = swigName;
117 this.swigValue = swigValue;
118 swigNext = swigValue+1;
121 private $csclassname(string swigName, $csclassname swigEnum) {
122 this.swigName = swigName;
123 this.swigValue = swigEnum.swigValue;
124 swigNext = this.swigValue+1;
127 private static $csclassname[] swigValues = { $enumvalues };
128 private static int swigNext = 0;
129 private readonly string swigName;