PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/rel-1-3-15/SWIG/Examples/perl5/reference/example.cxx

#
C++ | 41 lines | 32 code | 8 blank | 1 comment | 2 complexity | d413ab5f3aa59934acb6a678aeca301e MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* File : example.cxx */
  2. #include "example.h"
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. Vector operator+(const Vector &a, const Vector &b) {
  6. Vector r;
  7. r.x = a.x + b.x;
  8. r.y = a.y + b.y;
  9. r.z = a.z + b.z;
  10. return r;
  11. }
  12. char *Vector::print() {
  13. static char temp[512];
  14. sprintf(temp,"Vector %x (%g,%g,%g)", this, x,y,z);
  15. return temp;
  16. }
  17. VectorArray::VectorArray(int size) {
  18. items = new Vector[size];
  19. maxsize = size;
  20. }
  21. VectorArray::~VectorArray() {
  22. delete [] items;
  23. }
  24. Vector &VectorArray::operator[](int index) {
  25. if ((index < 0) || (index >= maxsize)) {
  26. printf("Panic! Array index out of bounds.\n");
  27. exit(1);
  28. }
  29. return items[index];
  30. }
  31. int VectorArray::size() {
  32. return maxsize;
  33. }