Discussion:
[Swig-devel] How do I extract B from A<B>?
Eric Ehlers
2015-09-06 17:08:34 UTC
Permalink
Hello,

Suppose my interface file says:

void f(std::vector<int>);

How in my Language class would I parse the above
and isolate the token "int"?

Here is my attempt:

int functionHandler(Node *n) {
ParmList *parms = Getattr(n, "parms");
for (Parm *p = parms; p; p = nextSibling(p)) {
SwigType *t1 = Getattr(p, "type");
// prints "t1 = std::vector< int >"
printf("t1 = %s\n", Char(SwigType_str(t1, 0)));
// prints "is_template=1"
printf("is_template=%d\n", SwigType_istemplate(t1));
// This doesn't compile :(
//SwigType *t2 = SwigType_pop_template(t1);
}
return Language::functionHandler(n);
}

So far the only solution I can find is to take
t1 ("std::vector< int >"),
convert it into a char*, parse it,
and extract everything between the <>s.
Is there a better way?

Many Thanks,
Eric

------------------------------------------------------------------------------
William S Fulton
2015-09-15 22:24:22 UTC
Permalink
No, you aren't using SWIG correctly. Take a look at
Lib/csharp/std_vector.i for how to handle std::vector primitive types
differently to classes. Basically you use template specialization.

William
Post by Eric Ehlers
Hello,
void f(std::vector<int>);
How in my Language class would I parse the above
and isolate the token "int"?
int functionHandler(Node *n) {
ParmList *parms = Getattr(n, "parms");
for (Parm *p = parms; p; p = nextSibling(p)) {
SwigType *t1 = Getattr(p, "type");
// prints "t1 = std::vector< int >"
printf("t1 = %s\n", Char(SwigType_str(t1, 0)));
// prints "is_template=1"
printf("is_template=%d\n", SwigType_istemplate(t1));
// This doesn't compile :(
//SwigType *t2 = SwigType_pop_template(t1);
}
return Language::functionHandler(n);
}
So far the only solution I can find is to take
t1 ("std::vector< int >"),
convert it into a char*, parse it,
and extract everything between the <>s.
Is there a better way?
Many Thanks,
Eric
------------------------------------------------------------------------------
_______________________________________________
Swig-devel mailing list
https://lists.sourceforge.net/lists/listinfo/swig-devel
------------------------------------------------------------------------------
Loading...