PageRenderTime 27ms CodeModel.GetById 18ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
C++ | 49 lines | 39 code | 8 blank | 2 comment | 3 complexity | eee927de7661d54627d891da1fb1e478 MD5 | raw file
 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
12Vector 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
20char *Vector::as_string() {
21  static char temp[512];
22  sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z);
23  return temp;
24}
25
26VectorArray::VectorArray(int size) {
27  items = new Vector[size];
28  maxsize = size;
29  printf("VectorArray new: self=%p\n",this);
30}
31
32VectorArray::~VectorArray() {
33  printf("VectorArray delete: self=%p\n",this);
34  delete [] items;
35}
36
37Vector &VectorArray::operator[](int index) {
38  printf("VectorArray: read[%d] self=%p\n",index,this);
39  if ((index < 0) || (index >= maxsize)) {
40    printf("Panic! Array index out of bounds.\n");
41    exit(1);
42  }
43  return items[index];
44}
45
46int VectorArray::size() {
47  printf("VectorArray: size %d self=%p\n",maxsize,this);
48  return maxsize;
49}