[C++-sig] New to Py++
Rolf Schlup
rschlup at highspeedcrow.ca
Sun Mar 30 16:36:30 CEST 2008
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 "exposed" to be usable. I've tried
the Py++ GUI, but the C++ code I get from it doesn'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/VisualSyst
emTest/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;
std::vector<const VSBasePacket*> m_PacketRefList;
ShVal<VSCommManager> m_CommManager;
private:
VSControl(const VSControl &right);
VSControl & operator=(const VSControl &right);
bool operator==(const VSControl &right) const;
bool operator!=(const VSControl &right) const;
void installDefaultCoordConverter ();
ShVal<VSEntityMan> m_EntityManager;
ShVal<VSTerrainMan> m_TerrainManager;
ShVal<VSSystem> m_System;
ShVal<VSSightMan> m_SightManager;
ShVal<VSWeatherMan> m_WeatherManager;
ShVal<VSTextMan> m_TextManager;
ShVal<VSHudMan> m_HudManager;
ShVal<VSEffectMan> m_EffectManager;
ShVal<VSCelestial> m_Celestial;
ShVal<VSSensorMan> m_SensorManager;
ShVal<VSCreatureMan> m_CreatureManager;
ShVal<VSIsectorMan> m_IsectorManager;
ShVal<VSMunitionMan> m_MunitionManager;
VSConverterBase* m_DefaultConverter;
};
} // namespace N_VisualSystem
#endif
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080330/bffacd3d/attachment.htm>
More information about the Cplusplus-sig
mailing list