How to expose self defined type in boost.python

Hi, I try to use boost.python to invoke C++ library in Python, so I need to expose types and classes. Here is the c++ head file: *typedef int XTYPE;* *class XCLASS* *{* *public:* * XTYPE getvalue( void ){ return XTYPE( 3 ); }* *};* So I write exposing code in BOOST_PYTHON_MODULE like this: *BOOST_PYTHON_MODULE( x )* *{* * class_< XCLASS >( "XCLASS" )* * .def( "getvalue", &XCLASS::getvalue, return_value_policy< copy_non_const_reference >() )* * ;* *}* but there is compiling error as using of undefined type. what shall I do to make the type XTYPE known by boost.python? Thanks in advance! -- Huang You Gong

I checked the maillist history, and there are guys who have the same
question with me.
class btQuadWord
{
protected:
btScalar m_x;
btScalar m_y;
btScalar m_z;
btScalar m_unusedW;
public:
SIMD_FORCE_INLINE const btScalar& getX() const { return m_x;
}
};
class_<btQuadWord>("btQuadWord")
.def("getX", &btQuadWord::getX)
;
see here: http://lists.boost.org/boost-users/2007/05/27828.php
the same question is, when the function return a value which type is not a
basic type ( even a pointer ), there will be errors.
On 1/14/08, Huang You Gong
Hi,
I try to use boost.python to invoke C++ library in Python, so I need to expose types and classes. Here is the c++ head file:
*typedef int XTYPE;* *class XCLASS* *{* *public:* * XTYPE getvalue( void ){ return XTYPE( 3 ); }* *};*
So I write exposing code in BOOST_PYTHON_MODULE like this:
*BOOST_PYTHON_MODULE( x )* *{* * class_< XCLASS >( "XCLASS" )* * .def( "getvalue", &XCLASS::getvalue, return_value_policy< copy_non_const_reference >() )* * ;* *}*
but there is compiling error as using of undefined type. what shall I do to make the type XTYPE known by boost.python? Thanks in advance!
-- Huang You Gong
-- Huang You Gong

on Mon Jan 14 2008, "Huang You Gong"
Hi,
I try to use boost.python to invoke C++ library in Python, so I need to expose types and classes. Here is the c++ head file:
typedef int XTYPE; class XCLASS { public: XTYPE getvalue( void ){ return XTYPE( 3 ); } };
So I write exposing code in BOOST_PYTHON_MODULE like this:
BOOST_PYTHON_MODULE( x ) { class_< XCLASS >( "XCLASS" ) .def( "getvalue", &XCLASS::getvalue, return_value_policy< copy_non_const_reference >() ) ; }
but there is compiling error as using of undefined type.
The return_value_policy is wrong. The type returned by getvalue is not a reference type.
what shall I do to make the type XTYPE known by boost.python? Thanks in advance!
Boost.Python already knows about int. -- Dave Abrahams Boost Consulting http://boost-consulting.com
participants (2)
-
David Abrahams
-
Huang You Gong