List Info

Thread: New to Py++




New to Py++
country flaguser name
Canada
2008-03-30 09:36:30

Hi all,

  I’m new to Py++ and I need to create bindings for a Visual Simulation control library for the company I work for.  The library consists of over 200 classes of which 50 or need to be “;exposed221; to be usable.  I’ve tried the Py++ GUI, but the C++ code I get from it doesn̵7;t compile.  There is one main interface class – VSControl -  that has methods for returning references to members ( mostly of other classes ).  Some of the classes have forward referencing of their dependencies which causes the C++ to completely haywire and I’m thinking it has something to do with how Py++ generates the wrapper code. ; I’m also having a lot of issues with Call Policies. Mainly, the ones that have with return of reference types are giving me warnings when I generate the C++ code. ; I’ve been using the followingcode, but the resulting C++ code only compiles when I manually add the necessary header files to the generated code. ; But, then when I try to import it, I get unresolved reference errors.  If I try to add all necessary files to the builder lines, the warnings and compiler errors increase exponentially.  Again, any help or examples that can yield usable binding code will be appreciated.  I’ve included the VSControl header file at the end of this message.

 

Thank you in advance

 

Rolf Schlup

 

 

***************************************************************************************************************************************************************************

#!/usr/bin/python

import os

import sys

sys.path.append( '../../../..' )

from pyplusplus import module_builder

from pyplusplus.module_builder import call_policies

from pygccxml import declarations

from pygccxml.declarations import custom_matcher_t as c_matcher

from pygccxml.declarations import regex_matcher_t as re_matcher

#Creating an instance of class that will help you to expose your declarations

 

mb = module_builder.module_builder_t( files=[ 'VSControl.hpp']

           ;           ;           ;     , gccxml_path=r"/usr/local/bin/gccxml"

           ;           ;           ;     , working_directory=r"/home/rolf/source/ws_stes/BER/cobusiness/test/VisualSystemTest/VSPython/"

                   ;           ;        , include_paths=['/home/rolf/source/ws_stes/BER/cobusiness/VisualSystem/VSCore'

           ;           ;           ;           ;          ,'/home/rolf/source/ws_stes/BER/cobusiness/VisualSystem/VSCommBase'

           ;           ;        ;           ;           ;  ,'/home/rolf/source/ws_stes/BER/cobusiness/VisualSystem/VSException'

           ;           ;           ;           ;          ,'/home/rolf/source/ws_stes/UNT/real/Types'

           ;           ;           ;           ;          ,'/home/rolf/source/ws_stes/BER/cobusiness/VisualSystem/VSCoordConverter'

           ;           ;           ;           ;          ,'/home/rolf/source/ws_stes/BER/cobusiness/VisualSystem/VSEnumAndTypes'

           ;           ;           ;           ;          ,'/home/rolf/source/ws_stes/BER/cobusiness/VisualSystem/VSDefFileReader'

           ;           ;           ;           ;          ,'/usr/include/python/'

           ;           ;           ;           ;          ,'/home/rolf/source/ws_stes/BER/real/'

           ;                   ;           ;           ;  ,'/home/rolf/source/ws_stes/BER/real/Global'

           ;           ;           ;           ;          ,'/home/rolf/source/ws_stes/BER/reglobal'

           ;           ;           ;           ;          ,'/home/rolf/source/ws_stes/BER/cobusiness/'

           ;           ;           ;           ;          ,'/home/rolf/source/ws_stes/UNT/real/'

           ;           ;           ;           ;          ,'/home/rolf/source/ws_stes/BER/cobusiness/VisualSystem/VSCommManager'

           ;                   ;           ;           ;  ,'/home/rolf/source/ws_stes/BER/cobusiness/VisualSystem/VSComm'

           ;           ;           ;           ;          ]

           ;           ;           ;     , define_symbols=[] )

# The following 2 lines do not have any effect

mb.build_code_creator('VSControl')

mb.code_creator.add_include( "path.hpp" )

 

mem_funs = mb.calldefs()

mem_funs.create_with_signature = True

for mem_fun in mem_funs:

  if mem_fun.call_policies:

    continue

  if not mem_fun.call_policies and (declarations.is_reference(mem_fun.return_type) or declarations.is_pointer (mem_fun.return_type)

  ):

     mem_fun.call_policies = call_policies.return_value_policy(call_policies.reference_existing_object )

 

 

#Well, don't you want to see what's going on?

mb.print_declarations()

 

#Give a name to the module. After this step you should not modify/customize declarations.

mb.build_code_creator( module_name='vscontrol' )

 

#I don't want absolute includes within code

mb.code_creator.user_defined_directories.append( os.path.abspath('.') )

 

#Write code to file.

mb.write_module( os.path.join( os.path.abspath('.'),'VSControl_Bindings.cpp' ) )

 

***************************************************************************************************************************************************

 

 

#ifndef VSControl_h

#define VSControl_h 1

 

#include "Global/REALGlobal.hpp"

#include "VisualSystem/VSCommBase/VSAllPacketDefinitions.hpp"

 

namespace N_VisualSystem {

  class VSBasePacket;

  class VSCommManager;

  class VSConverterBase;

  class VSMunitionMan;

  class VSIsectorMan;

  class VSCreatureMan;

  class VSSensorMan;

  class VSCelestial;

  class VSEntityMan;

  class VSObjectAllocater;

  class VSSystem;

  class VSEffectMan;

  class VSTerrainMan;

  class VSHudMan;

  class VSTextMan;

  class VSWeatherMan;

  class VSSightMan;

 

} // namespace N_VisualSystem

 

namespace N_VisualSystem {

 

  class VSControl

  {

    public:

        VSControl ();

        virtual ~VSControl();

