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

Haridev, Meghana mharidev at qualcomm.com
Wed Jul 26 21:01:26 CEST 2006


Hi Roman,

 

I tried your second approach since it goes better with our environment.
I made some changes (highlighted in bold below) to get it to run. It
works fine till I come to the point where I need to write the module to
multiple files (or even just a single file).

 

mb = module_builder_t( ... )

mb.class_('baseB').include() #because baseB defined in header file in
diff directory

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 = filter( lambda c: isinstance( c, relevant_clss ),
baseB_creators )

 

for c in baseB_creators:

         c.create = lambda self: ''

 

mb.split_module( os.path.abspath('.') )

 

 

I get this error:

 

  File "generate_code.py", line 80, in export

    mb.split_module( os.path.abspath('.') )

  File "...pyplusplus/module_builder/builder.py", line 224, in
split_module

    file_writers.write_multiple_files( self.code_creator, dir_name )

  File "...pyplusplus/file_writers/__init__.py", line 32, in
write_multiple_files

    mfs.write()

  File "...pyplusplus/file_writers/multiple_files.py", line 253, in
write

    map( self.split_class, class_creators )

  File "...pyplusplus/file_writers/multiple_files.py", line 171, in
split_class

    self.__split_class_impl( class_creator )

  File "...pyplusplus/file_writers/multiple_files.py", line 148, in
__split_class_impl

    , [class_creator] ))

  File "...pyplusplus/file_writers/multiple_files.py", line 126, in
create_source

    answer.append( creator.wrapper.create() )

TypeError: <lambda>() takes exactly 1 argument (0 given)

 

 

Seems like it doesn't like the empty string we give to create...

 

I also tried just writing the module to a single file:

mb.write_module( os.path.join( os.path.abspath('.'),
settings.module_name + '.cpp' ) )

 

  File "...pyplusplus/module_builder/builder.py", line 215, in
write_module

    file_writers.write_file( self.code_creator, file_name )

  File "...pyplusplus/file_writers/__init__.py", line 28, in write_file

    sf.write()

  File "...pyplusplus/file_writers/single_file.py", line 24, in write

    self.write_file( self.file_name, self.extmodule.create() )

  File "...pyplusplus/code_creators/code_creator.py", line 93, in create

    code = self._create_impl()

  File "...pyplusplus/code_creators/module.py", line 195, in
_create_impl

    code = compound.compound_t.create_internal_code(
self.creators[index:] )

  File "...pyplusplus/code_creators/compound.py", line 56, in
create_internal_code

    internals = map( lambda expr: expr.create(), creators )

  File "...pyplusplus/code_creators/compound.py", line 56, in <lambda>

    internals = map( lambda expr: expr.create(), creators )

TypeError: <lambda>() takes exactly 1 argument (0 given)

 

Any suggestions?

 

Thanks,

-Meghana.

 

 

-----Original Message-----
From: c++-sig-bounces+mharidev=qualcomm.com at python.org
[mailto:c++-sig-bounces+mharidev=qualcomm.com at python.org] On Behalf Of
Roman Yakovenko
Sent: Friday, July 14, 2006 1:35 AM
To: Development of Python/C++ integration
Subject: Re: [C++-sig] Base class defined in other header file
notincludedin bp::bases<>

 

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

        else:

            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

http://www.language-binding.net/

_______________________________________________

C++-sig mailing list

C++-sig at python.org

http://mail.python.org/mailman/listinfo/c++-sig

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060726/40dfa845/attachment.htm>


More information about the Cplusplus-sig mailing list