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:
Cheryl Foil 2008-08-18 18:30:21 +00:00
commit ad0a3d9179
9 changed files with 63 additions and 16 deletions

View file

@ -3,9 +3,12 @@
#include <cstdio>
#include <iostream>
/** Let's document class CALLBACK! */
/*! Let's document class CALLBACK!
/author Alfred
*/
class Callback {
public:
/** Information about Callback */
virtual ~Callback() { std::cout << "Callback::~Callback()" << std:: endl; }
virtual void run() { std::cout << "Callback::run()" << std::endl; }
};
@ -16,7 +19,7 @@ private:
Callback *_callback;
public:
Caller(): _callback(0) {}
~Caller() { delCallback(); }
~Caller() { delCallback(); }/**< Deletes Callback */
void delCallback() { delete _callback; _callback = 0; }
void setCallback(Callback *cb) { delCallback(); _callback = cb; }
void call() { if (_callback) _callback->run(); }

View file

@ -6,12 +6,15 @@
#include <string>
#include <cmath>
/**This is describiing class Employee */
/**This is describiing class Employee
/author Bob */
class Employee {
private:
std::string name;
public:
/** TEST */
/** Employee
\param n name of Employee
\throws some exception */
Employee(const char* n): name(n) {}
/**This is describing method getTitle */
virtual std::string getTitle() { return getPosition() + " " + getName(); }
@ -31,11 +34,15 @@ public:
class EmployeeList {
std::vector<Employee*> list;
public:
/** Initialises Employee List */
EmployeeList() {
list.push_back(new Employee("Bob"));
list.push_back(new Employee("Jane"));
list.push_back(new Manager("Ted"));
}
/** Add employee
* \param p employee p
* \return void */
void addEmployee(Employee *p) {
list.push_back(p);
std::cout << "New employee added. Current employees are:" << std::endl;

View file

@ -4,11 +4,16 @@
%{
#include <string.h>
/*! Structure Point */
typedef struct point {
int x;
int y;
} Point;
/*! Point_create Description
/param x integer x
/param y some integer y
/return a point */
Point *point_create(int x, int y) {
Point *p = (Point *) malloc(sizeof(Point));
@ -18,6 +23,11 @@ Point *point_create(int x, int y) {
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 buf[80];
@ -54,3 +64,4 @@ char *point_toString1(Point *p);
extern void free(void *memblock);
%native(point_toString2) char *point_toString2(Point *p);

View file

@ -7,10 +7,16 @@ extern void sub(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 */
/* 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);
%include cpointer.i
%pointer_functions(int, intp);
@ -28,3 +34,5 @@ extern int divide(int n, int d, int *r);

View file

@ -8,6 +8,12 @@
#include "example.h"
%}
/*! Class vector description
\author Fred
\exception something random
\since 1.0
\name ignoreme
\see something */
class Vector {
public:
Vector(double x, double y, double z);
@ -15,15 +21,18 @@ public:
char *print();
};
/* This helper function calls an overloaded operator */
/** This helper function calls an overloaded operator */
%inline %{
Vector addv(Vector &a, Vector &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 {
public:
VectorArray(int maxsize);
@ -44,3 +53,6 @@ public:

View file

@ -2,6 +2,10 @@
%module example
%inline %{
/*! Function foo
\param x int x
\param y int y
\return the gcd */
extern int gcd(int x, int y);
extern double Foo;
extern double Foo; /*!< description of double foo
%}

View file

@ -2,8 +2,15 @@
// 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 Vector
\author cmfoil
\sa something something */
template<class T> class vector {
T *v;
int sz;
@ -17,12 +24,12 @@ template<class T> class vector {
}
void set(int index, T &val) {
v[index] = val;
}
} /*!< Something about set */
#ifdef SWIG
%extend {
T getitem(int index) {
return $self->get(index);
}
}/*!< Something about get item */
void setitem(int index, T val) {
$self->set(index,val);
}