diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index e2dd71314..6abe6f5c5 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -158,6 +158,7 @@ extern "C" { extern String *SwigType_namestr(const SwigType *t); extern String *SwigType_templateprefix(const SwigType *t); extern String *SwigType_templatesuffix(const SwigType *t); + extern String *SwigType_istemplate_templateprefix(const SwigType *t); extern String *SwigType_templateargs(const SwigType *t); extern String *SwigType_prefix(const SwigType *t); extern int SwigType_array_ndim(SwigType *t); diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index b9d53d5d1..7b1ea529b 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -705,9 +705,9 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type /* look for the type reduced to just the template prefix */ Delete(template_prefix); - template_prefix = SwigType_templateprefix(ctype); - tm = get_typemap(ts, template_prefix); + template_prefix = SwigType_istemplate_templateprefix(ctype); if (template_prefix) { + tm = get_typemap(ts, template_prefix); if (debug_display && cqualifiedname) Printf(stdout, " Looking for: %s\n", SwigType_str(template_prefix, cqualifiedname)); if (tm && cqualifiedname) { diff --git a/Source/Swig/typeobj.c b/Source/Swig/typeobj.c index abd84ee09..81a5aeff1 100644 --- a/Source/Swig/typeobj.c +++ b/Source/Swig/typeobj.c @@ -852,10 +852,12 @@ SwigType *SwigType_add_template(SwigType *t, ParmList *parms) { * SwigType_templateprefix() * * Returns the prefix before the first template definition. + * Returns the type unmodified if not a template. * For example: * * Foo<(p.int)>::bar => Foo * r.q(const).Foo<(p.int)>::bar => r.q(const).Foo + * Foo => Foo * ----------------------------------------------------------------------------- */ String *SwigType_templateprefix(const SwigType *t) { @@ -896,6 +898,25 @@ String *SwigType_templatesuffix(const SwigType *t) { return NewStringEmpty(); } +/* ----------------------------------------------------------------------------- + * SwigType_istemplate_templateprefix() + * + * Combines SwigType_istemplate and SwigType_templateprefix efficiently into one function. + * Returns the prefix before the first template definition. + * Returns NULL if not a template. + * For example: + * + * Foo<(p.int)>::bar => Foo + * r.q(const).Foo<(p.int)>::bar => r.q(const).Foo + * Foo => NULL + * ----------------------------------------------------------------------------- */ + +String *SwigType_istemplate_templateprefix(const SwigType *t) { + const char *s = Char(t); + const char *c = strstr(s, "<("); + return c ? NewStringWithSize(s, c - s) : 0; +} + /* ----------------------------------------------------------------------------- * SwigType_templateargs() *