From 73fe0fdc7e72311072235137d498864e15ccf2f2 Mon Sep 17 00:00:00 2001 From: luav Date: Tue, 12 Sep 2017 04:10:30 +0200 Subject: [PATCH] %rename for functions with default parameters explained, see #1087 --- Doc/Manual/SWIG.html | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index 965fae11c..304377f29 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -1736,6 +1736,43 @@ already defined in the target scripting language. However, if you are careful about namespaces and your use of modules, you can usually avoid these problems.

+

+%rename directive respects function parameters and discriminates default parameters from non-default, +which is essential for some languages including Python. Be careful renaming functions having default parameters: +

+
+%rename(toFFVal) to_val(FileFormat, bool bin=false);
+int to_val(FileFormat flag, bool bin=false)
+{
+  return 0;
+}
+
+%rename(toDFVal) to_val(DirFormat, bool bin);
+int to_val(DirFormat flag, bool bin=false)
+{
+  return 0;
+}
+
+%rename(toLFVal) to_val(FolderFormat, bool bin);
+int to_val(FolderFormat flag, bool bin=false)
+{
+  return 0;
+}
+
+ +

+The SWIG generator yields the following warning for the last renaming:
+ +rename.i:36: Warning 509: Overloaded method to_val(FolderFormat) effectively ignored,
+rename.i:26: Warning 509: as it is shadowed by to_val(DirFormat).
+
+The renaming performed for the int to_val(FolderFormat flag, bool bin), +but not for the int to_val(FolderFormat flag), where the second parameter bool bin +is omitted taking the default value false. See details about the default +parameters processing in the Default Arguments section. +

+ +

Closely related to %rename is the %ignore directive. %ignore instructs SWIG to ignore declarations that match a given identifier. For example: