~ubuntu-branches/ubuntu/maverick/swig1.3/maverick

« back to all changes in this revision

Viewing changes to Examples/ruby/reference/example.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Landschoff
  • Date: 2002-03-29 01:56:07 UTC
  • Revision ID: james.westby@ubuntu.com-20020329015607-c0wt03xu8oy9ioj7
Tags: upstream-1.3.11
ImportĀ upstreamĀ versionĀ 1.3.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* File : example.cxx */
 
2
 
 
3
#include "example.h"
 
4
#include <stdio.h>
 
5
#include <stdlib.h>
 
6
 
 
7
Vector 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
 
 
15
char *Vector::print() {
 
16
  static char temp[512];
 
17
  sprintf(temp,"Vector %x (%g,%g,%g)", this, x,y,z);
 
18
  return temp;
 
19
}
 
20
 
 
21
VectorArray::VectorArray(int size) {
 
22
  items = new Vector[size];
 
23
  maxsize = size;
 
24
}
 
25
 
 
26
VectorArray::~VectorArray() {
 
27
  delete [] items;
 
28
}
 
29
 
 
30
Vector &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
 
 
38
int VectorArray::size() {
 
39
  return maxsize;
 
40
}
 
41