PageRenderTime 48ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/php/reference/example.cxx

#
C++ | 49 lines | 39 code | 8 blank | 2 comment | 3 complexity | eee927de7661d54627d891da1fb1e478 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::as_string() {
  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. printf("VectorArray new: self=%p\n",this);
  25. }
  26. VectorArray::~VectorArray() {
  27. printf("VectorArray delete: self=%p\n",this);
  28. delete [] items;
  29. }
  30. Vector &VectorArray::operator[](int index) {
  31. printf("VectorArray: read[%d] self=%p\n",index,this);
  32. if ((index < 0) || (index >= maxsize)) {
  33. printf("Panic! Array index out of bounds.\n");
  34. exit(1);
  35. }
  36. return items[index];
  37. }
  38. int VectorArray::size() {
  39. printf("VectorArray: size %d self=%p\n",maxsize,this);
  40. return maxsize;
  41. }