46
46
<li><a href="#SWIGPlus_nn27">Comments on overloading</a>
48
48
<li><a href="#SWIGPlus_nn28">Wrapping overloaded operators</a>
49
<li><a href="#SWIGPlus_nn29">Class extension</a>
49
<li><a href="#SWIGPlus_class_extension">Class extension</a>
50
50
<li><a href="#SWIGPlus_nn30">Templates</a>
51
51
<li><a href="#SWIGPlus_nn31">Namespaces</a>
52
<li><a href="#SWIGPlus_renaming_templated_types_namespaces">Renaming templated types in namespaces</a>
52
53
<li><a href="#SWIGPlus_exception_specifications">Exception specifications</a>
53
54
<li><a href="#SWIGPlus_catches">Exception handling with %catches</a>
54
55
<li><a href="#SWIGPlus_nn33">Pointers to Members</a>
1495
1496
<p> SWIG treats private or protected inheritance as close to the C++
1496
spirit, and target language capabilities, as possible. In most of the
1497
spirit, and target language capabilities, as possible. In most
1497
1498
cases, this means that SWIG will parse the non-public inheritance
1498
1499
declarations, but that will have no effect in the generated code,
1499
1500
besides the implicit policies derived for constructor and
1656
1657
This behavior resulted in huge amounts of replicated code for large
1657
1658
class hierarchies and made it awkward to build applications spread
1658
1659
across multiple modules (since accessor functions are duplicated in
1659
every single module). It is also unnecessary to have such wrappers
1660
every single module). It is also unnecessary to have such wrappers
1660
1661
when advanced features like proxy classes are used.
1662
1663
<b>Note:</b> Further optimizations are enabled when using the
2445
Currently no resolution is performed in order to match function parameters. This means function parameter types must match exactly.
2446
For example, namespace qualifiers and typedefs will not work. The following usage of typedefs demonstrates this:
2450
typedef int Integer;
2452
%rename(foo_i) foo(int);
2456
void foo(Integer); // Stays 'foo' (not renamed)
2460
void foo(int); // Renamed to foo_i
2444
2466
The name matching rules also use default arguments for finer control when wrapping methods that have default arguments.
2445
2467
Recall that methods with default arguments are wrapped as if the equivalent overloaded methods had been parsed
2446
2468
(<a href="#SWIGPlus_default_args">Default arguments</a> section).
2764
2786
The C++ 'this' pointer is often needed to access member variables, methods etc.
2765
2787
The <tt>$self</tt> special variable should be used wherever you could use 'this'.
2766
2788
The example above demonstrates this for accessing member variables.
2789
Note that the members dereferenced by <tt>$self</tt> must be public members as the code is ultimately generated
2790
into a global function and so will not have any access to non-public members.
2767
2791
The implicit 'this' pointer that is present in C++ methods is not present in <tt>%extend</tt> methods.
2768
2792
In order to access anything in the extended class or its base class, an explicit 'this' is required.
2769
2793
The following example shows how one could access base class members:
2819
There are some restrictions on the use of non-type arguments. Specifically,
2820
they have to be simple literals and not expressions. For example:
2843
There are some restrictions on the use of non-type arguments. Simple literals
2844
are supported, and so are some constant expressions. However, use of '<'
2845
and '>' within a constant expressions currently is not supported by SWIG
2846
('<=' and '>=' are though). For example:
2823
2849
<div class="code">
2825
void bar(list<int,100> *x); // OK
2826
void bar(list<int,2*50> *x); // Illegal
2851
void bar(list<int,100> *x); // OK
2852
void bar(list<int,2*50> *x); // OK
2853
void bar(list<int,(2>1 ? 100 : 50)> *x) // Not supported
4023
Note, however, that if the operator is defined using a qualifier in its name, then the feature must use it too...
4028
%rename(tofoo) foo::spam::operator bar(); // will not match
4029
%rename(tofoo) foo::spam::operator foo::bar(); // will match
4035
operator foo::bar();
4043
<b>Compatibility Note:</b> Versions of SWIG prior to 1.3.32 were inconsistent in this approach. A fully qualified name was usually required, but would not work in some situations.
3998
4048
<b>Note:</b> The flattening of namespaces is only intended to serve as
3999
a basic namespace implementation. Since namespaces are a new addition
4000
to SWIG, none of the target language modules are currently programmed
4049
a basic namespace implementation.
4050
None of the target language modules are currently programmed
4001
4051
with any namespace awareness. In the future, language modules may or may not provide
4002
4052
more advanced namespace support.
4006
<H2><a name="SWIGPlus_exception_specifications"></a>6.20 Exception specifications</H2>
4055
<H2><a name="SWIGPlus_renaming_templated_types_namespaces"></a>6.20 Renaming templated types in namespaces</H2>
4059
As has been mentioned, when %rename includes parameters, the parameter types must match exactly (no typedef or namespace resolution is performed).
4060
SWIG treats templated types slightly differently and has an additional matching rule so unlike non-templated types, an exact match is not always required.
4061
If the fully qualified templated type is specified, it will have a higher precedence over the generic template type.
4062
In the example below, the generic template type is used to rename to <tt>bbb</tt> and the fully qualified type is used to rename to <tt>ccc</tt>.
4067
%rename(bbb) Space::ABC::aaa(T t); // will match but with lower precedence than ccc
4068
%rename(ccc) Space::ABC<Space::XYZ>::aaa(Space::XYZ t); // will match but with higher precedence than bbb
4072
template<typename T> struct ABC {
4076
%template(ABCXYZ) Space::ABC<Space::XYZ>;
4081
It should now be apparent that there are many ways to achieve a renaming with %rename. This is demonstrated
4082
by the following two examples, which are effectively the same as the above example.
4083
Below shows how %rename can be placed inside a namespace.
4089
%rename(bbb) ABC::aaa(T t); // will match but with lower precedence than ccc
4090
%rename(ccc) ABC<Space::XYZ>::aaa(Space::XYZ t); // will match but with higher precedence than bbb
4091
%rename(ddd) ABC<Space::XYZ>::aaa(XYZ t); // will not match
4096
template<typename T> struct ABC {
4100
%template(ABCXYZ) Space::ABC<Space::XYZ>;
4105
Note that <tt>ddd</tt> does not match as there is no namespace resolution for parameter types and the fully qualified type must be specified for template type expansion.
4106
The following example shows how %rename can be placed within %extend.
4113
%rename(bbb) aaa(T t); // will match but with lower precedence than ccc
4115
%extend ABC<Space::XYZ> {
4116
%rename(ccc) aaa(Space::XYZ t); // will match but with higher precedence than bbb
4117
%rename(ddd) aaa(XYZ t); // will not match
4123
template<typename T> struct ABC {
4127
%template(ABCXYZ) Space::ABC<Space::XYZ>;
4132
<H2><a name="SWIGPlus_exception_specifications"></a>6.21 Exception specifications</H2>