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"> <div class="code">
<pre> <pre>
public static void myArrayCopy(int[] sourceArray, int[] targetArray, int nitems) { public static void myArrayCopy(int[] sourceArray, int[] targetArray, int nitems) {
examplePINVOKE.myArrayCopy(sourceArray, targetArray, nitems); examplePINVOKE.myArrayCopy(sourceArray, targetArray, nitems);
} }
</pre> </pre>
</div> </div>

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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