Fix some typos in docs and examples and make the code look nicer.
This commit is contained in:
parent
70801d47d1
commit
8985c34809
45 changed files with 717 additions and 717 deletions
|
|
@ -115,7 +115,7 @@ this module is in generating pointers to primitive datatypes such as
|
|||
</p>
|
||||
|
||||
<p>
|
||||
<b><tt>%pointer_functions(type,name)</tt></b>
|
||||
<b><tt>%pointer_functions(type, name)</tt></b>
|
||||
</p>
|
||||
|
||||
<div class="indent">
|
||||
|
|
@ -195,7 +195,7 @@ Now, in Python:
|
|||
<pre>
|
||||
>>> import example
|
||||
>>> c = example.new_intp() # Create an "int" for storing result
|
||||
>>> example.add(3,4,c) # Call function
|
||||
>>> example.add(3, 4, c) # Call function
|
||||
>>> example.intp_value(c) # Dereference
|
||||
7
|
||||
>>> example.delete_intp(c) # Delete
|
||||
|
|
@ -205,7 +205,7 @@ Now, in Python:
|
|||
</div>
|
||||
|
||||
<p>
|
||||
<b><tt>%pointer_class(type,name)</tt></b>
|
||||
<b><tt>%pointer_class(type, name)</tt></b>
|
||||
</p>
|
||||
|
||||
<div class="indent">
|
||||
|
|
@ -275,7 +275,7 @@ Now, in Python (using proxy classes)
|
|||
<pre>
|
||||
>>> import example
|
||||
>>> c = example.intp() # Create an "int" for storing result
|
||||
>>> example.add(3,4,c) # Call function
|
||||
>>> example.add(3, 4, c) # Call function
|
||||
>>> c.value() # Dereference
|
||||
7
|
||||
</pre>
|
||||
|
|
@ -331,7 +331,7 @@ raw C array data.
|
|||
</p>
|
||||
|
||||
<p>
|
||||
<b><tt>%array_functions(type,name)</tt></b>
|
||||
<b><tt>%array_functions(type, name)</tt></b>
|
||||
</p>
|
||||
|
||||
<div class="indent">
|
||||
|
|
@ -414,8 +414,8 @@ Now, in a scripting language, you might write this:
|
|||
<div class="code">
|
||||
<pre>
|
||||
a = new_doubleArray(10) # Create an array
|
||||
for i in range(0,10):
|
||||
doubleArray_setitem(a,i,2*i) # Set a value
|
||||
for i in range(0, 10):
|
||||
doubleArray_setitem(a, i, 2*i) # Set a value
|
||||
print_array(a) # Pass to C
|
||||
delete_doubleArray(a) # Destroy array
|
||||
</pre>
|
||||
|
|
@ -424,7 +424,7 @@ delete_doubleArray(a) # Destroy array
|
|||
</div>
|
||||
|
||||
<p>
|
||||
<b><tt>%array_class(type,name)</tt></b>
|
||||
<b><tt>%array_class(type, name)</tt></b>
|
||||
</p>
|
||||
<div class="indent">
|
||||
|
||||
|
|
@ -479,7 +479,7 @@ Allows you to do this:
|
|||
<pre>
|
||||
import example
|
||||
c = example.doubleArray(10) # Create double[10]
|
||||
for i in range(0,10):
|
||||
for i in range(0, 10):
|
||||
c[i] = 2*i # Assign values
|
||||
example.print_array(c) # Pass to C
|
||||
</pre>
|
||||
|
|
@ -507,7 +507,7 @@ This module defines macros for wrapping the low-level C memory allocation functi
|
|||
</p>
|
||||
|
||||
<p>
|
||||
<b><tt>%malloc(type [,name=type])</tt></b>
|
||||
<b><tt>%malloc(type [, name=type])</tt></b>
|
||||
</p>
|
||||
|
||||
<div class="indent">
|
||||
|
|
@ -530,7 +530,7 @@ is not a valid identifier (e.g., "<tt>int *</tt>", "<tt>double **</tt>", etc.).
|
|||
</div>
|
||||
|
||||
<p>
|
||||
<b><tt>%calloc(type [,name=type])</tt></b>
|
||||
<b><tt>%calloc(type [, name=type])</tt></b>
|
||||
</p>
|
||||
|
||||
<div class="indent">
|
||||
|
|
@ -551,7 +551,7 @@ If <tt>type</tt> is <tt>void</tt>, then the size parameter <tt>sz</tt> is requir
|
|||
</div>
|
||||
|
||||
<p>
|
||||
<b><tt>%realloc(type [,name=type])</tt></b>
|
||||
<b><tt>%realloc(type [, name=type])</tt></b>
|
||||
</p>
|
||||
|
||||
<div class="indent">
|
||||
|
|
@ -574,7 +574,7 @@ it holds 100 integers.
|
|||
</div>
|
||||
|
||||
<p>
|
||||
<b><tt>%free(type [,name=type])</tt></b>
|
||||
<b><tt>%free(type [, name=type])</tt></b>
|
||||
</p>
|
||||
|
||||
<div class="indent">
|
||||
|
|
@ -590,7 +590,7 @@ void free_<em>name</em>(<em>type</em> *ptr);
|
|||
</div>
|
||||
|
||||
<p>
|
||||
<b><tt>%sizeof(type [,name=type])</tt></b>
|
||||
<b><tt>%sizeof(type [, name=type])</tt></b>
|
||||
</p>
|
||||
|
||||
<div class="indent">
|
||||
|
|
@ -606,7 +606,7 @@ Creates the constant:
|
|||
</div>
|
||||
|
||||
<p>
|
||||
<b><tt>%allocators(type [,name=type])</tt></b>
|
||||
<b><tt>%allocators(type [, name=type])</tt></b>
|
||||
</p>
|
||||
|
||||
<div class="indent"><p>
|
||||
|
|
@ -716,14 +716,14 @@ Python example:
|
|||
<div class="targetlang">
|
||||
<pre>
|
||||
>>> a = intArray(10)
|
||||
>>> for i in range(0,10):
|
||||
>>> for i in range(0, 10):
|
||||
... a[i] = i
|
||||
>>> b = cdata(a,40)
|
||||
>>> b = cdata(a, 40)
|
||||
>>> b
|
||||
'\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04
|
||||
\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\t'
|
||||
>>> c = intArray(10)
|
||||
>>> memmove(c,b)
|
||||
>>> memmove(c, b)
|
||||
>>> print c[4]
|
||||
4
|
||||
>>>
|
||||
|
|
@ -735,7 +735,7 @@ Since the size of data is not always known, the following macro is also defined:
|
|||
</p>
|
||||
|
||||
<p>
|
||||
<b><tt>%cdata(type [,name=type])</tt></b>
|
||||
<b><tt>%cdata(type [, name=type])</tt></b>
|
||||
</p>
|
||||
|
||||
<div class="indent">
|
||||
|
|
@ -855,7 +855,7 @@ Now, in the target language, you can use binary string data like this:
|
|||
<div class="code">
|
||||
<pre>
|
||||
>>> s = "H\x00\x15eg\x09\x20"
|
||||
>>> parity(s,0)
|
||||
>>> parity(s, 0)
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
|
@ -920,7 +920,7 @@ implementation:
|
|||
<pre>
|
||||
void get_path(char *s) {
|
||||
// Potential buffer overflow---uh, oh.
|
||||
sprintf(s,"%s/%s", base_directory, sub_directory);
|
||||
sprintf(s, "%s/%s", base_directory, sub_directory);
|
||||
}
|
||||
...
|
||||
// Somewhere else in the C program
|
||||
|
|
@ -1554,7 +1554,7 @@ To illustrate the use of this library, consider the following functions:
|
|||
#include <numeric>
|
||||
|
||||
double average(std::vector<int> v) {
|
||||
return std::accumulate(v.begin(),v.end(),0.0)/v.size();
|
||||
return std::accumulate(v.begin(), v.end(), 0.0)/v.size();
|
||||
}
|
||||
|
||||
std::vector<double> half(const std::vector<double>& v) {
|
||||
|
|
@ -1565,8 +1565,8 @@ std::vector<double> half(const std::vector<double>& v) {
|
|||
}
|
||||
|
||||
void halve_in_place(std::vector<double>& v) {
|
||||
std::transform(v.begin(),v.end(),v.begin(),
|
||||
std::bind2nd(std::divides<double>(),2.0));
|
||||
std::transform(v.begin(), v.end(), v.begin(),
|
||||
std::bind2nd(std::divides<double>(), 2.0));
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -1602,20 +1602,20 @@ Now, to illustrate the behavior in the scripting interpreter, consider this Pyth
|
|||
<pre>
|
||||
>>> from example import *
|
||||
>>> iv = IntVector(4) # Create an vector<int>
|
||||
>>> for i in range(0,4):
|
||||
>>> for i in range(0, 4):
|
||||
... iv[i] = i
|
||||
>>> average(iv) # Call method
|
||||
1.5
|
||||
>>> average([0,1,2,3]) # Call with list
|
||||
>>> average([0, 1, 2, 3]) # Call with list
|
||||
1.5
|
||||
>>> half([1,2,3]) # Half a list
|
||||
(0.5,1.0,1.5)
|
||||
>>> halve_in_place([1,2,3]) # Oops
|
||||
>>> half([1, 2, 3]) # Half a list
|
||||
(0.5, 1.0, 1.5)
|
||||
>>> halve_in_place([1, 2, 3]) # Oops
|
||||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in ?
|
||||
TypeError: Type error. Expected _p_std__vectorTdouble_t
|
||||
>>> dv = DoubleVector(4)
|
||||
>>> for i in range(0,4):
|
||||
>>> for i in range(0, 4):
|
||||
... dv[i] = i
|
||||
>>> halve_in_place(dv) # Ok
|
||||
>>> for i in dv:
|
||||
|
|
@ -1629,7 +1629,7 @@ TypeError: Type error. Expected _p_std__vectorTdouble_t
|
|||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in ?
|
||||
File "example.py", line 81, in __setitem__
|
||||
def __setitem__(*args): return apply(examplec.DoubleVector___setitem__,args)
|
||||
def __setitem__(*args): return apply(examplec.DoubleVector___setitem__, args)
|
||||
IndexError: vector index out of range
|
||||
>>>
|
||||
</pre>
|
||||
|
|
@ -2014,7 +2014,7 @@ For example:
|
|||
try {
|
||||
$action
|
||||
} catch (std::out_of_range& e) {
|
||||
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
||||
SWIG_exception(SWIG_IndexError, const_cast<char*>(e.what()));
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue