More consistent formatting of examples in documentation

This commit is contained in:
William S Fulton 2017-07-30 17:18:55 +01:00
commit 04131a988f
8 changed files with 161 additions and 160 deletions

View file

@ -677,7 +677,7 @@ As a result, we get the following method in the module class:
<div class="code">
<pre>
public static void myArrayCopy(int[] sourceArray, int[] targetArray, int nitems) {
examplePINVOKE.myArrayCopy(sourceArray, targetArray, nitems);
examplePINVOKE.myArrayCopy(sourceArray, targetArray, nitems);
}
</pre>
</div>

View file

@ -949,7 +949,7 @@ Foo *BarToFoo(Bar *b) {
}
Foo *IncrFoo(Foo *f, int i) {
return f+i;
return f+i;
}
%}
</pre>
@ -1057,7 +1057,7 @@ produces a single accessor function like this:
<div class="code">
<pre>
int *Foo_x_get(Foo *self) {
return self-&gt;x;
return self-&gt;x;
};
</pre>
</div>
@ -1092,11 +1092,11 @@ generates accessor functions such as this:
<div class="code">
<pre>
Foo *Bar_f_get(Bar *b) {
return &amp;b-&gt;f;
return &amp;b-&gt;f;
}
void Bar_f_set(Bar *b, Foo *val) {
b-&gt;f = *val;
b-&gt;f = *val;
}
</pre>
</div>
@ -1887,9 +1887,9 @@ like this:
<div class="targetlang">
<pre>
%typemap(out) int {
$result = sv_newmortal();
set_setiv($result, (IV) $1);
argvi++;
$result = sv_newmortal();
set_setiv($result, (IV) $1);
argvi++;
}
</pre>
</div>
@ -2312,8 +2312,8 @@ Consider the following data structure:
<div class="code"><pre>
#define SIZE 8
typedef struct {
int values[SIZE];
...
int values[SIZE];
...
} Foo;
</pre></div>
@ -2327,10 +2327,10 @@ To make the member writable, a "memberin" typemap can be used.
<div class="code"><pre>
%typemap(memberin) int [SIZE] {
int i;
for (i = 0; i &lt; SIZE; i++) {
$1[i] = $input[i];
}
int i;
for (i = 0; i &lt; SIZE; i++) {
$1[i] = $input[i];
}
}
</pre></div>
@ -2599,48 +2599,48 @@ package example::Vector;
%BLESSEDMEMBERS = ();
sub new () {
my $self = shift;
my @args = @_;
$self = vectorc::new_Vector(@args);
return undef if (!defined($self));
bless $self, "example::Vector";
$OWNER{$self} = 1;
my %retval;
tie %retval, "example::Vector", $self;
return bless \%retval, "Vector";
my $self = shift;
my @args = @_;
$self = vectorc::new_Vector(@args);
return undef if (!defined($self));
bless $self, "example::Vector";
$OWNER{$self} = 1;
my %retval;
tie %retval, "example::Vector", $self;
return bless \%retval, "Vector";
}
sub DESTROY {
return unless $_[0]-&gt;isa('HASH');
my $self = tied(%{$_[0]});
delete $ITERATORS{$self};
if (exists $OWNER{$self}) {
examplec::delete_Vector($self));
delete $OWNER{$self};
}
return unless $_[0]-&gt;isa('HASH');
my $self = tied(%{$_[0]});
delete $ITERATORS{$self};
if (exists $OWNER{$self}) {
examplec::delete_Vector($self));
delete $OWNER{$self};
}
}
sub FETCH {
my ($self, $field) = @_;
my $member_func = "vectorc::Vector_${field}_get";
my $val = &amp;$member_func($self);
if (exists $BLESSEDMEMBERS{$field}) {
return undef if (!defined($val));
my %retval;
tie %retval, $BLESSEDMEMBERS{$field}, $val;
return bless \%retval, $BLESSEDMEMBERS{$field};
}
return $val;
my ($self, $field) = @_;
my $member_func = "vectorc::Vector_${field}_get";
my $val = &amp;$member_func($self);
if (exists $BLESSEDMEMBERS{$field}) {
return undef if (!defined($val));
my %retval;
tie %retval, $BLESSEDMEMBERS{$field}, $val;
return bless \%retval, $BLESSEDMEMBERS{$field};
}
return $val;
}
sub STORE {
my ($self, $field, $newval) = @_;
my $member_func = "vectorc::Vector_${field}_set";
if (exists $BLESSEDMEMBERS{$field}) {
&amp;$member_func($self, tied(%{$newval}));
} else {
&amp;$member_func($self, $newval);
}
my ($self, $field, $newval) = @_;
my $member_func = "vectorc::Vector_${field}_set";
if (exists $BLESSEDMEMBERS{$field}) {
&amp;$member_func($self, tied(%{$newval}));
} else {
&amp;$member_func($self, $newval);
}
}
</pre></div>
@ -2841,11 +2841,11 @@ this:
<div class="targetlang"><pre>
sub dot_product {
my @args = @_;
$args[0] = tied(%{$args[0]}); # Get the real pointer values
$args[1] = tied(%{$args[1]});
my $result = vectorc::dot_product(@args);
return $result;
my @args = @_;
$args[0] = tied(%{$args[0]}); # Get the real pointer values
$args[1] = tied(%{$args[1]});
my $result = vectorc::dot_product(@args);
return $result;
}
</pre></div>
@ -3103,14 +3103,14 @@ the methods one() and two() (but not three()):
%feature("director") Foo;
class Foo {
public:
Foo(int foo);
virtual void one();
virtual void two();
Foo(int foo);
virtual void one();
virtual void two();
};
class Bar: public Foo {
public:
virtual void three();
virtual void three();
};
</pre>
</div>
@ -3304,8 +3304,8 @@ suitable exception handler:
<div class="code">
<pre>
%exception {
try { $action }
catch (Swig::DirectorException &amp;e) { SWIG_fail; }
try { $action }
catch (Swig::DirectorException &amp;e) { SWIG_fail; }
}
</pre>
</div>

