I'm using boost python. I've exported some function which takes class CL_DomElement
in arguments. Now, when I run app I have:
TypeError: No to_python (by-value) converter found for C++ type: CL_DomElement
So what about code. I've exported function which takes function-pointer in arguments. Here is the code:
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);
I register it this way (in python):
class TestObj(Object):
@staticmethod
def ParseTestObj(node, desc):
print 'Parser is called!'
# Register parser
RegisterParser("testobj", TestObj.ParseTestObj)
It successfully registers, I check my map (register parser adds passed key→value into std::map) and everything is fine there (new value is added). Now I want to call passed pointer:
boost::shared_ptr<Object> TypesManager::parseObject(CL_DomElement* objectTag, const std::string &type, std::string &desc)
{
return (getParser(type))(objectTag, desc);
}
getParser
returns function-pointer from std::map with key type
.
So, as I understand something wrong with passing class CL_DomElement
. But I did in my module:
bp::class_<CL_DomElement>("CL_DomElement");
I think this shouldn't prevent such errors I described. So, what's wrong?