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

/tags/rel-1-3-25/SWIG/Examples/tcl/reference/example.cxx

#
C++ | 41 lines | 32 code | 8 blank | 1 comment | 2 complexity | 73a3194de0bbbe86d865e67435e80a05 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 %p (%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. }