[C++-sig] pygccxml and inner classes

Roman Yakovenko roman.yakovenko at gmail.com
Mon Nov 29 21:22:39 CET 2010


On Mon, Nov 29, 2010 at 8:36 AM, Davidson, Josh <josh.davidson at lmco.com>wrote:

> I'm wondering if this behavior is correct when using pygccxml.  Consider
> the following two sets of simple class definitions:
>
> -------------- SET 1 ----------------------
> class inner {
> protected:
>    unsigned a;
>    unsigned b;
>    unsigned c;
> };
>
> class Cool {
> public:
>    Cool(){}
>
> protected:
>    int x;
>    int y;
>    int z;
>
>    inner i;
> };
>
> -------------- SET 2 ----------------------
> class Cool {
> public:
>    Cool();
>
> protected:
>    class inner {
>    protected:
>        unsigned a;
>        unsigned b;
>        unsigned c;
>    };
>
>    int x;
>    int y;
>    int z;
>
>    inner i;
> };
>
> -------------- END ----------------------
>
> So you'll notice that the only difference between 1 & 2 is that 2, defines
> "inner" as an inner class.  Now, if I parse a header file containing those
> classes, obtain a reference to the pygccxml for class Cool and print it's
> variables like so:
>
> for var in classType.variables():
>  print "var", var.name, var.type
>
> This is what I get:
>
> SET 1
> var x int
> var y int
> var z int
> var i inner
>
> SET 2
> var x int
> var y int
> var z int
> var i Cool::inner
> var a unsigned int
> var b unsigned int
> var c unsigned int
>
>
> As you can see, when I is an inner class, the inner class's members show up
> in the parent class in addition to the inner class itself.  Is this behavior
> correct?  In SET 2, I would not expect to see a, b, and c show up as members
> of class Cool.  If this behavior is correct, is there a way to filter out
> those members that belong to the inner class?
>
>
This is the current package behavior. Another interesting use case, you can
bring, is based classes. You will not see the variables from the base
classes.

Take a look on this document:
http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pygccxml_dev/docs/query_interface.rest?revision=1727&view=markup
and
then on pygccxml/declarations/scopedef.py - variables method.


In your case, it is very simple to get the desired variables:

class_vars = classType.variables( lambda var: var.parent is classType )


HTH
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20101129/8093e44f/attachment.html>


More information about the Cplusplus-sig mailing list