2011-03-31 168 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"); 

我認爲這不應該阻止我描述的這樣的錯誤。那麼,怎麼了?

回答