[C++-sig] Trouble with custom container class
Philip Bloom
pbloom at crystald.com
Thu May 14 23:01:18 CEST 2009
Hello,
I'm having some issues with retrieving objects from a custom container
class. The objects in the container are otherwise wrapped objects
(PythonDTPNodeHandle *) that the python wrapper knows how to convert,
but what I get back from the container with __getitem__ seems to not
know how to convert it. I suspect that I'm doing something wrong on
what I'm feeding Py++ and thus the generated wrapping is bad, but I
don't see anything wrong with the final wrapping for getitem or
operator[]. I've no idea why it wouldn't be able to convert, for this
specific usage. Any advise/help would be well welcome. I've included
the whole wrapper at the bottom.
Example use:
Node=Test.getRootNode() #Returns a PythonDTPNodeHandle *
object, which is converted into a PythonDTPNodeHandle refrence in
python.
#print Node - Which is wrapped fine, converting naturally.
array=test.getCDCArray() #Returns the container object. This is a
wrapped cdc::array<PythonDTPNodeHandle *> * object.
#help(array) - Verified Python sees it as cdcArray(super), the
container object
print "Array has: %s elements"%array.size() # Array is empty
node.GetItemChildren(array) #Function call passed the Array. The
function expects a cdc::array<PythonDTPNodeHandle *> * object.
print "Array has: %s elements"%array.size() # Array has 125
elements.
print array[0] #Causes error
anode=array.__getitem__(0) #Causes error.
Output:
Array has: 0 elements
Array has: 125 elements
Traceback (most recent call last):
File "D:\stgame\cdc\tools\cdcPython\DTPXMLNode\example.py", line 43,
in <module>
print array[0]
TypeError: No to_python (by-value) converter found for C++ type: class
PythonDTPNodeHandle *
The getitem wrapped:
{ //::cdc::ArrayImpl< PythonDTPNodeHandle* >::operator[]
typedef cdc::ArrayImpl< PythonDTPNodeHandle* >
exported_class_t;
typedef ::PythonDTPNodeHandle * & (
exported_class_t::*__getitem___function_type )( ::cdc::uint32 ) ;
super_exposer.def(
"__getitem__"
, __getitem___function_type( &::cdc::ArrayImpl<
PythonDTPNodeHandle* >::operator[] )
, ( bp::arg("i") )
, bp::return_internal_reference< >() );
}
My Python Wrapper:
// This file has been generated by Py++.
//CDC DTP Autogenerated Python Interface
#include "boost/python.hpp"
#include "pythondtpscriptinterfacewrapper.h"
#include "cdcsys/array.h"
namespace bp = boost::python;
struct PythonDTPInterface_wrapper : PythonDTPInterface, bp::wrapper<
PythonDTPInterface > {
PythonDTPInterface_wrapper(PythonDTPInterface const & arg )
: PythonDTPInterface( arg )
, bp::wrapper< PythonDTPInterface >(){
// copy constructor
}
PythonDTPInterface_wrapper(char const * szGameRoot )
: PythonDTPInterface( szGameRoot )
, bp::wrapper< PythonDTPInterface >(){
// constructor
}
PythonDTPInterface_wrapper(char const * szGameRoot, char const *
datFile, char const * dtpFile )
: PythonDTPInterface( szGameRoot, datFile, dtpFile )
, bp::wrapper< PythonDTPInterface >(){
// constructor
}
virtual void NotifyDATFileChanged( char const * pDATItemPath ) {
if( bp::override func_NotifyDATFileChanged = this->get_override(
"NotifyDATFileChanged" ) )
func_NotifyDATFileChanged( pDATItemPath );
else
this->PythonDTPInterface::NotifyDATFileChanged( pDATItemPath
);
}
void default_NotifyDATFileChanged( char const * pDATItemPath ) {
PythonDTPInterface::NotifyDATFileChanged( pDATItemPath );
}
};
BOOST_PYTHON_MODULE(DTPScriptInterface){
{ //::PythonDTPInterface
typedef bp::class_< PythonDTPInterface_wrapper >
PythonDTPInterface_exposer_t;
PythonDTPInterface_exposer_t PythonDTPInterface_exposer =
PythonDTPInterface_exposer_t( "PythonDTPInterface", bp::init< char const
* >(( bp::arg("szGameRoot") )) );
bp::scope PythonDTPInterface_scope( PythonDTPInterface_exposer
);
bp::implicitly_convertible< char const *, PythonDTPInterface
>();
PythonDTPInterface_exposer.def( bp::init< char const *, char
const *, char const * >(( bp::arg("szGameRoot"), bp::arg("datFile"),
bp::arg("dtpFile") )) );
{ //::PythonDTPInterface::DumbTestFunction
typedef int (
::PythonDTPInterface::*DumbTestFunction_function_type )( ) ;
PythonDTPInterface_exposer.def(
"DumbTestFunction"
, DumbTestFunction_function_type(
&::PythonDTPInterface::DumbTestFunction ) );
}
{ //::PythonDTPInterface::GetRootNode
typedef ::PythonDTPNodeHandle * (
::PythonDTPInterface::*GetRootNode_function_type )( ) ;
PythonDTPInterface_exposer.def(
"GetRootNode"
, GetRootNode_function_type(
&::PythonDTPInterface::GetRootNode )
, bp::return_value_policy< bp::manage_new_object >() );
}
{ //::PythonDTPInterface::NotifyDATFileChanged
typedef void (
::PythonDTPInterface::*NotifyDATFileChanged_function_type )( char const
* ) ;
typedef void (
PythonDTPInterface_wrapper::*default_NotifyDATFileChanged_function_type
)( char const * ) ;
PythonDTPInterface_exposer.def(
"NotifyDATFileChanged"
,
NotifyDATFileChanged_function_type(&::PythonDTPInterface::NotifyDATFileC
hanged)
,
default_NotifyDATFileChanged_function_type(&PythonDTPInterface_wrapper::
default_NotifyDATFileChanged)
, ( bp::arg("pDATItemPath") ) );
}
{ //::PythonDTPInterface::OpenDATFile
typedef bool (
::PythonDTPInterface::*OpenDATFile_function_type )( char const *,char
const *,bool ) ;
PythonDTPInterface_exposer.def(
"OpenDATFile"
, OpenDATFile_function_type(
&::PythonDTPInterface::OpenDATFile )
, ( bp::arg("datFilenameAndPath"),
bp::arg("dtpFilenameAndPath"), bp::arg("bSavePrevious")=(bool)(true) )
);
}
{ //::PythonDTPInterface::Release
typedef void ( ::PythonDTPInterface::*Release_function_type
)( ) ;
PythonDTPInterface_exposer.def(
"Release"
, Release_function_type( &::PythonDTPInterface::Release
) );
}
{ //::PythonDTPInterface::SaveDATFile
typedef void (
::PythonDTPInterface::*SaveDATFile_function_type )( ) ;
PythonDTPInterface_exposer.def(
"SaveDATFile"
, SaveDATFile_function_type(
&::PythonDTPInterface::SaveDATFile ) );
}
{ //::PythonDTPInterface::getCDCArray
typedef ::cdc::Array< PythonDTPNodeHandle* > * (
::PythonDTPInterface::*getCDCArray_function_type )( ) ;
PythonDTPInterface_exposer.def(
"getCDCArray"
, getCDCArray_function_type(
&::PythonDTPInterface::getCDCArray )
, bp::return_value_policy< bp::manage_new_object >() );
}
{ //::PythonDTPInterface::instantiate
typedef void (
::PythonDTPInterface::*instantiate_function_type )( ) ;
PythonDTPInterface_exposer.def(
"instantiate"
, instantiate_function_type(
&::PythonDTPInterface::instantiate ) );
}
}
bp::class_< PythonDTPNodeHandle, boost::noncopyable >(
"PythonDTPNodeHandle", bp::no_init )
.def(
"AddChild"
, (::PythonDTPNodeHandle * ( ::PythonDTPNodeHandle::* )(
char const * ) )( &::PythonDTPNodeHandle::AddChild )
, ( bp::arg("szName") )
, bp::return_value_policy< bp::manage_new_object >() )
.def(
"DumbNodeTestFunction"
, (int ( ::PythonDTPNodeHandle::* )( ) )(
&::PythonDTPNodeHandle::DumbNodeTestFunction ) )
.def(
"GetChild"
, (::PythonDTPNodeHandle * ( ::PythonDTPNodeHandle::* )(
char const * ) )( &::PythonDTPNodeHandle::GetChild )
, ( bp::arg("szName") )
, bp::return_value_policy< bp::manage_new_object >() )
.def(
"GetItemChildren"
, (void ( ::PythonDTPNodeHandle::* )( ::cdc::Array<
PythonDTPNodeHandle* > * ) )( &::PythonDTPNodeHandle::GetItemChildren )
, ( bp::arg("pAllItemChildren") ) )
.def(
"GetName"
, (char const * ( ::PythonDTPNodeHandle::* )( ) )(
&::PythonDTPNodeHandle::GetName ) )
.def(
"GetTagName"
, (char const * ( ::PythonDTPNodeHandle::* )( ) )(
&::PythonDTPNodeHandle::GetTagName ) )
.def(
"GetValue"
, (char const * ( ::PythonDTPNodeHandle::* )( ) )(
&::PythonDTPNodeHandle::GetValue ) )
.def(
"Release"
, (void ( ::PythonDTPNodeHandle::* )( ) )(
&::PythonDTPNodeHandle::Release ) )
.def(
"RemoveChild"
, (bool ( ::PythonDTPNodeHandle::* )( char const * ) )(
&::PythonDTPNodeHandle::RemoveChild )
, ( bp::arg("szName") ) )
.def(
"SetName"
, (bool ( ::PythonDTPNodeHandle::* )( char const * ) )(
&::PythonDTPNodeHandle::SetName )
, ( bp::arg("szNewName") ) )
.def(
"SetValue"
, (bool ( ::PythonDTPNodeHandle::* )( char const * ) )(
&::PythonDTPNodeHandle::SetValue )
, ( bp::arg("szNewValue") ) );
{ //::cdc::ArrayImpl< PythonDTPNodeHandle* >
typedef bp::class_< cdc::ArrayImpl< PythonDTPNodeHandle* > >
super_exposer_t;
super_exposer_t super_exposer = super_exposer_t( "super",
bp::init< cdc::MemTag >(( bp::arg("tag") )) );
bp::scope super_scope( super_exposer );
bp::implicitly_convertible< cdc::MemTag, cdc::ArrayImpl<
PythonDTPNodeHandle* > >();
super_exposer.def( bp::init< cdc::ArrayImpl<
PythonDTPNodeHandle* > const & >(( bp::arg("x") )) );
{ //::cdc::ArrayImpl< PythonDTPNodeHandle* >::capacity
typedef cdc::ArrayImpl< PythonDTPNodeHandle* >
exported_class_t;
typedef ::cdc::uint32 (
exported_class_t::*capacity_function_type )( ) const;
super_exposer.def(
"capacity"
, capacity_function_type( &::cdc::ArrayImpl<
PythonDTPNodeHandle* >::capacity ) );
}
{ //::cdc::ArrayImpl< PythonDTPNodeHandle* >::clear
typedef cdc::ArrayImpl< PythonDTPNodeHandle* >
exported_class_t;
typedef void ( exported_class_t::*clear_function_type )( )
;
super_exposer.def(
"clear"
, clear_function_type( &::cdc::ArrayImpl<
PythonDTPNodeHandle* >::clear ) );
}
{ //::cdc::ArrayImpl< PythonDTPNodeHandle* >::empty
typedef cdc::ArrayImpl< PythonDTPNodeHandle* >
exported_class_t;
typedef bool ( exported_class_t::*empty_function_type )( )
const;
super_exposer.def(
"empty"
, empty_function_type( &::cdc::ArrayImpl<
PythonDTPNodeHandle* >::empty ) );
}
{ //::cdc::ArrayImpl< PythonDTPNodeHandle* >::operator=
typedef cdc::ArrayImpl< PythonDTPNodeHandle* >
exported_class_t;
typedef ::cdc::ArrayImpl< PythonDTPNodeHandle* > & (
exported_class_t::*assign_function_type )( ::cdc::ArrayImpl<
PythonDTPNodeHandle* > const & ) ;
super_exposer.def(
"assign"
, assign_function_type( &::cdc::ArrayImpl<
PythonDTPNodeHandle* >::operator= )
, ( bp::arg("x") )
, bp::return_self< >() );
}
{ //::cdc::ArrayImpl< PythonDTPNodeHandle* >::operator[]
typedef cdc::ArrayImpl< PythonDTPNodeHandle* >
exported_class_t;
typedef ::PythonDTPNodeHandle * & (
exported_class_t::*__getitem___function_type )( ::cdc::uint32 ) ;
super_exposer.def(
"__getitem__"
, __getitem___function_type( &::cdc::ArrayImpl<
PythonDTPNodeHandle* >::operator[] )
, ( bp::arg("i") )
, bp::return_internal_reference< >() );
}
{ //::cdc::ArrayImpl< PythonDTPNodeHandle* >::operator[]
typedef cdc::ArrayImpl< PythonDTPNodeHandle* >
exported_class_t;
typedef ::PythonDTPNodeHandle * const & (
exported_class_t::*__getitem___function_type )( ::cdc::uint32 ) const;
super_exposer.def(
"__getitem__"
, __getitem___function_type( &::cdc::ArrayImpl<
PythonDTPNodeHandle* >::operator[] )
, ( bp::arg("i") )
, bp::return_value_policy< bp::copy_const_reference >()
);
}
{ //::cdc::ArrayImpl< PythonDTPNodeHandle* >::pop_back
typedef cdc::ArrayImpl< PythonDTPNodeHandle* >
exported_class_t;
typedef void ( exported_class_t::*pop_back_function_type )(
) ;
super_exposer.def(
"pop_back"
, pop_back_function_type( &::cdc::ArrayImpl<
PythonDTPNodeHandle* >::pop_back ) );
}
{ //::cdc::ArrayImpl< PythonDTPNodeHandle* >::push_back
typedef cdc::ArrayImpl< PythonDTPNodeHandle* >
exported_class_t;
typedef void ( exported_class_t::*push_back_function_type )(
::PythonDTPNodeHandle * const & ) ;
super_exposer.def(
"push_back"
, push_back_function_type( &::cdc::ArrayImpl<
PythonDTPNodeHandle* >::push_back )
, ( bp::arg("val") ) );
}
{ //::cdc::ArrayImpl< PythonDTPNodeHandle* >::reserve
typedef cdc::ArrayImpl< PythonDTPNodeHandle* >
exported_class_t;
typedef void ( exported_class_t::*reserve_function_type )(
::cdc::uint32 ) ;
super_exposer.def(
"reserve"
, reserve_function_type( &::cdc::ArrayImpl<
PythonDTPNodeHandle* >::reserve )
, ( bp::arg("n") ) );
}
{ //::cdc::ArrayImpl< PythonDTPNodeHandle* >::shrink_to_size
typedef cdc::ArrayImpl< PythonDTPNodeHandle* >
exported_class_t;
typedef void (
exported_class_t::*shrink_to_size_function_type )( ) ;
super_exposer.def(
"shrink_to_size"
, shrink_to_size_function_type( &::cdc::ArrayImpl<
PythonDTPNodeHandle* >::shrink_to_size ) );
}
{ //::cdc::ArrayImpl< PythonDTPNodeHandle* >::size
typedef cdc::ArrayImpl< PythonDTPNodeHandle* >
exported_class_t;
typedef ::cdc::uint32 (
exported_class_t::*size_function_type )( ) const;
super_exposer.def(
"size"
, size_function_type( &::cdc::ArrayImpl<
PythonDTPNodeHandle* >::size ) );
}
{ //::cdc::ArrayImpl< PythonDTPNodeHandle* >::swap
typedef cdc::ArrayImpl< PythonDTPNodeHandle* >
exported_class_t;
typedef void ( exported_class_t::*swap_function_type )(
::cdc::ArrayImpl< PythonDTPNodeHandle* > & ) ;
super_exposer.def(
"swap"
, swap_function_type( &::cdc::ArrayImpl<
PythonDTPNodeHandle* >::swap )
, ( bp::arg("x") ) );
}
}
{ //::cdc::Array< PythonDTPNodeHandle* >
typedef bp::class_< cdc::Array< PythonDTPNodeHandle* >,
bp::bases< cdc::ArrayImpl< PythonDTPNodeHandle* > > >
cdcArray_exposer_t;
cdcArray_exposer_t cdcArray_exposer = cdcArray_exposer_t(
"cdcArray", bp::init< cdc::MemTag >(( bp::arg("tag") )) );
bp::scope cdcArray_scope( cdcArray_exposer );
bp::implicitly_convertible< cdc::MemTag, cdc::Array<
PythonDTPNodeHandle* > >();
}
}
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20090514/fbea0cc2/attachment-0001.htm>
More information about the Cplusplus-sig
mailing list