PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/enums.i

#
Swig | 102 lines | 75 code | 22 blank | 5 comment | 0 complexity | 7ba81122001a5004d7a142eea7545f3a MD5 | raw file
  1/* Test whether varios enums in C. */
  2
  3%module "enums"
  4
  5/* Suppress warning messages from the Ruby module for all of the following.. */
  6%warnfilter(SWIGWARN_RUBY_WRONG_NAME) boo;
  7%warnfilter(SWIGWARN_RUBY_WRONG_NAME) hoo;
  8%warnfilter(SWIGWARN_RUBY_WRONG_NAME) globalinstance1;
  9%warnfilter(SWIGWARN_RUBY_WRONG_NAME) globalinstance2;
 10%warnfilter(SWIGWARN_RUBY_WRONG_NAME) globalinstance3;
 11%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK);
 12
 13%inline %{
 14
 15typedef enum { 
 16    CSP_ITERATION_FWD,
 17    CSP_ITERATION_BWD = 11
 18} foo1;
 19
 20typedef enum foo2 {
 21    ABCDE = 0,
 22    FGHJI = 1
 23} foo3;
 24
 25void
 26bar1(foo1 x) {}
 27
 28void
 29bar2(enum foo2 x) {}
 30
 31void 
 32bar3(foo3 x) {}
 33
 34enum sad { boo, hoo = 5 };
 35
 36#ifdef __cplusplus /* For Octave and g++ which compiles C test code as C++ */
 37extern "C" {
 38#endif
 39/* Unnamed enum instance */
 40enum { globalinstance1, globalinstance2, globalinstance3 = 30 } GlobalInstance;
 41#ifdef __cplusplus
 42}
 43#endif
 44
 45/* Anonymous enum */
 46enum { AnonEnum1, AnonEnum2 = 100 };
 47
 48%}
 49
 50%inline %{
 51
 52typedef struct _Foo {
 53  enum { BAR1, BAR2 } e;
 54} Foo;
 55
 56%}
 57
 58  
 59%warnfilter(SWIGWARN_RUBY_WRONG_NAME) _iFoo;
 60
 61#ifdef SWIGD
 62/* Work around missing support for proper char quoting due to parser shortcomings. */
 63%dconstvalue("'a'") _iFoo::Char;
 64#endif
 65
 66#ifndef __cplusplus
 67%inline %{
 68typedef struct _iFoo 
 69{ 
 70    enum { 
 71      Phoo = +50,
 72      Char = 'a'
 73    } e;
 74} iFoo; 
 75%}
 76#else
 77%inline %{
 78struct iFoo 
 79{ 
 80    enum { 
 81      Phoo = +50,
 82      Char = 'a'
 83    }; 
 84}; 
 85%}
 86#endif
 87
 88// enum declaration and initialization
 89%inline %{
 90enum Exclamation {
 91  goodness,
 92  gracious,
 93  me
 94} enumInstance = me;
 95
 96enum ContainYourself {
 97  slap = 10,
 98  mine,
 99  thigh
100} Slap = slap, Mine = mine, Thigh = thigh, *pThigh = &Thigh, arrayContainYourself[3] = {slap, mine, thigh};
101%}
102