More consistent formatting of examples in documentation
This commit is contained in:
parent
8052211ac5
commit
ba45861b46
3 changed files with 84 additions and 84 deletions
|
|
@ -639,12 +639,12 @@ public:
|
||||||
virtual ~FooBarAbstract() {};
|
virtual ~FooBarAbstract() {};
|
||||||
|
|
||||||
std::string FooBar() {
|
std::string FooBar() {
|
||||||
return this->Foo() + ", " + this->Bar();
|
return this->Foo() + ", " + this->Bar();
|
||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual std::string Foo() {
|
virtual std::string Foo() {
|
||||||
return "Foo";
|
return "Foo";
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual std::string Bar() = 0;
|
virtual std::string Bar() = 0;
|
||||||
|
|
|
||||||
|
|
@ -1043,14 +1043,14 @@ expect :</p>
|
||||||
<div class="targetlang"><pre>
|
<div class="targetlang"><pre>
|
||||||
# Copy a file
|
# Copy a file
|
||||||
def filecopy(source, target):
|
def filecopy(source, target):
|
||||||
f1 = fopen(source, "r")
|
f1 = fopen(source, "r")
|
||||||
f2 = fopen(target, "w")
|
f2 = fopen(target, "w")
|
||||||
buffer = malloc(8192)
|
buffer = malloc(8192)
|
||||||
nbytes = fread(buffer, 8192, 1, f1)
|
nbytes = fread(buffer, 8192, 1, f1)
|
||||||
while (nbytes > 0):
|
while (nbytes > 0):
|
||||||
fwrite(buffer, 8192, 1, f2)
|
fwrite(buffer, 8192, 1, f2)
|
||||||
nbytes = fread(buffer, 8192, 1, f1)
|
nbytes = fread(buffer, 8192, 1, f1)
|
||||||
free(buffer)
|
free(buffer)
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
|
||||||
|
|
@ -777,9 +777,9 @@ the normal constructor function. For example, if you have this:
|
||||||
<pre>
|
<pre>
|
||||||
class List {
|
class List {
|
||||||
public:
|
public:
|
||||||
List();
|
List();
|
||||||
List(const List &); // Copy constructor
|
List(const List &); // Copy constructor
|
||||||
...
|
...
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -803,7 +803,7 @@ through a special function like this:
|
||||||
<div class="code">
|
<div class="code">
|
||||||
<pre>
|
<pre>
|
||||||
List *copy_List(List *f) {
|
List *copy_List(List *f) {
|
||||||
return new List(*f);
|
return new List(*f);
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -832,7 +832,7 @@ However, copy constructor wrappers can be generated if using the <tt>copyctor</t
|
||||||
|
|
||||||
class List {
|
class List {
|
||||||
public:
|
public:
|
||||||
List();
|
List();
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -851,9 +851,9 @@ could be wrapped, but they had to be renamed. For example:
|
||||||
<pre>
|
<pre>
|
||||||
class Foo {
|
class Foo {
|
||||||
public:
|
public:
|
||||||
Foo();
|
Foo();
|
||||||
%name(CopyFoo) Foo(const Foo &);
|
%name(CopyFoo) Foo(const Foo &);
|
||||||
...
|
...
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -969,8 +969,8 @@ not primitive types, such as classes. For instance, if you had another class lik
|
||||||
<pre>
|
<pre>
|
||||||
class Foo {
|
class Foo {
|
||||||
public:
|
public:
|
||||||
List items;
|
List items;
|
||||||
...
|
...
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -982,10 +982,10 @@ For example:
|
||||||
<div class="code">
|
<div class="code">
|
||||||
<pre>
|
<pre>
|
||||||
List *Foo_items_get(Foo *self) {
|
List *Foo_items_get(Foo *self) {
|
||||||
return &self->items;
|
return &self->items;
|
||||||
}
|
}
|
||||||
void Foo_items_set(Foo *self, List *value) {
|
void Foo_items_set(Foo *self, List *value) {
|
||||||
self->items = *value;
|
self->items = *value;
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -1007,10 +1007,10 @@ It is the naturalvar feature and can be used to effectively change the way acces
|
||||||
<div class="code">
|
<div class="code">
|
||||||
<pre>
|
<pre>
|
||||||
const List &Foo_items_get(Foo *self) {
|
const List &Foo_items_get(Foo *self) {
|
||||||
return self->items;
|
return self->items;
|
||||||
}
|
}
|
||||||
void Foo_items_set(Foo *self, const List &value) {
|
void Foo_items_set(Foo *self, const List &value) {
|
||||||
self->items = value;
|
self->items = value;
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -1105,7 +1105,7 @@ SWIG will wrap all types of functions that have default arguments. For example m
|
||||||
<pre>
|
<pre>
|
||||||
class Foo {
|
class Foo {
|
||||||
public:
|
public:
|
||||||
void bar(int x, int y = 3, int z = 4);
|
void bar(int x, int y = 3, int z = 4);
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -1120,9 +1120,9 @@ Thus for the example above, it is as if we had instead given the following to SW
|
||||||
<pre>
|
<pre>
|
||||||
class Foo {
|
class Foo {
|
||||||
public:
|
public:
|
||||||
void bar(int x, int y, int z);
|
void bar(int x, int y, int z);
|
||||||
void bar(int x, int y);
|
void bar(int x, int y);
|
||||||
void bar(int x);
|
void bar(int x);
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -1158,7 +1158,7 @@ can be re-activated by using the <tt>compactdefaultargs</tt>
|
||||||
%feature("compactdefaultargs") Foo::bar;
|
%feature("compactdefaultargs") Foo::bar;
|
||||||
class Foo {
|
class Foo {
|
||||||
public:
|
public:
|
||||||
void bar(int x, int y = 3, int z = 4);
|
void bar(int x, int y = 3, int z = 4);
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -1485,8 +1485,8 @@ class A;
|
||||||
|
|
||||||
%feature("valuewrapper") B;
|
%feature("valuewrapper") B;
|
||||||
struct B {
|
struct B {
|
||||||
B();
|
B();
|
||||||
// ....
|
// ....
|
||||||
};
|
};
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
|
|
@ -3000,15 +3000,15 @@ provide an expanded version of the class directly like this:
|
||||||
%rename(intList) List<int>; // Rename to a suitable identifier
|
%rename(intList) List<int>; // Rename to a suitable identifier
|
||||||
class List<int> {
|
class List<int> {
|
||||||
private:
|
private:
|
||||||
int *data;
|
int *data;
|
||||||
int nitems;
|
int nitems;
|
||||||
int maxitems;
|
int maxitems;
|
||||||
public:
|
public:
|
||||||
List(int max);
|
List(int max);
|
||||||
~List();
|
~List();
|
||||||
void append(int obj);
|
void append(int obj);
|
||||||
int length();
|
int length();
|
||||||
int get(int n);
|
int get(int n);
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -3244,15 +3244,15 @@ a class like this,
|
||||||
<pre>
|
<pre>
|
||||||
template<> class List<int> {
|
template<> class List<int> {
|
||||||
private:
|
private:
|
||||||
int *data;
|
int *data;
|
||||||
int nitems;
|
int nitems;
|
||||||
int maxitems;
|
int maxitems;
|
||||||
public:
|
public:
|
||||||
List(int max);
|
List(int max);
|
||||||
~List();
|
~List();
|
||||||
void append(int obj);
|
void append(int obj);
|
||||||
int length();
|
int length();
|
||||||
int get(int n);
|
int get(int n);
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -3275,15 +3275,15 @@ code defines a template that is applied when the template argument is a pointer.
|
||||||
<pre>
|
<pre>
|
||||||
template<class T> class List<T*> {
|
template<class T> class List<T*> {
|
||||||
private:
|
private:
|
||||||
T *data;
|
T *data;
|
||||||
int nitems;
|
int nitems;
|
||||||
int maxitems;
|
int maxitems;
|
||||||
public:
|
public:
|
||||||
List(int max);
|
List(int max);
|
||||||
~List();
|
~List();
|
||||||
void append(int obj);
|
void append(int obj);
|
||||||
int length();
|
int length();
|
||||||
T get(int n);
|
T get(int n);
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -3587,11 +3587,11 @@ It is also possible to separate these declarations from the template class. For
|
||||||
|
|
||||||
...
|
...
|
||||||
template<class T> class List {
|
template<class T> class List {
|
||||||
...
|
...
|
||||||
public:
|
public:
|
||||||
List() { }
|
List() { }
|
||||||
T get(int index);
|
T get(int index);
|
||||||
...
|
...
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -3609,9 +3609,9 @@ additional methods to a specific instantiation. For example:
|
||||||
%template(intList) List<int>;
|
%template(intList) List<int>;
|
||||||
|
|
||||||
%extend List<int> {
|
%extend List<int> {
|
||||||
void blah() {
|
void blah() {
|
||||||
printf("Hey, I'm an List<int>!\n");
|
printf("Hey, I'm an List<int>!\n");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -3698,7 +3698,7 @@ template <class T> class OuterTemplateClass {};
|
||||||
// OuterTemplateClass<OuterClass::InnerStruct> and thus the template needs
|
// OuterTemplateClass<OuterClass::InnerStruct> and thus the template needs
|
||||||
// to be expanded with %template before the OuterClass declaration.
|
// to be expanded with %template before the OuterClass declaration.
|
||||||
%template(OuterTemplateClass_OuterClass__InnerStruct)
|
%template(OuterTemplateClass_OuterClass__InnerStruct)
|
||||||
OuterTemplateClass<OuterClass::InnerStruct>
|
OuterTemplateClass<OuterClass::InnerStruct>
|
||||||
|
|
||||||
|
|
||||||
// Don't forget to use %feature("flatnested") for OuterClass::InnerStruct and
|
// Don't forget to use %feature("flatnested") for OuterClass::InnerStruct and
|
||||||
|
|
@ -3736,7 +3736,7 @@ introduced a new class name. This name could then be used with other directives
|
||||||
<pre>
|
<pre>
|
||||||
%template(vectori) vector<int>;
|
%template(vectori) vector<int>;
|
||||||
%extend vectori {
|
%extend vectori {
|
||||||
void somemethod() { }
|
void somemethod() { }
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -3750,7 +3750,7 @@ as the class name. For example:
|
||||||
<pre>
|
<pre>
|
||||||
%template(vectori) vector<int>;
|
%template(vectori) vector<int>;
|
||||||
%extend vector<int> {
|
%extend vector<int> {
|
||||||
void somemethod() { }
|
void somemethod() { }
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -4011,7 +4011,7 @@ in a different namespace. For example:
|
||||||
<div class="code">
|
<div class="code">
|
||||||
<pre>
|
<pre>
|
||||||
namespace foo {
|
namespace foo {
|
||||||
template<typename T> T max(T a, T b) { return a > b ? a : b; }
|
template<typename T> T max(T a, T b) { return a > b ? a : b; }
|
||||||
}
|
}
|
||||||
|
|
||||||
using foo::max;
|
using foo::max;
|
||||||
|
|
@ -4020,8 +4020,8 @@ using foo::max;
|
||||||
%template(maxfloat) foo::max<float>; // Okay (qualified name).
|
%template(maxfloat) foo::max<float>; // Okay (qualified name).
|
||||||
|
|
||||||
namespace bar {
|
namespace bar {
|
||||||
using namespace foo;
|
using namespace foo;
|
||||||
%template(maxdouble) max<double>; // Okay.
|
%template(maxdouble) max<double>; // Okay.
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -4445,10 +4445,10 @@ struct Error4 : EBase { };
|
||||||
|
|
||||||
class Foo {
|
class Foo {
|
||||||
public:
|
public:
|
||||||
...
|
...
|
||||||
void bar();
|
void bar();
|
||||||
void blah() throw(Error1, Error2, Error3, Error4);
|
void blah() throw(Error1, Error2, Error3, Error4);
|
||||||
...
|
...
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -4545,8 +4545,8 @@ public:
|
||||||
// Ordinary class
|
// Ordinary class
|
||||||
class Foo_Impl {
|
class Foo_Impl {
|
||||||
public:
|
public:
|
||||||
int x;
|
int x;
|
||||||
virtual void bar();
|
virtual void bar();
|
||||||
...
|
...
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -4555,13 +4555,13 @@ typedef SmartPtr<Foo_Impl> Foo;
|
||||||
|
|
||||||
// Create smart pointer Foo
|
// Create smart pointer Foo
|
||||||
Foo make_Foo() {
|
Foo make_Foo() {
|
||||||
return SmartPtr<Foo_Impl>(new Foo_Impl());
|
return SmartPtr<Foo_Impl>(new Foo_Impl());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do something with smart pointer Foo
|
// Do something with smart pointer Foo
|
||||||
void do_something(Foo f) {
|
void do_something(Foo f) {
|
||||||
printf("x = %d\n", f->x);
|
printf("x = %d\n", f->x);
|
||||||
f->bar();
|
f->bar();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the wrapped smart pointer proxy class in the target language 'Foo'
|
// Call the wrapped smart pointer proxy class in the target language 'Foo'
|
||||||
|
|
@ -4660,13 +4660,13 @@ example, if you have this code</p>
|
||||||
<pre>
|
<pre>
|
||||||
class Foo {
|
class Foo {
|
||||||
public:
|
public:
|
||||||
int x;
|
int x;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Bar {
|
class Bar {
|
||||||
public:
|
public:
|
||||||
int x;
|
int x;
|
||||||
Foo *operator->();
|
Foo *operator->();
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -4970,14 +4970,14 @@ you wrap this code in Python, the module works just like you would expect:
|
||||||
<pre>
|
<pre>
|
||||||
class Foo {
|
class Foo {
|
||||||
protected:
|
protected:
|
||||||
int x;
|
int x;
|
||||||
int blah(int x);
|
int blah(int x);
|
||||||
};
|
};
|
||||||
|
|
||||||
class Bar : public Foo {
|
class Bar : public Foo {
|
||||||
public:
|
public:
|
||||||
using Foo::x; // Make x public
|
using Foo::x; // Make x public
|
||||||
using Foo::blah; // Make blah public
|
using Foo::blah; // Make blah public
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue