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

/trunk/Examples/php/reference/example.i

#
Swig | 47 lines | 30 code | 8 blank | 9 comment | 0 complexity | 8da5545a1bfb854463e00c33f0d914ff MD5 | raw file
 1/* File : example.i */
 2
 3/* This example has nothing to do with references but the name is used by all
 4 * the other languages so it's hard to rename to something more meaningful.
 5 *
 6 * Mostly it shows how to use %extend.
 7 */
 8
 9%module example
10
11%{
12#include "example.h"
13%}
14
15class Vector {
16public:
17    Vector(double x, double y, double z);
18   ~Vector();
19    char *as_string();
20};
21
22/* This helper function calls an overloaded operator */
23%inline %{
24Vector addv(Vector &a, Vector &b) {
25  return a+b;
26}
27%}
28
29/* Wrapper around an array of vectors class */
30
31class VectorArray {
32public:
33  VectorArray(int maxsize);
34  ~VectorArray();
35  int size();
36  
37 /*  This wrapper provides an alternative to the [] operator */
38  %extend {
39    Vector &get(int index) {
40      printf("VectorArray extended get: %p %d\n",$self,index);
41      return (*$self)[index];
42    }
43    void set(int index, Vector &a) {
44      (*$self)[index] = a;
45    }
46  }
47};