From f069d0a744ef9bf7b3e31a89877977e9153fc959 Mon Sep 17 00:00:00 2001 From: luav Date: Mon, 11 Sep 2017 22:55:13 +0200 Subject: [PATCH] %shared_ptr usage for the templates documented, see #1049 --- Doc/Manual/Library.html | 43 +++++++++++++++++++++++++++++++++++++++-- Doc/Manual/SWIG.html | 2 +- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/Doc/Manual/Library.html b/Doc/Manual/Library.html index f41799bf0..40677cc9f 100644 --- a/Doc/Manual/Library.html +++ b/Doc/Manual/Library.html @@ -1728,6 +1728,10 @@ Any thrown STL exceptions will then be gracefully handled instead of causing a c

9.4.4 shared_ptr smart pointer

+

+%shared_ptr Basics +

+

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 std::shared_ptr. @@ -1822,7 +1826,11 @@ System.out.println(val1 + " " + val2);

-This shared_ptr library works quite differently to SWIG's normal, but somewhat limited, +%shared_ptr and Inheritance +

+ +

+The shared_ptr library works quite differently to SWIG's normal, but somewhat limited, smart pointer handling. 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 %shared_ptr macros will fix this:

-%include "boost_shared_ptr.i"
+%include <boost_shared_ptr.i>
 %shared_ptr(GrandParent);
 %shared_ptr(Parent);
 %shared_ptr(Child);
@@ -1909,6 +1917,37 @@ Adding the missing %shared_ptr macros will fix this:
 
+

+%shared_ptr and Templates +

+ +

+Only the single %shared_ptr declaration should be used for all specializations +of the template before the first template instantiation using the following notation: +%shared_ptr(TemplateName<>). For example: +

+ +
+
+%include <std_shared_ptr.i>
+
+%shared_ptr(Graph<>);  //!< 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<false>;  //!< Simple graph 
+// Note: the Graph name is redefined in the following line from the template to the specialization (class)
+%template(Graph) Graph<true>;  //!< Weighted graph
+
+
+ +

Note: There is somewhat limited support for %shared_ptr and the director feature and the degrees of success varies among the different target languages. diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index f0c4837f1..965fae11c 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -3305,7 +3305,7 @@ is given to both the C compiler and SWIG, it is illegal to include any SWIG directives inside a %{ ... %} block.

-Note:Any #include directives are omitted inside the +Note: Any #include directives are omitted inside the %inline %{ ... %} block unless the -includeall command line option is supplied.