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

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

#
Swig | 200 lines | 133 code | 58 blank | 9 comment | 0 complexity | db8e8c2d335923d1a133b58102311277 MD5 | raw file
  1%module(directors="1") director_abstract
  2%{
  3#include <string>
  4
  5class Foo {
  6public:
  7	virtual ~Foo() {}
  8	virtual std::string ping() = 0;
  9	virtual std::string pong() { return "Foo::pong();" + ping(); }
 10};
 11
 12%}
 13
 14%include <std_string.i>
 15
 16%feature("director") Foo;
 17
 18class Foo {
 19public:
 20  virtual ~Foo() {}
 21  virtual std::string ping() = 0;
 22  virtual std::string pong() { return "Foo::pong();" + ping(); }
 23};
 24
 25
 26
 27%feature("director");
 28
 29%inline %{
 30class Example0
 31{
 32protected:
 33  int xsize, ysize;
 34  
 35public:
 36  
 37  Example0(int x, int y)
 38    : xsize(x), ysize(y) { }
 39
 40  Example0() { }
 41
 42public:
 43  virtual ~Example0() {}
 44  
 45  int  GetXSize() const { return xsize; }
 46  
 47  // pure virtual methods that must be overridden
 48  virtual int Color(unsigned char r, unsigned char g, unsigned char b)  
 49  {
 50    return 0;
 51  }
 52  
 53
 54  static int get_color(Example0 *ptr, unsigned char r, 
 55		       unsigned char g, unsigned char b) {
 56    return ptr->Color(r, g, b);
 57  }
 58};
 59
 60class Example1
 61{
 62protected:
 63  int xsize, ysize;
 64  
 65protected:
 66  /* this shouldn't be emitted, unless 'dirprot' is used, since they
 67   is already a public constructor */
 68  
 69  Example1(int x, int y)
 70    : xsize(x), ysize(y) { }
 71
 72public:
 73  Example1() { }
 74
 75public:
 76  virtual ~Example1() {}
 77  
 78  int  GetXSize() const { return xsize; }
 79  
 80  // pure virtual methods that must be overridden
 81  virtual int Color(unsigned char r, unsigned char g, unsigned char b)  = 0;
 82
 83  static int get_color(Example1 *ptr, unsigned char r, 
 84		       unsigned char g, unsigned char b) {
 85    return ptr->Color(r, g, b);
 86  }
 87  
 88
 89};
 90
 91
 92class Example2
 93{
 94protected:
 95 int xsize, ysize;
 96
 97protected:
 98  /* there is no default constructor, hence, all protected constructors
 99     should be emitted */
100
101  Example2(int x)
102  {
103  }
104
105  Example2(int x, int y)
106    : xsize(x), ysize(y) { }
107
108public:
109
110  virtual ~Example2() {}
111
112  int  GetXSize() const { return xsize; }
113
114  // pure virtual methods that must be overridden
115  virtual int Color(unsigned char r, unsigned char g, unsigned char b) = 0;
116
117  static int get_color(Example2 *ptr, unsigned char r, 
118		       unsigned char g, unsigned char b) {
119    return ptr->Color(r, g, b);
120  }
121};
122
123class Example4
124{
125protected:
126 int xsize, ysize;
127
128protected:
129
130  Example4()
131  {
132  }
133
134  /* this is not emitted, unless dirprot is used */
135  Example4(int x, int y)
136    : xsize(x), ysize(y) { }
137
138public:
139
140  virtual ~Example4() {}
141
142  int  GetXSize() const { return xsize; }
143
144  // pure virtual methods that must be overridden
145  virtual int Color(unsigned char r, unsigned char g, unsigned char b) = 0;
146
147  static int get_color(Example4 *ptr, unsigned char r, 
148		       unsigned char g, unsigned char b) {
149    return ptr->Color(r, g, b);
150  }
151};
152
153namespace ns 
154{
155  template <class T>
156  class Example3
157  {
158  protected:
159    /* the default constructor is always emitter, even when protected,
160        having another public constructor, and 'dirprot' is not used.
161        This is just for Java compatibility */
162    Example3()
163    {
164    }
165
166    /* this is no emitted, unless dirprot mode is used */
167    Example3(int x) { }
168
169  public:
170    
171    Example3(int x, int y) { }
172
173    virtual ~Example3() {}
174    
175    // pure virtual methods that must be overridden
176    virtual int Color(unsigned char r, unsigned char g, unsigned char b) = 0;    
177
178    static int get_color(Example3 *ptr, unsigned char r, 
179			 unsigned char g, unsigned char b) {
180      return ptr->Color(r, g, b);
181    }
182  };
183}    
184%}
185
186%template(Example3_i) ns::Example3<int>;
187
188
189%inline %{
190  struct A{
191    virtual ~A() {}
192    friend  int g(A* obj);    
193  protected:
194    A(const A&){}
195    virtual int f() = 0;
196  };
197  
198  int g(A* obj) {return 1;}
199
200%}