[C++-sig] Base class defined in other header file not includedin bp::bases<>

Roman Yakovenko roman.yakovenko at gmail.com
Fri Jul 14 10:34:43 CEST 2006

On 7/13/06, Haridev, Meghana <mharidev at qualcomm.com> wrote:
> In other words, I want the generated code to look like this:
>     /* bp::class_< baseB >( "baseB" );  - Do not want to generate */
>     bp::class_< baseA >( "baseA" );
>     bp::class_< derivedC, bp::bases< baseA, baseB > >( "derivedC" );

It is possible, but you will have to understand a little how code
creators works.
There are few ways to solve the problem.

1. Exclude baseB from being generated, and add it manually to derivedC.
    Take a look on pyplusplus/code_creators/class_declaration.py -
class "class_t",
    method - _generate_bases. You will have to redefine this method, something
    like this:

    def my_generate_bases( self, base_creators ):
        if self.declaration.Name != 'derivedC':
            run current code
            your logic is going her

   pyplusplus.code_creators.class_t._generate_bases = my_generate_bases

2. You can include baseB to be generated, but instead of generating code it
    will generate empty string:

    mb = module_builder_t( ... )
    mb.build_code_creators( ... )

    from pyplusplus import code_creators

    baseB = mb.class_( 'baseB' )

    baseB_creators \
        = code_creators.creator_finder.find_by_declaration(
                     lambda decl: decl is baseB #what to look
                     , mb.code_creator ) #where
    #now, we have to leave only class_t and class_wrapper_t code creators
     relevant_clss = ( code_creators.class_t, code_creators.class_wrapper_t )
     baseB_creators = filters( lambda c: isinstance( c, relevant_clss ) )
     for c in baseB_creators:
         c.create = lambda self: ''

Second approach is better, because in this case pyplusplus will take
into account
all data available from baseB, but will not generate code.

Roman Yakovenko
C++ Python language binding

More information about the Cplusplus-sig mailing list