PageRenderTime 37ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/perl5/reference/example.cxx

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