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

Rocketman@JSC snemeth at houston.rr.com
Sat Sep 6 23:48:47 CEST 2008


I have a few questions about this thread.  Basically I have the same problem,
my bases for a binding are not getting picked up cause they are in a
separate library.

I've tried solution #2 and here's a snippet from the Py++ generator file:

<<Start
Snippet=================================================================

mb.build_code_creator( module_name='SmpSim' )

# This is an attempt at getting the bases included for Vehicle

baseModel = mb.class_('Model')

print type(mb.code_creator)

baseModel_creators = code_creators.creator_finder.find_by_declaration(
lambda decl: decl is baseModel, mb.code_creator, False )

vehicle = mb.class_('Vehicle') # This is the class I need to add the bases
to
vehicle = ( code_creators.class_t, code_creators.class_wrapper_t )

baseModel_creators = filter( lambda c: isinstance(c, vehicle),
baseModel_creators)

for c in baseModel_creators:
    c.create = lambda: ''
<<End
Snippet=================================================================

and I get the following error:

Traceback (most recent call last):
  File "/data/home/scott/eclipse/Smp_lib/generate_code.py", line 157, in
<module>
    baseModel_creators = code_creators.creator_finder.find_by_declaration(
lambda decl: decl is baseModel, mb.code_creator, False )
  File "/data/apps/oss/lib/python/pyplusplus/code_creators/algorithm.py",
line 87, in find_by_declaration
    , search_area )
TypeError: 'module_t' object is not iterable

I'm sure this is something I'm doing wrong, but I looked at the API's and
could not figure it out.  Does anyone have an idea what I'm doing wrong
here?

Thanks in advance for any help.

Scott


Roman Yakovenko wrote:
> 
> 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
> 
> 

-- 
View this message in context: http://www.nabble.com/-C%2B%2B-sig--Base-class-defined-in-other-header-file-not-included-in-bp%3A%3Abases%3C%3E-tp5299734p19351675.html
Sent from the Python - c++-sig mailing list archive at Nabble.com.




More information about the Cplusplus-sig mailing list