2011-03-31 163 views
3

我正在使用boost python。我已经导出了一些参数中需要类CL_DomElement的函数。现在,当我运行的应用程序,我有:将类型转换为python

TypeError: No to_python (by-value) converter found for C++ type: CL_DomElement 

那么代码呢。我已经导出了函数,它在参数中使用函数指针。下面是代码:

typedef boost::function<boost::shared_ptr<Object> (CL_DomElement*, std::string& desc)> Parser; 
void registerParser(std::string type, Parser p); 

struct ParserProxy 
{ 
    bp::object callable; 

    ParserProxy(bp::object callable) 
    : callable(callable) 
    { } 

    boost::shared_ptr<Object> operator()(CL_DomElement* elem, std::string& desc) 
    { 
     bp::object obj = callable(elem, desc); 
     return bp::extract<boost::shared_ptr<Object> >(obj); 
    } 
}; 

void registerParserByProxy(std::string type, bp::object callable) 
{ 
    registerParser(type, ParserProxy(callable)); 
} 

// In some boost.python module 
bp::def("RegisterParser", registerParserByProxy); 

注册我是这样(在python):

class TestObj(Object): 
    @staticmethod 
    def ParseTestObj(node, desc): 
     print 'Parser is called!' 
# Register parser 
RegisterParser("testobj", TestObj.ParseTestObj) 

它成功注册,检查我的地图(注册解析器增加了通过键→值成的std ::地图),一切都很好(新增值)。现在,我想打电话给传递指针:

boost::shared_ptr<Object> TypesManager::parseObject(CL_DomElement* objectTag, const std::string &type, std::string &desc) 
{ 
    return (getParser(type))(objectTag, desc); 
} 

getParser从收益的std ::地图键type函数指针。


所以,据我所知,通过类CL_DomElement类错误。但我在我的模块中:

bp::class_<CL_DomElement>("CL_DomElement"); 

我认为这不应该阻止我描述的这样的错误。那么,怎么了?

回答