%feature mods for default arguments

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6663 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2004-11-04 22:25:17 +00:00
commit 485a4e8b6a
3 changed files with 94 additions and 1 deletions

View file

@ -377,6 +377,10 @@
</ul>
<li><a href="Customization.html#ownership">Object ownership and %newobject</a>
<li><a href="Customization.html#features">Features and the %feature directive</a>
<ul>
<li><a href="Customization.html#Customization_features_default_args">Features and default arguments</a>
<li><a href="Customization.html#features_example">Feature example</a>
</ul>
</ul>
<!-- INDEX -->

View file

@ -18,6 +18,10 @@
</ul>
<li><a href="#ownership">Object ownership and %newobject</a>
<li><a href="#features">Features and the %feature directive</a>
<ul>
<li><a href="#Customization_features_default_args">Features and default arguments</a>
<li><a href="#features_example">Feature example</a>
</ul>
</ul>
<!-- INDEX -->
@ -639,10 +643,90 @@ In the following example, <tt>MyExceptionClass</tt> is the name of the Java clas
</pre>
</blockquote>
<p>
Further details can be obtained from the <a href="Java.html#exception_handling">Java exception handling</a> section.
</p>
<H3><a name="Customization_features_default_args"></a>11.3.1 Features and default arguments</H3>
<p>
As can be seen, the intended use for the <tt>%feature</tt> directive is as a highly flexible customization mechanism that can be used to annotate
SWIG treats methods with default arguments as separate overloaded methods as detailed
in the <a href="SWIGPlus.html#SWIGPlus_default_args">default arguments</a> section.
Any <tt>%feature</tt> targeting a method with default arguments
will apply to all the extra overloaded methods that SWIG generates if the
default arguments are specified in the feature. If the default arguments are
not specified in the feature, then the feature will match that exact
wrapper method only and not the extra overloaded methods that SWIG generates.
For example:
</p>
<blockquote>
<pre>
%feature("except") void hello(int i=0, double d=0.0);
void hello(int i=0, double d=0.0);
</pre>
</blockquote>
<p>
will apply the feature to all three wrapper methods, that is:
</p>
<blockquote>
<pre>
void hello(int i, double d);
void hello(int i);
void hello();
</pre>
</blockquote>
<p>
If the default arguments are not specified in the feature:
</p>
<blockquote>
<pre>
%feature("except") void hello(int i, double d);
void hello(int i=0, double d=0.0);
</pre>
</blockquote>
<p>
then the feature will only apply to this wrapper method:
</p>
<blockquote>
<pre>
void hello(int i, double d);
</pre>
</blockquote>
<p>
and not these wrapper methods:
</p>
<blockquote>
<pre>
void hello(int i);
void hello();
</pre>
</blockquote>
<p>
If <a href="SWIGPlus.html#SWIGPlus_default_args">compactdefaultargs</a> are being used, then the difference between
specifying or not specifying default arguments in a feature is not applicable as just one wrapper is generated.
</p>
<p>
<b>Compatibility note:</b> The different behaviour of features specified with or without default arguments was introduced
in SWIG-1.3.23 when the approach to wrapping methods with default arguments was changed.
</p>
<H3><a name="features_example"></a>11.3.2 Feature example</H3>
<p>
As has been shown earlier, the intended use for the <tt>%feature</tt> directive is as a highly flexible customization mechanism that can be used to annotate
declarations with additional information for use by specific target language modules. Another example is
in the Python module. You might use <tt>%feature</tt> to rewrite proxy/shadow class code as follows:
</p>

View file

@ -660,6 +660,11 @@ This approach allows SWIG to wrap all possible default arguments, but can be ver
For example if a method has ten default arguments, then eleven wrapper methods are generated.
</p>
<p>
Please see the <a href="Customization.html#Customization_features_default_args">Features and default arguments</a>
section for more information on using <tt>%feature</tt> for functions with default arguments.
</p>
<p>
<b>Compatibility note:</b> Versions of SWIG prior to SWIG-1.3.23 wrapped default arguments slightly differently.
Instead a single wrapper method was generated and the default values were copied into the C++ wrappers