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

« back to all changes in this revision

Viewing changes to Examples/test-suite/pointer_cxx.i

  • 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.i */
 
2
%module example
 
3
 
 
4
/* This example illustrates a couple of different techniques
 
5
   for manipulating C pointers */
 
6
 
 
7
/* First we'll use the pointer library */
 
8
extern void add(int *x, int *y, int *result);
 
9
 
 
10
#ifndef SWIGGUILE
 
11
#ifndef SWIGJAVA
 
12
#ifndef SWIGMZSCHEME
 
13
%include pointer.i
 
14
#endif
 
15
#endif
 
16
#endif
 
17
 
 
18
/* Next we'll use some typemaps */
 
19
 
 
20
%include typemaps.i
 
21
extern void sub(int *INPUT, int *INPUT, int *OUTPUT);
 
22
 
 
23
/* Next we'll use typemaps and the %apply directive */
 
24
 
 
25
%apply int *OUTPUT { int *r };
 
26
extern int divide(int n, int d, int *r);
 
27
 
 
28
/* Try using pointers that are used as input and output */
 
29
%apply int *INOUT {int *z};
 
30
extern void negate(int *z);
 
31
 
 
32
%{
 
33
void add(int *x, int *y, int *result) {
 
34
  *result = *x + *y;
 
35
}
 
36
 
 
37
void sub(int *x, int *y, int *result) {
 
38
  *result = *x - *y;
 
39
}
 
40
 
 
41
int divide(int n, int d, int *r) {
 
42
   int q;
 
43
   q = n/d;
 
44
   *r = n - q*d;
 
45
   return q;
 
46
}
 
47
 
 
48
void negate(int *z) {
 
49
    *z = -(*z);
 
50
}
 
51
 
 
52
%}
 
53
 
 
54