[C++-sig] Header error in boost/python/object/make_holder?
Roman Yakovenko
roman.yakovenko at gmail.com
Tue Oct 16 12:31:39 CEST 2007
On 10/15/07, Thomas Hauk <thauk at novuscom.net> wrote:
>
> On Oct 15, 2007, at 12:43 PM, David Abrahams wrote:
> > 9 times out of 10, preparing a minimal example reveals the actual
> > problem to the person asking the question ;-)
>
> Speaking of which, and I'm changing the subject rather selfishly, but
> I still haven't had an answer about what the bindings to:
>
> struct Foo
> {
> unsigned char data[4];
> };
>
> should be... and I don't think that type of question to this
> newsgroup gets any more minimal than that. :)
>
Next code was generated by Py++, may be it is not optimal but it does the
work. __array_1.pypp.hpp file is attached
#include "boost/python.hpp"
#include "__array_1.pypp.hpp"
#include "1.hpp"
namespace bp = boost::python;
struct Foo_wrapper : Foo, bp::wrapper< Foo > {
Foo_wrapper(Foo const & arg )
: Foo( arg )
, bp::wrapper< Foo >(){
// copy constructor
}
Foo_wrapper()
: Foo()
, bp::wrapper< Foo >(){
// null constructor
}
static pyplusplus::containers::static_sized::array_1_t< unsigned char,
4>
pyplusplus_data_wrapper( ::Foo & inst ){
return pyplusplus::containers::static_sized::array_1_t< unsigned
char, 4>( inst.data );
}
};
BOOST_PYTHON_MODULE(pyplusplus){
{ //::Foo
typedef bp::class_< Foo_wrapper > Foo_exposer_t;
Foo_exposer_t Foo_exposer = Foo_exposer_t( "Foo" );
bp::scope Foo_scope( Foo_exposer );
pyplusplus::containers::static_sized::register_array_1< unsigned
char, 4 >( "__array_1_unsigned_char_4" );
{ //Foo::data [variable], type=unsigned char[4]
typedef pyplusplus::containers::static_sized::array_1_t<
unsigned char, 4> ( *array_wrapper_creator )( ::Foo & );
Foo_exposer.add_property( "data"
, bp::make_function(
array_wrapper_creator(&Foo_wrapper::pyplusplus_data_wrapper)
, bp::with_custodian_and_ward_postcall<
0, 1 >() ) );
}
}
}
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20071016/12a072d1/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: __array_1.pypp.hpp
Type: text/x-c++hdr
Size: 5152 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20071016/12a072d1/attachment.hpp>
More information about the Cplusplus-sig
mailing list