PageRenderTime 30ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

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