PageRenderTime 31ms CodeModel.GetById 26ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-26/SWIG/Examples/ruby/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
 3#include "example.h"
 4#include <stdio.h>
 5#include <stdlib.h>
 6
 7Vector operator+(const Vector &a, const Vector &b) {
 8  Vector r;
 9  r.x = a.x + b.x;
10  r.y = a.y + b.y;
11  r.z = a.z + b.z;
12  return r;
13}
14
15char *Vector::print() {
16  static char temp[512];
17  sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z);
18  return temp;
19}
20
21VectorArray::VectorArray(int size) {
22  items = new Vector[size];
23  maxsize = size;
24}
25
26VectorArray::~VectorArray() {
27  delete [] items;
28}
29
30Vector &VectorArray::operator[](int index) {
31  if ((index < 0) || (index >= maxsize)) {
32    printf("Panic! Array index out of bounds.\n");
33    exit(1);
34  }
35  return items[index];
36}
37
38int VectorArray::size() {
39  return maxsize;
40}
41