[C++-sig] Lost Again! :)
Roman Yakovenko
roman.yakovenko at gmail.com
Fri Sep 1 09:55:25 CEST 2006
On 9/1/06, Nicolas Tessore <wz_ at gmx.net> wrote:
> Nicolas Tessore wrote:
> >> from pygccxml import declarations
> >>
> >> def rename_cast( cast ):
> >> cls_to = declarations.class_traits.get_declaration( cast.return_type )
> >> cast.rename( 'DynamicCastTo' + cls_to.name )
> >>
> >> casts = mb.free_functions ( lambda decl: decl.name.startswith(
> >> 'DynamicCast<' ) )
> >> map( rename_cast, casts )
> >
> > This always leaves me with a "query returned no matches" error :(
> Ok, I figured this out myself. GCCXML does not save the template part of
> the name, so all those functions are called "DynamicCast". I slightly
> modified your approach:
>
> 01: #Find object type in Casts. Const T casts are ignored
> 02: pattern = "::Mylib::Ref<Mylib::(.*)>"
> 03: p = re.compile(pattern)
> 04:
> 05: def rename_casts( cast ):
> 06: m = p.match(cast.return_type.decl_string)
> 07: if m:
> 08: cast.rename( cast.name + 'To' + m.groups()[0] )
> 09: else: #DynamicCast should be excluded
> 10: cast.exclude()
> 11:
> 12: casts = mb.free_functions ( lambda decl: ( decl.name ==
> 'DynamicCast' or decl.name == 'StaticCast' ) )
> 13: map( rename_casts, casts )
>
> This works beautifully :) But is it a correct approach?
If it works, that the answer is yes.
> And it clearly
> shows I barely scratched the surface of the power that Py++/ pygccxml
> hold :/
Please take a look on
http://language-binding.net/pygccxml/apidocs/pygccxml.declarations.templates-module.html
The functionality provided by this module will do the job for you.
But you ignored my advice:
cls_to = declarations.class_traits.get_declaration( cast.return_type )
cast.rename( 'DynamicCastTo' + cls_to.name )
You don't have to parse, just extract class declaration from DynamicCast return
type.
> Now while still giggling at the wonderful result I saw, it happened that
> I noticed my typedefs à la
>
> typedef Mylib::Ref<Mylib::MyClass> MyClassRef;
> sizeof(MyClassRef);
>
> are not automatically detected and thus, the Mylib::Ref<Mylib::MyClass>
> is still named Mylib_scope_Ref_less_than_Mylib_scope_MyClass_grate etc
> in the generated binding source. Any clues why that could be? It is not
> a problem though, I will just apply the same method as above to them.
Read this: http://language-binding.net/pyplusplus/documentation/hints.html
It should explain why Py++ does not work as you expects.
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
More information about the Cplusplus-sig
mailing list