fix $typemap() when the type contains template parameters

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11506 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2009-08-05 21:40:49 +00:00
commit 41d3c98993
5 changed files with 48 additions and 2 deletions

View file

@ -14,6 +14,8 @@ public class runme {
throw new Exception("test failed");
if (special_variable_macros.testJim(name) != "multiname num")
throw new Exception("test failed");
if (special_variable_macros.testJohn(new PairIntBool(10, false)) != 123)
throw new Exception("test failed");
NewName newName = NewName.factory("factoryname");
name = newName.getStoredName();
}

View file

@ -24,6 +24,8 @@ public class special_variable_macros_runme {
throw new RuntimeException("test failed");
if (!special_variable_macros.testJim(name).equals("multiname num"))
throw new RuntimeException("test failed");
if (special_variable_macros.testJohn(new PairIntBool(10, false)) != 123)
throw new RuntimeException("test failed");
NewName newName = NewName.factory("factoryname");
name = newName.getStoredName();
}

View file

@ -11,4 +11,6 @@ if special_variable_macros.testMary(name) != "SWIGTYPE_p_NameWrap":
raise "test failed"
if special_variable_macros.testJim(name) != "multiname num":
raise "test failed"
if special_variable_macros.testJohn(special_variable_macros.PairIntBool(10, False)) != 123:
raise "test failed"

View file

@ -110,6 +110,40 @@ const char * testJim(Name *jim, int count) {
}
%}
//////////////////////////////////////////////////////////////////////////////////////
// Template types with more than one template parameter
// check $1 and $input get expanded properly when used from $typemap()
%typemap(in) Space::Pair<int, bool> PAIR_INT_BOOL ($1_type temp)
%{
/*%typemap(in) Name *GENERIC start */
temp = Space::Pair<int, bool>(123, true);
(void)$input;
$1 = ($1_ltype)temp;
/*%typemap(in) Name *GENERIC end */
%}
%typemap(in) Space::Pair<int, bool> john {
// %typemap(in) Name *john start
$typemap(in, Space::Pair<int, bool> PAIR_INT_BOOL)
// %typemap(in) Name *john end
}
%inline %{
namespace Space {
template <typename T1, typename T2> struct Pair {
Pair(T1 f, T2 s) : first(f), second(s) {}
Pair() {}
T1 first;
T2 second;
};
int testJohn(Space::Pair<int, bool> john) {
return john.first;
}
}
%}
%template(PairIntBool) Space::Pair<int, bool>;
//////////////////////////////////////////////////////////////////////////////////////
// A real use case for $typemap

View file

@ -1699,9 +1699,10 @@ static List *split_embedded_typemap(String *s) {
List *args = 0;
char *c, *start;
int level = 0;
int angle_level = 0;
int leading = 1;
args = NewList();
args = NewList();
c = strchr(Char(s), '(');
assert(c);
c++;
@ -1720,7 +1721,7 @@ static List *split_embedded_typemap(String *s) {
c++;
}
}
if ((level == 0) && ((*c == ',') || (*c == ')'))) {
if ((level == 0) && angle_level == 0 && ((*c == ',') || (*c == ')'))) {
String *tmp = NewStringWithSize(start, c - start);
Append(args, tmp);
Delete(tmp);
@ -1735,6 +1736,10 @@ static List *split_embedded_typemap(String *s) {
level++;
if (*c == ')')
level--;
if (*c == '<')
angle_level++;
if (*c == '>')
angle_level--;
if (isspace((int) *c) && leading)
start++;
if (!isspace((int) *c))
@ -1901,6 +1906,7 @@ static void replace_embedded_typemap(String *s, ParmList *parm_sublist, Wrapper
}
Delete(l);
}
if (syntax_error) {
String *dtypemap = NewString(dollar_typemap);
Replaceall(dtypemap, "$TYPEMAP", "$typemap");