PageRenderTime 11ms CodeModel.GetById 9ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Swig | 103 lines | 83 code | 20 blank | 0 comment | 0 complexity | f852310808e2628699bb97203e356321 MD5 | raw file
  1%module extend_variable
  2
  3// Tests %extend for variables
  4
  5%inline %{
  6class ExtendMe {
  7  double var;
  8public:
  9  ExtendMe() : var(0.0) {}
 10  bool get(double &d) {
 11    d = var;
 12    return true;
 13  }
 14  bool set(const double &d) {
 15    var = d;
 16    return true;
 17  }
 18};
 19%}
 20
 21%extend ExtendMe {
 22  double ExtendVar;
 23};
 24
 25%{
 26// If possible, all language modules should use this naming format for consistency
 27void ExtendMe_ExtendVar_set(ExtendMe *thisptr, double value) {
 28  thisptr->set(value);
 29}
 30double ExtendMe_ExtendVar_get(ExtendMe *thisptr) {
 31  double value = 0;
 32  thisptr->get(value);
 33  return value;
 34}
 35%}
 36
 37
 38%{
 39  class Foo 
 40  {
 41  };
 42%}
 43
 44#if SWIGJAVA
 45%javaconst(1) AllBarOne;
 46#elif SWIGCSHARP
 47%csconst(1) AllBarOne;
 48#endif
 49
 50
 51class Foo {
 52  public:
 53    %extend {
 54        static const int Bar = 42;
 55        static const int AllBarOne = 4422;
 56        static const int StaticConstInt;
 57        static int StaticInt;
 58    }
 59}; 
 60  
 61%{
 62  int globalVariable = 1111;
 63
 64  void Foo_StaticInt_set(int value) {
 65    globalVariable = value;
 66  }
 67
 68  int Foo_StaticInt_get() {
 69    return globalVariable;
 70  }
 71
 72  int Foo_StaticConstInt_get() {
 73    static int var = 2222;
 74    return var;
 75  }
 76%}
 77
 78%inline {
 79  namespace ns1 
 80  {
 81    struct Bar
 82    {
 83    }
 84    ;
 85  }
 86}
 87
 88%{
 89  int ns1_Bar_x_get(ns1::Bar *self) {
 90    return 1;
 91  }
 92
 93  void ns1_Bar_x_set(ns1::Bar *self, int x) {
 94  }
 95%}
 96  
 97%extend ns1::Bar 
 98{
 99  int x;
100}
101
102
103