        virtual bool init (const std::string& a_configFileName, const std::string& a_interfaceName);

        VSWeatherMan& getWeatherMan ();

        VSCelestial& getCelestial () const;

        VSCreatureMan& getCreatureMan () const;

        VSEffectMan& getEffectMan ();

        VSEntityMan& getEntityMan () const;

        VSHudMan& getHudMan ();

        VSIsectorMan& getIsectorMan () const;

        VSMunitionMan& getMunitionMan ();

        VSSensorMan& getSensorMan ();

        VSSightMan& getSightMan () const;

        VSSystem& getSystem ();

        VSTerrainMan& getTerrainMan ();

        VSTextMan& getTextMan ();

        virtual bool isUpdateRequested ();

        void startUpdate ();

        void endUpdate ();

        bool getConnectionState () const;

        void preUpdate ();

 

    protected:

        void createPacketRefList ();

        void evalIncommingPackets (const std::vector<VSBasePacket*>& a_packetList);

        void handleSystemResponse (const VSSystemPacket& a_systemPacket);

        void handleCollisionResponse ();

        void handleTerrainResponse (const VSTerrainResponsePacket& a_terrainPacket);

        void handleEffectResponse (const VSEffectResponsePacket& a_effectResponsePacket);

        VSCommManager& getCommManager ();

        void handleIsectorResponse (const VSBasePacket& a_isectorPacket);

        bool m_Initialized;

 &nbsp; &nbsp; &nbsp;  std::vector<const VSBasePacket*> m_PacketRefList;

 &nbsp; &nbsp; &nbsp;  ShVal<VSCommManager> m_CommManager;

 &nbsp;  private:

 &nbsp; &nbsp; &nbsp;  VSControl(const VSControl &right);

 &nbsp; &nbsp; &nbsp;  VSControl & operator=(const VSControl &right);

 &nbsp; &nbsp; &nbsp;  bool operator==(const VSControl &right) const;

 &nbsp; &nbsp; &nbsp;  bool operator!=(const VSControl &right) const;

 &nbsp; &nbsp; &nbsp;  void installDefaultCoordConverter ();

 

 &nbsp; &nbsp; &nbsp;  ShVal<VSEntityMan&gt; m_EntityManager;

 &nbsp; &nbsp; &nbsp;  ShVal<VSTerrainMan> m_TerrainManager;

 &nbsp; &nbsp; &nbsp;  ShVal<VSSystem> m_System;

 &nbsp; &nbsp; &nbsp;  ShVal<VSSightMan&gt; m_SightManager;

 &nbsp; &nbsp; &nbsp;  ShVal<VSWeatherMan> m_WeatherManager;

 &nbsp; &nbsp; &nbsp;  ShVal<VSTextMan>; m_TextManager;

 &nbsp; &nbsp; &nbsp;  ShVal<VSHudMan> m_HudManager;

 &nbsp; &nbsp; &nbsp;  ShVal<VSEffectMan&gt; m_EffectManager;

 &nbsp; &nbsp; &nbsp;  ShVal<VSCelestial&gt; m_Celestial;

 &nbsp; &nbsp; &nbsp;  ShVal<VSSensorMan&gt; m_SensorManager;

 &nbsp; &nbsp; &nbsp;  ShVal<VSCreatureMan> m_CreatureManager;

 &nbsp; &nbsp; &nbsp;  ShVal<VSIsectorMan> m_IsectorManager;

 &nbsp; &nbsp; &nbsp;  ShVal<VSMunitionMan> m_MunitionManager;

 &nbsp; &nbsp; &nbsp;  VSConverterBase* m_DefaultConverter;

 

  };

 

 

} // namespace N_VisualSystem

 

#endif

 

Re: New to Py++
user name
2008-03-30 12:13:47
2008/3/30 Rolf Schlup <rschluphighspeedcrow.ca>:
> Hi all,

Good evening

>   I'm new to Py++ and I need to create bindings for a
Visual Simulation
> control library for the company I work for.  The
library consists of over
> 200 classes of which 50 or need to be
"exposed" to be usable.  I've tried
> the Py++ GUI, but the C++ code I get from it doesn't
compile.

Py++ GUI was created to suite single goal: to show what code
generates
Py++, without customization. You can use it almost as-is in
small
projects or when you just start with Boost.Python.

> There is one
> main interface class – VSControl -  that has methods
for returning
> references to members ( mostly of other classes ). 
Some of the classes have
> forward referencing of their dependencies which causes
the C++ to completely
> haywire and I'm thinking it has something to do with
how Py++ generates the
> wrapper code.

Well, you can expose forward declarated classes as opaque
type. I
think that Py++ doesn't support thi use case. Normally what
you want
is to expose that classes too.

In order to do this, you need to create header file, that
will include
all relevant files and than to path is to Py++

> I'm also having a lot of issues with Call Policies.
Mainly,
> the ones that have with return of reference types are
giving me warnings
> when I generate the C++ code.  I've been using the
followingcode, but the
> resulting C++ code only compiles when I manually add
the necessary header
> files to the generated code.

I guess this errors relaed to forward declarations. Try to
pass single
header file, built as described above.

>  But, then when I try to import it, I get
> unresolved reference errors.

I think this error is related to your environment. Use
"dependency
viewer" to verify that your dll can load others.

>If I try to add all necessary files to the
> builder lines, the warnings and compiler errors
increase exponentially.
> Again, any help or examples that can yield usable
binding code will be
> appreciated.

I need more specific error description. From my experience
it is
better to start from something small, just few classes. To
get to the
point you can import and use few simple exported classes and
than
start to add other classes and functions.

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-
binding.net/
_______________________________________________
C++-sig mailing list
C++-sigpython.org
http:
//mail.python.org/mailman/listinfo/c++-sig

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )