%shared_ptr usage for the templates documented, see #1049

This commit is contained in:
luav 2017-09-11 22:55:13 +02:00
parent 0587edd559
commit f069d0a744
2 changed files with 42 additions and 3 deletions

View File

@ -1728,6 +1728,10 @@ Any thrown STL exceptions will then be gracefully handled instead of causing a c
<H3><a name="Library_std_shared_ptr">9.4.4 shared_ptr smart pointer</a></H3>
<p>
<b>%shared_ptr Basics</b>
</p>
<p>
Some target languages have support for handling the shared_ptr reference counted smart pointer.
This smart pointer is available in the standard C++11 library as <tt>std::shared_ptr</tt>.
@ -1822,7 +1826,11 @@ System.out.println(val1 + " " + val2);
</div>
<p>
This shared_ptr library works quite differently to SWIG's normal, but somewhat limited,
<b>%shared_ptr and Inheritance</b>
</p>
<p>
The shared_ptr library works quite differently to SWIG's normal, but somewhat limited,
<a href="SWIGPlus.html#SWIGPlus_smart_pointers">smart pointer handling</a>.
The shared_ptr library does not generate extra wrappers, just for smart pointer handling, in addition to the proxy class.
The normal proxy class including inheritance relationships is generated as usual.
@ -1900,7 +1908,7 @@ Adding the missing <tt>%shared_ptr</tt> macros will fix this:
<div class="code">
<pre>
%include "boost_shared_ptr.i"
%include &lt;boost_shared_ptr.i&gt;
%shared_ptr(GrandParent);
%shared_ptr(Parent);
%shared_ptr(Child);
@ -1909,6 +1917,37 @@ Adding the missing <tt>%shared_ptr</tt> macros will fix this:
</pre>
</div>
<p>
<b>%shared_ptr and Templates</b>
</p>
<p>
Only the single <tt>%shared_ptr</tt> declaration should be used for all specializations
of the template before the first template instantiation using the following notation:
<tt>%shared_ptr(TemplateName&lt;&gt;)</tt>. For example:
</p>
<div class="code">
<pre>
%include &lt;std_shared_ptr.i&gt;
%shared_ptr(Graph&lt;&gt;); //!< Declaration of the transparent shared ptr for the Graph template
%{
#include "graph.hpp" // Graph definition (inside the namespace gany)
using namespace gany;
%}
%include "graph.h" // Graph declaration (inside the namespace gany)
using namespace gany;
%template(SGraph) Graph&lt;false&gt;; //!< Simple graph
// Note: the Graph name is redefined in the following line from the template to the specialization (class)
%template(Graph) Graph&lt;true&gt;; //!< Weighted graph
</pre>
</div>
<p>
<b>Note:</b> There is somewhat limited support for <tt>%shared_ptr</tt> and the director feature
and the degrees of success varies among the different target languages.

View File

@ -3305,7 +3305,7 @@ is given to both the C compiler and SWIG, it is illegal to include any
SWIG directives inside a <tt>%{ ... %}</tt> block.</p>
<p>
<b>Note:</b>Any <tt>#include</tt> directives are omitted inside the
<b>Note:</b> Any <tt>#include</tt> directives are omitted inside the
<tt>%inline %{ ... %}</tt> block unless the <tt>-includeall</tt> command line
option is supplied.</p>