diff options
Diffstat (limited to 'Doc/Manual/Library.html')
-rw-r--r-- | Doc/Manual/Library.html | 69 |
1 files changed, 55 insertions, 14 deletions
diff --git a/Doc/Manual/Library.html b/Doc/Manual/Library.html index 285192d5e..02b8e53bd 100644 --- a/Doc/Manual/Library.html +++ b/Doc/Manual/Library.html @@ -824,20 +824,20 @@ If you have a function that expects binary data, <div class="code"> <pre> -int parity(char *str, int len, int initial); +size_t parity(char *str, size_t len, size_t initial); </pre> </div> <p> -you can wrap the parameters <tt>(char *str, int len)</tt> as a single +you can wrap the parameters <tt>(char *str, size_t len)</tt> as a single argument using a typemap. Just do this: </p> <div class="code"> <pre> -%apply (char *STRING, int LENGTH) { (char *str, int len) }; +%apply (char *STRING, size_t LENGTH) { (char *str, size_t len) }; ... -int parity(char *str, int len, int initial); +size_t parity(char *str, size_t len, size_t initial); </pre> </div> @@ -854,6 +854,7 @@ Now, in the target language, you can use binary string data like this: <p> In the wrapper function, the passed string will be expanded to a pointer and length parameter. +The <tt>(char *STRING, int LENGTH)</tt> multi-argument typemap is also available in addition to <tt>(char *STRING, size_t LENGTH)</tt>. </p> <H3><a name="Library_nn11"></a>8.3.3 Using %newobject to release memory</H3> @@ -1802,27 +1803,67 @@ struct DerivedIntValue : IntValue { </div> <p> -Note that if the <tt>%shared_ptr</tt> macro is omitted for any class in the inheritance hierarchy, it will -result in a C++ compiler error. -For example if the above <tt>%shared_ptr(DerivedIntValue)</tt> is omitted, the following is typical of the compiler error that will result: +A shared_ptr of the derived class can now be passed to a method where the base is expected in the target language, just as it can in C++: +</p> + +<div class="targetlang"> +<pre> +DerivedIntValue div = new DerivedIntValue(5678); +int val3 = example.extractValue(div); +int val4 = example.extractValueSmart(div); +</pre> +</div> + +<p> +If the <tt>%shared_ptr</tt> macro is omitted for any class in the inheritance hierarchy, SWIG will warn about this and the generated code may or may not result in a C++ compilation error. +For example, the following input: +</p> + +<div class="code"> +<pre> +%include "boost_shared_ptr.i" +%shared_ptr(Parent); + +%inline %{ + #include <boost/shared_ptr.hpp> + struct GrandParent { + virtual ~GrandParent() {} + }; + + struct Parent : GrandParent { + virtual ~Parent() {} + }; + + struct Child : Parent { + virtual ~Child() {} + }; +%} +</pre> +</div> + +<p> +warns about the missing smart pointer information: </p> <div class="shell"> <pre> -example_wrap.cxx: In function 'void Java_exampleJNI_delete_1DerivedIntValue(JNIEnv*, _jclass*, jlong)': -example_wrap.cxx:3169: error: 'smartarg1' was not declared in this scope +example.i:12: Warning 520: Base class 'GrandParent' of 'Parent' is not similarly marked as a smart pointer. +example.i:16: Warning 520: Derived class 'Child' of 'Parent' is not similarly marked as a smart pointer. </pre> </div> <p> -A shared_ptr of the derived class can now be passed to a method where the base is expected in the target language, just as it can in C++: +Adding the missing <tt>%shared_ptr</tt> macros will fix this: </p> -<div class="targetlang"> +<div class="code"> <pre> -DerivedIntValue div = new DerivedIntValue(5678); -int val3 = example.extractValue(div); -int val4 = example.extractValueSmart(div); +%include "boost_shared_ptr.i" +%shared_ptr(GrandParent); +%shared_ptr(Parent); +%shared_ptr(Child); + +... as before ... </pre> </div> |