Consistent formatting of example code in the docs
This commit is contained in:
parent
129ef8ea8f
commit
268b942865
25 changed files with 1705 additions and 1714 deletions
|
|
@ -1166,7 +1166,6 @@ SWIGEXPORT void SWIGSTDCALL CSharp_negativesonly(int jarg1) {
|
||||||
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, e.what());
|
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, e.what());
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -1233,7 +1232,6 @@ SWIGEXPORT void SWIGSTDCALL CSharp_evensonly(int jarg1) {
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -229,8 +229,9 @@ void foo(SomeClass arg) {
|
||||||
|
|
||||||
%newobject bar();
|
%newobject bar();
|
||||||
SomeClass *bar();
|
SomeClass *bar();
|
||||||
%}</pre></div>
|
%}
|
||||||
<p>The code generated for <tt>foo()</tt> and <tt>bar()</tt> looks like this:</p>
|
</pre></div>
|
||||||
|
<p>The code generated for <tt>foo()</tt> and <tt>bar()</tt> looks like this:</p>
|
||||||
<div class="targetlang"><pre>
|
<div class="targetlang"><pre>
|
||||||
SomeClass foo() {
|
SomeClass foo() {
|
||||||
return new SomeClass(example_im.foo(), false);
|
return new SomeClass(example_im.foo(), false);
|
||||||
|
|
|
||||||
|
|
@ -1109,7 +1109,7 @@ Typesafe enums have their advantages over using plain integers in that they can
|
||||||
However, there are limitations. For example, they cannot be used in switch statements and serialization is an issue.
|
However, there are limitations. For example, they cannot be used in switch statements and serialization is an issue.
|
||||||
Please look at the following references for further information:
|
Please look at the following references for further information:
|
||||||
|
|
||||||
http://java.sun.com/developer/Books/shiftintojava/page1.html#replaceenums
|
http://java.sun.com/developer/Books/shiftintojava/page1.html#replaceenums
|
||||||
<a href="http://java.sun.com/developer/Books/shiftintojava/page1.html#replaceenums">Replace Enums with Classes</a> in <i>Effective Java Programming</i> on the Sun website,
|
<a href="http://java.sun.com/developer/Books/shiftintojava/page1.html#replaceenums">Replace Enums with Classes</a> in <i>Effective Java Programming</i> on the Sun website,
|
||||||
<a href="http://www.javaworld.com/javaworld/jw-07-1997/jw-07-enumerated.html">Create enumerated constants in Java</a> JavaWorld article,
|
<a href="http://www.javaworld.com/javaworld/jw-07-1997/jw-07-enumerated.html">Create enumerated constants in Java</a> JavaWorld article,
|
||||||
<a href="http://www.javaworld.com/javaworld/javatips/jw-javatip133.html">Java Tip 133: More on typesafe enums</a> and
|
<a href="http://www.javaworld.com/javaworld/javatips/jw-javatip133.html">Java Tip 133: More on typesafe enums</a> and
|
||||||
|
|
@ -4460,7 +4460,7 @@ We can catch the C++ exception and rethrow it as a Java exception like this:</p>
|
||||||
}
|
}
|
||||||
|
|
||||||
class FooClass {
|
class FooClass {
|
||||||
public:
|
public:
|
||||||
FooClass *getitem(int index); // Might throw std::out_of_range exception
|
FooClass *getitem(int index); // Might throw std::out_of_range exception
|
||||||
...
|
...
|
||||||
};
|
};
|
||||||
|
|
@ -5604,12 +5604,12 @@ The following code snippet might aid in understand aliasing rules better:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="code"><pre>
|
<div class="code"><pre>
|
||||||
short a;
|
short a;
|
||||||
short* pa = 0;
|
short* pa = 0;
|
||||||
int i = 0x1234;
|
int i = 0x1234;
|
||||||
|
|
||||||
a = (short)i; /* okay */
|
a = (short)i; /* okay */
|
||||||
a = *(short*)&i; /* breaks aliasing rules */
|
a = *(short*)&i; /* breaks aliasing rules */
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
@ -5618,15 +5618,15 @@ In SWIG, the "in" and "out" typemaps for pointers are typically
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="code"><pre>
|
<div class="code"><pre>
|
||||||
%typemap(in) struct Foo * %{
|
%typemap(in) struct Foo * %{
|
||||||
$1 = *(struct Foo **)&$input; /* cast jlong into C ptr */
|
$1 = *(struct Foo **)&$input; /* cast jlong into C ptr */
|
||||||
%}
|
%}
|
||||||
%typemap(out) struct Bar * %{
|
%typemap(out) struct Bar * %{
|
||||||
*(struct Bar **)&$result = $1; /* cast C ptr into jlong */
|
*(struct Bar **)&$result = $1; /* cast C ptr into jlong */
|
||||||
%}
|
%}
|
||||||
struct Bar {...};
|
struct Bar {...};
|
||||||
struct Foo {...};
|
struct Foo {...};
|
||||||
struct Bar * FooBar(struct Foo *f);
|
struct Bar * FooBar(struct Foo *f);
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
@ -7656,11 +7656,11 @@ The following Java code shows how we intend the code to be used:
|
||||||
|
|
||||||
<div class="code">
|
<div class="code">
|
||||||
<pre>
|
<pre>
|
||||||
Butler jeeves = new Butler();
|
Butler jeeves = new Butler();
|
||||||
example.HireButler(jeeves);
|
example.HireButler(jeeves);
|
||||||
System.out.println("Greeting: " + jeeves.getGreeting());
|
System.out.println("Greeting: " + jeeves.getGreeting());
|
||||||
System.out.println("Availability: " + jeeves.getHoursAvailable() + " hours per day");
|
System.out.println("Availability: " + jeeves.getHoursAvailable() + " hours per day");
|
||||||
example.FireButler(jeeves);
|
example.FireButler(jeeves);
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -7818,12 +7818,12 @@ and the following usage from Java after running the code through SWIG:
|
||||||
|
|
||||||
<div class="code">
|
<div class="code">
|
||||||
<pre>
|
<pre>
|
||||||
Wheel wheel = new Bike(10).getWheel();
|
Wheel wheel = new Bike(10).getWheel();
|
||||||
System.out.println("wheel size: " + wheel.getSize());
|
System.out.println("wheel size: " + wheel.getSize());
|
||||||
// Simulate a garbage collection
|
// Simulate a garbage collection
|
||||||
System.gc();
|
System.gc();
|
||||||
System.runFinalization();
|
System.runFinalization();
|
||||||
System.out.println("wheel size: " + wheel.getSize());
|
System.out.println("wheel size: " + wheel.getSize());
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -7938,10 +7938,10 @@ and usage from C++
|
||||||
|
|
||||||
<div class="code">
|
<div class="code">
|
||||||
<pre>
|
<pre>
|
||||||
Container container;
|
Container container;
|
||||||
Element element(20);
|
Element element(20);
|
||||||
container.setElement(&element);
|
container.setElement(&element);
|
||||||
cout << "element.value: " << container.getElement()->value << endl;
|
cout << "element.value: " << container.getElement()->value << endl;
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -7951,9 +7951,9 @@ and more or less equivalent usage from Java
|
||||||
|
|
||||||
<div class="code">
|
<div class="code">
|
||||||
<pre>
|
<pre>
|
||||||
Container container = new Container();
|
Container container = new Container();
|
||||||
container.setElement(new Element(20));
|
container.setElement(new Element(20));
|
||||||
System.out.println("element value: " + container.getElement().getValue());
|
System.out.println("element value: " + container.getElement().getValue());
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -7964,12 +7964,12 @@ In order to understand why, consider a garbage collection occuring...
|
||||||
|
|
||||||
<div class="code">
|
<div class="code">
|
||||||
<pre>
|
<pre>
|
||||||
Container container = new Container();
|
Container container = new Container();
|
||||||
container.setElement(new Element(20));
|
container.setElement(new Element(20));
|
||||||
// Simulate a garbage collection
|
// Simulate a garbage collection
|
||||||
System.gc();
|
System.gc();
|
||||||
System.runFinalization();
|
System.runFinalization();
|
||||||
System.out.println("element value: " + container.getElement().getValue());
|
System.out.println("element value: " + container.getElement().getValue());
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -8315,7 +8315,7 @@ public class FooDerived extends Foo {
|
||||||
public static FooDerived downcastFooDerived(Foo foo_object)
|
public static FooDerived downcastFooDerived(Foo foo_object)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return (foo_object != null ? (FooDerived) Foo.downcastFoo(foo_object);
|
return foo_object != null ? (FooDerived) Foo.downcastFoo(foo_object);
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (ClassCastException exc) {
|
catch (ClassCastException exc) {
|
||||||
|
|
@ -8366,10 +8366,8 @@ public abstract class UserVisibleFoo extends Foo {
|
||||||
public static UserVisibleFoo downcastUserVisibleFoo(Foo foo_object)
|
public static UserVisibleFoo downcastUserVisibleFoo(Foo foo_object)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return (foo_object != null ? (FooDerived) Foo.downcastFoo(foo_object) : null);
|
return foo_object != null ? (FooDerived) Foo.downcastFoo(foo_object) : null;
|
||||||
}
|
} catch (ClassCastException exc) {
|
||||||
|
|
||||||
catch (ClassCastException exc) {
|
|
||||||
// Wasn't a FooDerived object, some other subclass of Foo
|
// Wasn't a FooDerived object, some other subclass of Foo
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,6 @@ struct bar * my_struct;
|
||||||
struct foo {
|
struct foo {
|
||||||
int a;
|
int a;
|
||||||
struct foo * b[100];
|
struct foo * b[100];
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int pointer_func(void (*ClosureFun)( void* _fun, void* _data, void* _evt ), int p);
|
int pointer_func(void (*ClosureFun)( void* _fun, void* _data, void* _evt ), int p);
|
||||||
|
|
@ -460,16 +459,13 @@ namespace OpenDemo {
|
||||||
static const Test zero;
|
static const Test zero;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
inline Test operator* (float s, const Test& v) {return v*s;}
|
inline Test operator* (float s, const Test& v) {return v*s;}
|
||||||
|
|
||||||
|
|
||||||
inline std::ostream& operator<< (std::ostream& o, const Test& v)
|
inline std::ostream& operator<< (std::ostream& o, const Test& v)
|
||||||
{
|
{
|
||||||
return o << "(" << v.x << ")";
|
return o << "(" << v.x << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Test RandomUnitVectorOnXZPlane (void)
|
inline Test RandomUnitVectorOnXZPlane (void)
|
||||||
{
|
{
|
||||||
return RandomVectorInUnitRadiusSphere().setYtoZero().normalize();
|
return RandomVectorInUnitRadiusSphere().setYtoZero().normalize();
|
||||||
|
|
|
||||||
|
|
@ -1095,8 +1095,9 @@ Now we extend it with some new code
|
||||||
sprintf(tmp,"Complex(%g,%g)", $self->re(),$self->im());
|
sprintf(tmp,"Complex(%g,%g)", $self->re(),$self->im());
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
bool operator==(const Complex& c)
|
bool operator==(const Complex& c) {
|
||||||
{ return ($self->re()==c.re() && $self->im()==c.im());}
|
return ($self->re()==c.re() && $self->im()==c.im());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
</pre></div>
|
</pre></div>
|
||||||
<p>
|
<p>
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ More information can be found at <a href="http://www.gnu.org/software/octave/">O
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
This chapter is intended to give an introduction to using the module. You should also read the SWIG documentation that is not specific to Octave.
|
This chapter is intended to give an introduction to using the module. You should also read the SWIG documentation that is not specific to Octave.
|
||||||
Also, there are a dozen or so examples in the Examples/octave directory, and hundreds in the test suite (Examples/test-suite and Examples/test-suite/octave).
|
Also, there are a dozen or so examples in the Examples/octave directory, and hundreds in the test suite (Examples/test-suite and Examples/test-suite/octave).
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2188,20 +2188,20 @@ reference to be used as a char ** datatype.
|
||||||
|
|
||||||
// Now a few test functions
|
// Now a few test functions
|
||||||
%inline %{
|
%inline %{
|
||||||
int print_args(char **argv) {
|
int print_args(char **argv) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (argv[i]) {
|
while (argv[i]) {
|
||||||
printf("argv[%d] = %s\n", i,argv[i]);
|
printf("argv[%d] = %s\n", i,argv[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a char ** list
|
// Returns a char ** list
|
||||||
char **get_args() {
|
char **get_args() {
|
||||||
static char *values[] = { "Dave", "Mike", "Susan", "John", "Michelle", 0};
|
static char *values[] = { "Dave", "Mike", "Susan", "John", "Michelle", 0};
|
||||||
return &values[0];
|
return &values[0];
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
|
||||||
|
|
@ -1527,7 +1527,6 @@ class Spam {
|
||||||
public:
|
public:
|
||||||
static void foo();
|
static void foo();
|
||||||
static int bar;
|
static int bar;
|
||||||
|
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -256,7 +256,7 @@ C++ class like this:
|
||||||
<div class="code">
|
<div class="code">
|
||||||
<pre>
|
<pre>
|
||||||
class Foo {
|
class Foo {
|
||||||
public:
|
public:
|
||||||
Foo();
|
Foo();
|
||||||
~Foo();
|
~Foo();
|
||||||
int bar(int x);
|
int bar(int x);
|
||||||
|
|
@ -272,9 +272,9 @@ Using C++ as pseudocode, a proxy class looks something like this:
|
||||||
<div class="code">
|
<div class="code">
|
||||||
<pre>
|
<pre>
|
||||||
class FooProxy {
|
class FooProxy {
|
||||||
private:
|
private:
|
||||||
Foo *self;
|
Foo *self;
|
||||||
public:
|
public:
|
||||||
FooProxy() {
|
FooProxy() {
|
||||||
self = new_Foo();
|
self = new_Foo();
|
||||||
}
|
}
|
||||||
|
|
@ -407,7 +407,7 @@ roughly like this:
|
||||||
<div class="code">
|
<div class="code">
|
||||||
<pre>
|
<pre>
|
||||||
class FooProxy {
|
class FooProxy {
|
||||||
public:
|
public:
|
||||||
Foo *self;
|
Foo *self;
|
||||||
int thisown;
|
int thisown;
|
||||||
|
|
||||||
|
|
@ -2236,14 +2236,14 @@ class Bar : public Spam {
|
||||||
public:
|
public:
|
||||||
virtual void foo(int); // Renamed to foo_i
|
virtual void foo(int); // Renamed to foo_i
|
||||||
virtual void foo(double); // Renamed to foo_d
|
virtual void foo(double); // Renamed to foo_d
|
||||||
...
|
...
|
||||||
};
|
};
|
||||||
|
|
||||||
class Grok : public Bar {
|
class Grok : public Bar {
|
||||||
public:
|
public:
|
||||||
virtual void foo(int); // Renamed to foo_i
|
virtual void foo(int); // Renamed to foo_i
|
||||||
virtual void foo(double); // Renamed to foo_d
|
virtual void foo(double); // Renamed to foo_d
|
||||||
...
|
...
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -4047,7 +4047,7 @@ namespace foo {
|
||||||
%inline %{
|
%inline %{
|
||||||
void bar(int) { ... } /* I'm bad */
|
void bar(int) { ... } /* I'm bad */
|
||||||
...
|
...
|
||||||
%}
|
%}
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -443,14 +443,15 @@ The example below shows this for a C function returning 2 values and a result:
|
||||||
int divide(int n, int d, int *OUTPUT, int *OUTPUT);
|
int divide(int n, int d, int *OUTPUT, int *OUTPUT);
|
||||||
|
|
||||||
%{
|
%{
|
||||||
int divide(int n, int d, int q*, int *r) {
|
int divide(int n, int d, int q*, int *r) {
|
||||||
if (d != 0) {
|
if (d != 0) {
|
||||||
*q = n / d;
|
*q = n / d;
|
||||||
*r = n % d;
|
*r = n % d;
|
||||||
return 1;
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else return 0;
|
|
||||||
}
|
|
||||||
%}
|
%}
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1304,7 +1304,6 @@ class Spam {
|
||||||
public:
|
public:
|
||||||
static void foo();
|
static void foo();
|
||||||
static int bar;
|
static int bar;
|
||||||
|
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -2819,14 +2818,14 @@ used as a <tt>char **</tt> object.
|
||||||
|
|
||||||
// Now a test functions
|
// Now a test functions
|
||||||
%inline %{
|
%inline %{
|
||||||
int print_args(char **argv) {
|
int print_args(char **argv) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (argv[i]) {
|
while (argv[i]) {
|
||||||
printf("argv[%d] = %s\n", i,argv[i]);
|
printf("argv[%d] = %s\n", i,argv[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
%include "tclsh.i"
|
%include "tclsh.i"
|
||||||
|
|
||||||
|
|
@ -3031,7 +3030,6 @@ work)
|
||||||
%typemap(in) char * {
|
%typemap(in) char * {
|
||||||
int len;
|
int len;
|
||||||
$1 = Tcl_GetStringFromObj(interp, &len);
|
$1 = Tcl_GetStringFromObj(interp, &len);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -2915,7 +2915,6 @@ try {
|
||||||
catch(char const *_e) {
|
catch(char const *_e) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, _e);
|
PyErr_SetString(PyExc_RuntimeError, _e);
|
||||||
SWIG_fail;
|
SWIG_fail;
|
||||||
|
|
||||||
}
|
}
|
||||||
...
|
...
|
||||||
</pre>
|
</pre>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue