我试图找出一些自动生成(与Pyste)boost :: python代码什么是错的,但迄今没有运气。Boost :: Python与继承类绑定
有C++库,Magick ++,它提供了两个类,Magick::Drawable
和Magick::DrawableRectangle
:
https://www.imagemagick.org/subversion/ImageMagick/trunk/Magick++/lib/Magick++/Drawable.h
class MagickDLLDecl DrawableBase:
public std::unary_function<MagickCore::DrawingWand,void>
{...}
class MagickDLLDecl Drawable
{
public:
// Constructor
Drawable (void);
// Construct from DrawableBase
Drawable (const DrawableBase& original_);
...
}
class MagickDLLDecl DrawableRectangle : public DrawableBase
{ ... }
这些被用作参数为Image.draw()
: https://www.imagemagick.org/subversion/ImageMagick/trunk/Magick++/lib/Magick++/Image.h
// Draw on image using a single drawable
void draw (const Drawable &drawable_);
// Draw on image using a drawable list
void draw (const std::list<Magick::Drawable> &drawable_);
我试图为它做python绑定,那里有auto genned包装的所有类,
http://bitbucket.org/dan.kluev/pythonmagick/src/65d45c998ef3/src/_Drawable.cpp
http://bitbucket.org/dan.kluev/pythonmagick/src/65d45c998ef3/src/_DrawableRectangle.cpp
http://bitbucket.org/dan.kluev/pythonmagick/src/65d45c998ef3/src/_Image.cpp
问题是,由于间接类从DrawableBase强制转换为可绘制,这些包装不工作:
>>> import PythonMagick
>>> image = PythonMagick.Image()
>>> square = PythonMagick._PythonMagick.DrawableRectangle(0,0,200,200)
>>> image.draw(square)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Boost.Python.ArgumentError: Python argument types in
Image.draw(Image, DrawableRectangle)
did not match C++ signature:
draw(Magick::Image {lvalue}, std::list<Magick::Drawable, std::allocator<Magick::Drawable> >)
draw(Magick::Image {lvalue}, Magick::Drawable)
# But abstract Drawable() does work:
>>> image.draw(PythonMagick._PythonMagick.Drawable())
>>>
有没有更好的方式来处理这个问题,比在C + +中编写我自己的draw() +,这会将PyObject转换为Drawable?
这应该被标记为'pyste'以及'boost-python'。 – 2010-12-02 17:14:32
@Matthew,之前使用pyste自动编码,但现在被丢弃,代码被支持w/out它。 – 2010-12-03 01:35:46