← Back to team overview

ffc team mailing list archive

Solution for nested classes for SWIG

 

Hi!

I think I've found a solution for helping SWIG parse nested
classes. The only thing that's necessary seems to be to move the class
definition out to the top level:

class MyClass
{
public:
  MyClass(double d);

  double foo();
  double d;

  class Internal;
};

class MyClass::Internal
{
public:
  Internal(double e);

  double bar();
  double e;
};

Now the SWIG parser doesn't seem to have any problems parsing the
nested class. Then the naming issues can be taken care of by the
rename directive:

%rename(MyClassInternal) MyClass::Internal;

Here's a thread discussing it:

http://mailman.cs.uchicago.edu/pipermail/swig/2004-April/009591.html

This is a bit worrying though:

"it should be possible simply to hoist the nested class out of the
containing class and pretend as if they were defined consecutively.
This was dismissed as a hack (although I don't understand why) and
that a better scheme was in the works."

But just like the poster, I can't see why that would be a hack.

I'll do some more testing and see what I can find out.

  Johan



Follow ups