Extra Examples
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-cherylfoil@10790 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
719abc61cc
commit
ad0a3d9179
9 changed files with 63 additions and 16 deletions
|
|
@ -3,9 +3,12 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
/** Let's document class CALLBACK! */
|
/*! Let's document class CALLBACK!
|
||||||
|
/author Alfred
|
||||||
|
*/
|
||||||
class Callback {
|
class Callback {
|
||||||
public:
|
public:
|
||||||
|
/** Information about Callback */
|
||||||
virtual ~Callback() { std::cout << "Callback::~Callback()" << std:: endl; }
|
virtual ~Callback() { std::cout << "Callback::~Callback()" << std:: endl; }
|
||||||
virtual void run() { std::cout << "Callback::run()" << std::endl; }
|
virtual void run() { std::cout << "Callback::run()" << std::endl; }
|
||||||
};
|
};
|
||||||
|
|
@ -16,7 +19,7 @@ private:
|
||||||
Callback *_callback;
|
Callback *_callback;
|
||||||
public:
|
public:
|
||||||
Caller(): _callback(0) {}
|
Caller(): _callback(0) {}
|
||||||
~Caller() { delCallback(); }
|
~Caller() { delCallback(); }/**< Deletes Callback */
|
||||||
void delCallback() { delete _callback; _callback = 0; }
|
void delCallback() { delete _callback; _callback = 0; }
|
||||||
void setCallback(Callback *cb) { delCallback(); _callback = cb; }
|
void setCallback(Callback *cb) { delCallback(); _callback = cb; }
|
||||||
void call() { if (_callback) _callback->run(); }
|
void call() { if (_callback) _callback->run(); }
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,15 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
/**This is describiing class Employee */
|
/**This is describiing class Employee
|
||||||
|
/author Bob */
|
||||||
class Employee {
|
class Employee {
|
||||||
private:
|
private:
|
||||||
std::string name;
|
std::string name;
|
||||||
public:
|
public:
|
||||||
/** TEST */
|
/** Employee
|
||||||
|
\param n name of Employee
|
||||||
|
\throws some exception */
|
||||||
Employee(const char* n): name(n) {}
|
Employee(const char* n): name(n) {}
|
||||||
/**This is describing method getTitle */
|
/**This is describing method getTitle */
|
||||||
virtual std::string getTitle() { return getPosition() + " " + getName(); }
|
virtual std::string getTitle() { return getPosition() + " " + getName(); }
|
||||||
|
|
@ -31,11 +34,15 @@ public:
|
||||||
class EmployeeList {
|
class EmployeeList {
|
||||||
std::vector<Employee*> list;
|
std::vector<Employee*> list;
|
||||||
public:
|
public:
|
||||||
|
/** Initialises Employee List */
|
||||||
EmployeeList() {
|
EmployeeList() {
|
||||||
list.push_back(new Employee("Bob"));
|
list.push_back(new Employee("Bob"));
|
||||||
list.push_back(new Employee("Jane"));
|
list.push_back(new Employee("Jane"));
|
||||||
list.push_back(new Manager("Ted"));
|
list.push_back(new Manager("Ted"));
|
||||||
}
|
}
|
||||||
|
/** Add employee
|
||||||
|
* \param p employee p
|
||||||
|
* \return void */
|
||||||
void addEmployee(Employee *p) {
|
void addEmployee(Employee *p) {
|
||||||
list.push_back(p);
|
list.push_back(p);
|
||||||
std::cout << "New employee added. Current employees are:" << std::endl;
|
std::cout << "New employee added. Current employees are:" << std::endl;
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,16 @@
|
||||||
%{
|
%{
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
/*! Structure Point */
|
||||||
typedef struct point {
|
typedef struct point {
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
} Point;
|
} Point;
|
||||||
|
|
||||||
|
/*! Point_create Description
|
||||||
|
/param x integer x
|
||||||
|
/param y some integer y
|
||||||
|
/return a point */
|
||||||
|
|
||||||
Point *point_create(int x, int y) {
|
Point *point_create(int x, int y) {
|
||||||
Point *p = (Point *) malloc(sizeof(Point));
|
Point *p = (Point *) malloc(sizeof(Point));
|
||||||
|
|
@ -18,6 +23,11 @@ Point *point_create(int x, int y) {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Point_create Description
|
||||||
|
/param format the format
|
||||||
|
/param p some p
|
||||||
|
/return a character string of the point p */
|
||||||
|
|
||||||
static char *point_toString(char *format, Point *p) {
|
static char *point_toString(char *format, Point *p) {
|
||||||
static char buf[80];
|
static char buf[80];
|
||||||
|
|
||||||
|
|
@ -54,3 +64,4 @@ char *point_toString1(Point *p);
|
||||||
extern void free(void *memblock);
|
extern void free(void *memblock);
|
||||||
|
|
||||||
%native(point_toString2) char *point_toString2(Point *p);
|
%native(point_toString2) char *point_toString2(Point *p);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,16 @@ extern void sub(int *, int *, int *);
|
||||||
extern int divide(int, int, int *);
|
extern int divide(int, int, int *);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
/* This example illustrates a couple of different techniques
|
/** This example illustrates a couple of different techniques
|
||||||
for manipulating C pointers */
|
for manipulating C pointers */
|
||||||
|
|
||||||
/* First we'll use the pointer library */
|
/* First we'll use the pointer library */
|
||||||
|
|
||||||
|
/*! function add
|
||||||
|
\param x some int x
|
||||||
|
\param y some int y
|
||||||
|
\param result some result
|
||||||
|
*/
|
||||||
extern void add(int *x, int *y, int *result);
|
extern void add(int *x, int *y, int *result);
|
||||||
%include cpointer.i
|
%include cpointer.i
|
||||||
%pointer_functions(int, intp);
|
%pointer_functions(int, intp);
|
||||||
|
|
@ -28,3 +34,5 @@ extern int divide(int n, int d, int *r);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,12 @@
|
||||||
#include "example.h"
|
#include "example.h"
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
/*! Class vector description
|
||||||
|
\author Fred
|
||||||
|
\exception something random
|
||||||
|
\since 1.0
|
||||||
|
\name ignoreme
|
||||||
|
\see something */
|
||||||
class Vector {
|
class Vector {
|
||||||
public:
|
public:
|
||||||
Vector(double x, double y, double z);
|
Vector(double x, double y, double z);
|
||||||
|
|
@ -15,15 +21,18 @@ public:
|
||||||
char *print();
|
char *print();
|
||||||
};
|
};
|
||||||
|
|
||||||
/* This helper function calls an overloaded operator */
|
/** This helper function calls an overloaded operator */
|
||||||
%inline %{
|
%inline %{
|
||||||
Vector addv(Vector &a, Vector &b) {
|
Vector addv(Vector &a, Vector &b) {
|
||||||
return a+b;
|
return a+b;
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
/* Wrapper around an array of vectors class */
|
/*! Class Vector Array
|
||||||
|
\exception something random
|
||||||
|
\since 1.3
|
||||||
|
\see something
|
||||||
|
\author Fred */
|
||||||
class VectorArray {
|
class VectorArray {
|
||||||
public:
|
public:
|
||||||
VectorArray(int maxsize);
|
VectorArray(int maxsize);
|
||||||
|
|
@ -44,3 +53,6 @@ public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,10 @@
|
||||||
%module example
|
%module example
|
||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
|
/*! Function foo
|
||||||
|
\param x int x
|
||||||
|
\param y int y
|
||||||
|
\return the gcd */
|
||||||
extern int gcd(int x, int y);
|
extern int gcd(int x, int y);
|
||||||
extern double Foo;
|
extern double Foo; /*!< description of double foo
|
||||||
%}
|
%}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,15 @@
|
||||||
|
|
||||||
// Some template definitions
|
// Some template definitions
|
||||||
|
|
||||||
|
/*! Template class T
|
||||||
|
\author cmfoil
|
||||||
|
\sa something something */
|
||||||
|
|
||||||
template<class T> T max(T a, T b) { return a>b ? a : b; }
|
template<class T> T max(T a, T b) { return a>b ? a : b; }
|
||||||
|
|
||||||
|
/*! Template class Vector
|
||||||
|
\author cmfoil
|
||||||
|
\sa something something */
|
||||||
template<class T> class vector {
|
template<class T> class vector {
|
||||||
T *v;
|
T *v;
|
||||||
int sz;
|
int sz;
|
||||||
|
|
@ -17,12 +24,12 @@ template<class T> class vector {
|
||||||
}
|
}
|
||||||
void set(int index, T &val) {
|
void set(int index, T &val) {
|
||||||
v[index] = val;
|
v[index] = val;
|
||||||
}
|
} /*!< Something about set */
|
||||||
#ifdef SWIG
|
#ifdef SWIG
|
||||||
%extend {
|
%extend {
|
||||||
T getitem(int index) {
|
T getitem(int index) {
|
||||||
return $self->get(index);
|
return $self->get(index);
|
||||||
}
|
}/*!< Something about get item */
|
||||||
void setitem(int index, T val) {
|
void setitem(int index, T val) {
|
||||||
$self->set(index,val);
|
$self->set(index,val);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,5 +26,3 @@ extern void sub(int *INPUT, int *INPUT, int *OUTPUT);
|
||||||
extern int divide(int n, int d, int *r);
|
extern int divide(int n, int d, int *r);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,3 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue