scilab: rewrite doc on templates
This commit is contained in:
parent
65fe133e2d
commit
a9397c3b49
1 changed files with 57 additions and 0 deletions
|
|
@ -960,6 +960,63 @@ But we can use either use the <tt>get_perimeter()</tt> function of the parent cl
|
|||
|
||||
<H3><a name="Scilab_wrapping_templates"></a>37.3.10 C++ Templates</H3>
|
||||
|
||||
<p>
|
||||
As in other languages, function and class templates are supported in SWIG Scilab.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
You have to tell SWIG to create wrappers for a particular
|
||||
template instantiation. The <tt>%template</tt> directive is used for that purpose.
|
||||
For example:
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
%module example
|
||||
|
||||
template<class T1, class T2, class T3>
|
||||
struct triplet {
|
||||
T1 first;
|
||||
T2 second;
|
||||
T3 third;
|
||||
triplet(const T1& a, const T2& b, const T3& c) {
|
||||
third = a; second = b; third = c;
|
||||
}
|
||||
};
|
||||
|
||||
%template(IntTriplet) triplet<int,int,int>;
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
Then in Scilab:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
-->t = new_IntTriplet(3, 4, 1);
|
||||
|
||||
-->IntTriplet_first_get(t)
|
||||
ans =
|
||||
|
||||
3.
|
||||
|
||||
-->IntTriplet_second_get(t)
|
||||
ans =
|
||||
|
||||
4.
|
||||
|
||||
-->IntTriplet_third_get(t)
|
||||
ans =
|
||||
|
||||
1.
|
||||
|
||||
-->delete_IntTriplet(t);
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
More details on template support can be found in the <a href="SWIGPlus.html#SWIGPlus">SWIG C++ documentation</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Templates are supported. See the SWIG general documentation on how templates are interfaced in SWIG.<br>
|
||||
An example of templates can be found in <tt>Examples/scilab/templates</tt>.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue