[C++-sig] Py++ and nested classes

Roman Yakovenko roman.yakovenko at gmail.com
Mon Aug 27 21:11:50 CEST 2007


On 8/27/07, Pertti Kellomäki <pertti.kellomaki at tut.fi> wrote:
> Roman Yakovenko wrote:
> > mb = module_builder_t(...)
> > mb.class_( class name )
> >
> > should do the work
>
> Ah, it did not occur to me to use the base name of
> the class, I was trying to access the inner class as
> "Outer::Inner".

Internally Py++ uses pygccxml defined "matchers".
http://language-binding.net/pygccxml/apidocs/pygccxml.declarations.matchers-module.html

In the case you are looking for declaration by name you can specify:
* full name, for example ::std::wstring
* name only, for example wstring

but you cannot specify partial name

> What happens if I have two inner classes
> with the same name inside two different top level classes?

It depends whether the scope you are looking at, includes both classes
or not and what API do you use.

You can use next API:
* "class_" - returns reference to found declaration, if zero or more
than one declarations found exception is raised.

* "classes" - returns list of all found declarations, you can ask Py++
to raise exception if no declarations were found.

Take a look on this API doc:
http://language-binding.net/pygccxml/apidocs/pygccxml.declarations.scopedef.scopedef_t-class.html

You also can limit the scope:

namespace x{

namespace y{
struct z{};
}

}

mb = module_builder_t( ... )
x = mb.namespace( "x" )
y = x.namespace("y")
y.class_( ... )

> Can I differentiate between them somehow?

Of course, you can ask "decl_string" property value, which contains
declaration full name.

HTH.


-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/



More information about the Cplusplus-sig mailing list