Permalink
Browse files

Improve the class example for several languages.

Fix numerous inaccuracies in index.html (where it exists) and eliminate
unnecessary differences between the example code being wrapped.
  • Loading branch information...
1 parent 2f3bf14 commit 34c97ffdbd528f4c53873ccc8f60238579c2a22d @ojwb ojwb committed Feb 23, 2014
@@ -1,4 +1,4 @@
-/* File : example.c */
+/* File : example.cxx */
#include "example.h"
#define M_PI 3.14159265358979323846
@@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) {
int Shape::nshapes = 0;
-double Circle::area(void) {
+double Circle::area() {
return M_PI*radius*radius;
}
-double Circle::perimeter(void) {
+double Circle::perimeter() {
return 2*M_PI*radius;
}
-double Square::area(void) {
+double Square::area() {
return width*width;
}
-double Square::perimeter(void) {
+double Square::perimeter() {
return 4*width;
}
@@ -7,33 +7,28 @@ class Shape {
}
virtual ~Shape() {
nshapes--;
- };
- double x, y;
+ }
+ double x, y;
void move(double dx, double dy);
- virtual double area(void) = 0;
- virtual double perimeter(void) = 0;
+ virtual double area() = 0;
+ virtual double perimeter() = 0;
static int nshapes;
};
class Circle : public Shape {
private:
double radius;
public:
- Circle(double r) : radius(r) { };
- virtual double area(void);
- virtual double perimeter(void);
+ Circle(double r) : radius(r) { }
+ virtual double area();
+ virtual double perimeter();
};
class Square : public Shape {
private:
double width;
public:
- Square(double w) : width(w) { };
- virtual double area(void);
- virtual double perimeter(void);
+ Square(double w) : width(w) { }
+ virtual double area();
+ virtual double perimeter();
};
-
-
-
-
-
@@ -32,8 +32,8 @@
}
virtual ~Shape() {
nshapes--;
- };
- double x, y;
+ }
+ double x, y;
void move(double dx, double dy);
virtual double area() = 0;
virtual double perimeter() = 0;
@@ -44,7 +44,7 @@
private:
double radius;
public:
- Circle(double r) : radius(r) { };
+ Circle(double r) : radius(r) { }
virtual double area();
virtual double perimeter();
};
@@ -53,7 +53,7 @@
private:
double width;
public:
- Square(double w) : width(w) { };
+ Square(double w) : width(w) { }
virtual double area();
virtual double perimeter();
};
@@ -146,50 +146,15 @@
<ul>
<li>This high-level interface using proxy classes is not the only way to handle C++ code.
-A low level interface using c functions to access member variables and member functions is the alternative SWIG
-approach. This entails passing around the c pointer or c++ 'this' pointer and as such it is not difficult to crash the JVM.
+A low level interface using C functions to access member variables and member functions is the alternative SWIG
+approach. This entails passing around the C pointer or C++ 'this' pointer and as such it is not difficult to crash the JVM.
The abstraction of the underlying pointer by the java proxy classes far better fits the java programming paradigm.
<p>
-<li>SWIG *does* know how to properly perform upcasting of objects in an inheritance
+<li>SWIG <b>does</b> know how to properly perform upcasting of objects in an inheritance
hierarchy (including multiple inheritance). However Java classes can only derive from one base class so multiple inheritance
is not implemented. Java classes can implement more than one interface so there is scope for improvement in the future.
-<p>
-<li>A wide variety of C++ features are not currently supported by SWIG. Here is the
-short and incomplete list:
-
-<p>
-<ul>
-<li>Overloaded methods and functions. SWIG wrappers don't know how to resolve name
-conflicts so you must give an alternative name to any overloaded method name using the
-%name directive like this:
-
-<blockquote>
-<pre>
-void foo(int a);
-%name(foo2) void foo(double a, double b);
-</pre>
-</blockquote>
-
-<p>
-<li>Overloaded operators. Not supported at all. The only workaround for this is
-to write a helper function. For example:
-
-<blockquote>
-<pre>
-%inline %{
- Vector *vector_add(Vector *a, Vector *b) {
- ... whatever ...
- }
-%}
-</pre>
-</blockquote>
-
-<p>
-<li>Namespaces. Not supported at all. Won't be supported until SWIG2.0 (if at all).
-
-</ul>
</ul>
<hr>
@@ -1,4 +1,4 @@
-/* File : example.c */
+/* File : example.cxx */
#include "example.h"
#define M_PI 3.14159265358979323846
@@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) {
int Shape::nshapes = 0;
-double Circle::area(void) {
+double Circle::area() {
return M_PI*radius*radius;
}
-double Circle::perimeter(void) {
+double Circle::perimeter() {
return 2*M_PI*radius;
}
-double Square::area(void) {
+double Square::area() {
return width*width;
}
-double Square::perimeter(void) {
+double Square::perimeter() {
return 4*width;
}
@@ -7,41 +7,36 @@ class Shape {
}
virtual ~Shape() {
nshapes--;
- };
- double x, y;
+ }
+ double x, y;
void move(double dx, double dy);
- virtual double area(void) = 0;
- virtual double perimeter(void) = 0;
+ virtual double area() = 0;
+ virtual double perimeter() = 0;
static int nshapes;
};
class Circle : public Shape {
private:
double radius;
public:
- Circle(double r) : radius(r) { };
- virtual double area(void);
- virtual double perimeter(void);
+ Circle(double r) : radius(r) { }
+ virtual double area();
+ virtual double perimeter();
};
class Square : public Shape {
private:
double width;
public:
- Square(double w) : width(w) { };
- virtual double area(void);
- virtual double perimeter(void);
+ Square(double w) : width(w) { }
+ virtual double area();
+ virtual double perimeter();
};
typedef Square TSquare;
class CFoo
{
public:
- static Square MakeSquare(void) {return Square(4.0);};
- static TSquare MakeTSquare(void) {return Square(4.0);};
+ static Square MakeSquare(void) {return Square(4.0);}
+ static TSquare MakeTSquare(void) {return Square(4.0);}
};
-
-
-
-
-
@@ -6,6 +6,5 @@
%}
/* Let's just grab the original header file here */
-
%include "example.h"
Oops, something went wrong.

2 comments on commit 34c97ff

Owner

wsfulton replied Feb 23, 2014

Thanks for this tidy up. I would like to keep this example consistent across all languages. Are you planning on tidying up the remaining languages?

grep "area(void)" Examples/*/*/*.

Shows quite a few more with the same kind of issues.

Member

ojwb replied Feb 23, 2014

Please sign in to comment.