View file

@ -986,14 +986,14 @@ the methods one() and two() (but not three()):
%feature("director") Foo;
class Foo {
public:
Foo(int foo);
virtual void one();
virtual void two();
Foo(int foo);
virtual void one();
virtual void two();
};
class Bar: public Foo {
public:
virtual void three();
virtual void three();
};
</pre>
</div>
@ -1125,12 +1125,12 @@ Here is an example:
<pre>
class Foo {
public:
...
...
};
class FooContainer {
public:
void addFoo(Foo *);
...
void addFoo(Foo *);
...
};
</pre>
</div>
@ -1204,8 +1204,8 @@ suitable exception handler:
<div class="code">
<pre>
%exception {
try { $action }
catch (Swig::DirectorException &amp;e) { SWIG_fail; }
try { $action }
catch (Swig::DirectorException &amp;e) { SWIG_fail; }
}
</pre>
</div>

View file

@ -230,8 +230,8 @@ For example, given this C++ class declaration:
class Shape
{
public:
static void print();
static int nshapes;
static void print();
static int nshapes;
};
</pre></div>

View file

@ -1275,7 +1275,7 @@ Foo *BarToFoo(Bar *b) {
}
Foo *IncrFoo(Foo *f, int i) {
return f+i;
return f+i;
}
%}
</pre>
@ -1385,7 +1385,7 @@ example, consider this:
<div class="code">
<pre>
struct Bar {
int x[16];
int x[16];
};
</pre>
</div>
@ -1715,9 +1715,9 @@ Similarly, if you have a class like this,
<pre>
class Foo {
public:
Foo();
Foo(const Foo &amp;);
...
Foo();
Foo(const Foo &amp;);
...
};
</pre>
</div>
@ -1950,11 +1950,11 @@ For example:
%rename(Bar_spam) Bar::spam;
namespace Foo {
int spam();
int spam();
}
namespace Bar {
int spam();
int spam();
}
</pre>
</div>
@ -2165,9 +2165,9 @@ have a class like this
<pre>
class Foo {
public:
int x;
int spam(int);
...
int x;
int spam(int);
...
</pre>
</div>
@ -2178,19 +2178,19 @@ then SWIG transforms it into a set of low-level procedural wrappers. For example
<div class="code">
<pre>
Foo *new_Foo() {
return new Foo();
return new Foo();
}
void delete_Foo(Foo *f) {
delete f;
delete f;
}
int Foo_x_get(Foo *f) {
return f-&gt;x;
return f-&gt;x;
}
void Foo_x_set(Foo *f, int value) {
f-&gt;x = value;
f-&gt;x = value;
}
int Foo_spam(Foo *f, int arg1) {
return f-&gt;spam(arg1);
return f-&gt;spam(arg1);
}
</pre>
</div>
@ -2309,10 +2309,10 @@ please refer to the python documentation:</p>
<div class="code">
<pre>
typedef struct {
PyObject_HEAD
PyObject *dict;
PyObject *args;
PyObject *message;
PyObject_HEAD
PyObject *dict;
PyObject *args;
PyObject *message;
} PyBaseExceptionObject;
</pre>
</div>
@ -2322,12 +2322,12 @@ typedef struct {
<div class="code">
<pre>
typedef struct {
PyObject_HEAD
void *ptr;
swig_type_info *ty;
int own;
PyObject *next;
PyObject *dict;
PyObject_HEAD
void *ptr;
swig_type_info *ty;
int own;
PyObject *next;
PyObject *dict;
} SwigPyObject;
</pre>
</div>
@ -2338,13 +2338,13 @@ typedef struct {
<pre>
class MyException {
public:
MyException (const char *msg_);
~MyException ();
MyException (const char *msg_);
~MyException ();
const char *what () const;
const char *what () const;
private:
char *msg;
char *msg;
};
</pre>
</div>
@ -2371,9 +2371,9 @@ strings, you can define an <tt>'operator+ (const char*)'</tt> method :</p>
<pre>
class MyString {
public:
MyString (const char *init);
MyString operator+ (const char *other) const;
...
MyString (const char *init);
MyString operator+ (const char *other) const;
...
};
</pre>
</div>
@ -2472,11 +2472,12 @@ slot entries. For example, suppose you have this class:
<pre>
class Twit {
public:
Twit operator+ (const Twit&amp; twit) const;
Twit operator+ (const Twit&amp; twit) const;
// Forward to operator+
Twit add (const Twit&amp; twit) const
{ return *this + twit; }
// Forward to operator+
Twit add (const Twit&amp; twit) const {
return *this + twit;
}
};
</pre>
</div>
@ -2635,8 +2636,8 @@ ownership of the result. For example:
<pre>
class Foo {
public:
Foo();
Foo bar();
Foo();
Foo bar();
};
</pre>
</div>
@ -2665,9 +2666,9 @@ they came from. Therefore, the ownership is set to zero. For example:
<pre>
class Foo {
public:
...
Foo *spam();
...
...
Foo *spam();
...
};
</pre>
</div>
@ -2706,8 +2707,8 @@ or global variable. For example, consider this interface:
%module example
struct Foo {
int value;
Foo *next;
int value;
Foo *next;
};
Foo *head = 0;
@ -2938,15 +2939,15 @@ the methods one() and two() (but not three()):
%feature("director") Foo;
class Foo {
public:
Foo(int foo);
virtual ~Foo();
virtual void one();
virtual void two();
Foo(int foo);
virtual ~Foo();
virtual void one();
virtual void two();
};
class Bar: public Foo {
public:
virtual void three();
virtual void three();
};
</pre>
</div>
@ -3090,8 +3091,8 @@ public:
};
class FooContainer {
public:
void addFoo(Foo *);
...
void addFoo(Foo *);
...
};
</pre>
</div>
@ -3161,8 +3162,8 @@ suitable exception handler:
<div class="code">
<pre>
%exception {
try { $action }
catch (Swig::DirectorException &amp;e) { SWIG_fail; }
try { $action }
catch (Swig::DirectorException &amp;e) { SWIG_fail; }
}
</pre>
</div>
@ -3239,7 +3240,7 @@ references, such as
<pre>
class Foo {
&hellip;
virtual const int&amp; bar();
virtual const int&amp; bar();
&hellip;
};
</pre>
@ -3257,7 +3258,7 @@ types, wherever possible, for example
<pre>
class Foo {
&hellip;
virtual int bar();
virtual int bar();
&hellip;
};
</pre>
@ -3510,7 +3511,7 @@ def bar(*args):
class Foo {
public:
int bar(int x);
int bar(int x);
};
</pre>
</div>
@ -3547,7 +3548,7 @@ proxy, just before the return statement.
class Foo {
public:
int bar(int x);
int bar(int x);
};
</pre>
</div>
@ -3576,7 +3577,7 @@ SWIG version 1.3.28 you can use the directive forms
class Foo {
public:
int bar(int x);
int bar(int x);
};
</pre>
</div>
@ -3605,8 +3606,8 @@ as it will then get attached to all the overloaded C++ methods. For example:
class Foo {
public:
int bar(int x);
int bar();
int bar(int x);
int bar();
};
</pre>
</div>

View file

@ -1236,9 +1236,9 @@ creating a wrapper equivalent to the following:
<div class="code"><pre>
double wrap_dot_product(Vector *a, Vector *b) {
Vector x = *a;
Vector y = *b;
return dot_product(x, y);
Vector x = *a;
Vector y = *b;
return dot_product(x, y);
}
</pre></div>
@ -2368,10 +2368,10 @@ defined in the interface. For example:
<div class="code"><pre>
struct Vector *new_Vector() {
return (Vector *) calloc(1, sizeof(struct Vector));
return (Vector *) calloc(1, sizeof(struct Vector));
}
void delete_Vector(struct Vector *obj) {
free(obj);
free(obj);
}
</pre>
</div>
@ -2602,10 +2602,10 @@ like this:
<div class="code">
<pre>
WORD Foo_w_get(Foo *f) {
return f-&gt;w;
return f-&gt;w;
}
void Foo_w_set(FOO *f, WORD value) {
f-&gt;w = value;
f-&gt;w = value;
}
</pre>
</div>
@ -2896,7 +2896,7 @@ instead of a method. To do this, you might write some code like this:
<pre>
// Add a new attribute to Vector
%extend Vector {
const double magnitude;
const double magnitude;
}
// Now supply the implementation of the Vector_magnitude_get function
%{

View file

@ -4042,7 +4042,7 @@ namespace foo {
typedef int Integer;
class bar {
public:
...
...
};
}

View file

@ -958,7 +958,7 @@ Foo *BarToFoo(Bar *b) {
}
Foo *IncrFoo(Foo *f, int i) {
return f+i;
return f+i;
}
%}
</pre>
@ -1054,7 +1054,7 @@ example, consider this:
<div class="code">
<pre>
struct Bar {
int x[16];
int x[16];
};
</pre>
</div>
@ -1456,9 +1456,9 @@ Similarly, if you have a class like this,
<pre>
class Foo {
public:
Foo();
Foo(const Foo &amp;);
...
Foo();
Foo(const Foo &amp;);
...
};
</pre>
</div>
@ -1693,11 +1693,11 @@ For example:
%rename(Bar_spam) Bar::spam;
namespace Foo {
int spam();
int spam();
}
namespace Bar {
int spam();
int spam();
}
</pre>
</div>
@ -1886,19 +1886,19 @@ then SWIG transforms it into a set of low-level procedural wrappers. For example
<div class="code">
<pre>
Foo *new_Foo() {
return new Foo();
return new Foo();
}
void delete_Foo(Foo *f) {
delete f;
delete f;
}
int Foo_x_get(Foo *f) {
return f-&gt;x;
return f-&gt;x;
}
void Foo_x_set(Foo *f, int value) {
f-&gt;x = value;
f-&gt;x = value;
}
int Foo_spam(Foo *f, int arg1) {
return f-&gt;spam(arg1);
return f-&gt;spam(arg1);
}
</pre>
</div>
@ -1945,8 +1945,8 @@ ownership of the result. For example:
<pre>
class Foo {
public:
Foo();
Foo bar();
Foo();
Foo bar();
};
</pre>
</div>
@ -1975,9 +1975,9 @@ they came from. Therefore, the ownership is set to zero. For example:
<pre>
class Foo {
public:
...
Foo *spam();
...
...
Foo *spam();
...
};
</pre>
</div>
@ -2011,8 +2011,8 @@ or global variable. For example, consider this interface:
%module example
struct Foo {
int value;
Foo *next;
int value;
Foo *next;
};
Foo *head = 0;
@ -2465,9 +2465,9 @@ you might define a typemap like this:
%module example
%typemap(in) int {
if (Tcl_GetIntFromObj(interp, $input, &amp;$1) == TCL_ERROR)
return TCL_ERROR;
printf("Received an integer : %d\n", $1);
if (Tcl_GetIntFromObj(interp, $input, &amp;$1) == TCL_ERROR)
return TCL_ERROR;
printf("Received an integer : %d\n", $1);
}
%inline %{
extern int fact(int n);
@ -2585,7 +2585,7 @@ like this:
<div class="code">
<pre>
%typemap(out) int {
Tcl_SetObjResult(interp, Tcl_NewIntObj($1));
Tcl_SetObjResult(interp, Tcl_NewIntObj($1));
}
</pre>
</div>