import source from 1.3.40
[external/swig.git] / Examples / perl5 / reference / example.cxx
1 /* File : example.cxx */
2
3 /* Deal with Microsoft's attempt at deprecating C standard runtime functions */
4 #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER)
5 # define _CRT_SECURE_NO_DEPRECATE
6 #endif
7
8 #include "example.h"
9 #include <stdio.h>
10 #include <stdlib.h>
11
12 Vector operator+(const Vector &a, const Vector &b) {
13   Vector r;
14   r.x = a.x + b.x;
15   r.y = a.y + b.y;
16   r.z = a.z + b.z;
17   return r;
18 }
19
20 char *Vector::print() {
21   static char temp[512];
22   sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z);
23   return temp;
24 }
25
26 VectorArray::VectorArray(int size) {
27   items = new Vector[size];
28   maxsize = size;
29 }
30
31 VectorArray::~VectorArray() {
32   delete [] items;
33 }
34
35 Vector &VectorArray::operator[](int index) {
36   if ((index < 0) || (index >= maxsize)) {
37     printf("Panic! Array index out of bounds.\n");
38     exit(1);
39   }
40   return items[index];
41 }
42
43 int VectorArray::size() {
44   return maxsize;
45 }
46