mirror of
https://github.com/boostorg/python.git
synced 2026-01-22 17:32:55 +00:00
Convertibility checks now collect the auxiliary conversion data
[SVN r12186]
This commit is contained in:
@@ -39,35 +39,6 @@ namespace registry
|
||||
{
|
||||
}
|
||||
|
||||
namespace // <unnamed>
|
||||
{
|
||||
// A UnaryFunction type which deletes its argument
|
||||
struct delete_item
|
||||
{
|
||||
template <class T>
|
||||
void operator()(T* x) const
|
||||
{
|
||||
delete x;
|
||||
}
|
||||
};
|
||||
|
||||
// A UnaryFunction type which returns true iff its argument is a
|
||||
// unwrapper which can convert the given Python object.
|
||||
struct convertible
|
||||
{
|
||||
convertible(PyObject* p)
|
||||
: m_p(p)
|
||||
{}
|
||||
|
||||
bool operator()(unwrapper_base* converter) const
|
||||
{
|
||||
return converter->convertible(m_p);
|
||||
}
|
||||
|
||||
PyObject* m_p;
|
||||
};
|
||||
}
|
||||
|
||||
entry::~entry()
|
||||
{
|
||||
if (m_wrapper != 0)
|
||||
@@ -79,12 +50,25 @@ namespace registry
|
||||
}
|
||||
}
|
||||
|
||||
unwrapper_base* entry::unwrapper(PyObject* p) const
|
||||
std::pair<unwrapper_base*,void*>
|
||||
entry::unwrapper(PyObject* p) const
|
||||
{
|
||||
unwrappers::const_iterator q =
|
||||
std::find_if(m_unwrappers.begin(), m_unwrappers.end(), convertible(p));
|
||||
unwrapper_base* body = 0;
|
||||
void* data = 0;
|
||||
|
||||
return q == m_unwrappers.end() ? 0 : *q;
|
||||
for (unwrappers::const_iterator q = m_unwrappers.begin(),
|
||||
finish = m_unwrappers.end();
|
||||
q != finish;
|
||||
++q)
|
||||
{
|
||||
data = (*q)->can_convert(p);
|
||||
if (data != 0)
|
||||
{
|
||||
body = *q;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return std::make_pair(body,data);
|
||||
}
|
||||
|
||||
wrapper_base* entry::wrapper() const
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace
|
||||
struct pyobject_unwrapper : unwrapper_base
|
||||
{
|
||||
pyobject_unwrapper();
|
||||
bool convertible(PyObject*) const;
|
||||
void* can_convert(PyObject*) const;
|
||||
};
|
||||
|
||||
pyobject_unwrapper static_unwrapper;
|
||||
@@ -23,13 +23,13 @@ namespace
|
||||
{
|
||||
}
|
||||
|
||||
bool pyobject_unwrapper::convertible(PyObject*) const
|
||||
void* pyobject_unwrapper::can_convert(PyObject*) const
|
||||
{
|
||||
return true;
|
||||
return non_null;
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_PYTHON_EXPORT unwrapper_base*
|
||||
unwrap_more_<PyObject*>::m_unwrapper = &static_unwrapper;
|
||||
BOOST_PYTHON_DECL std::pair<unwrapper_base*,void*>
|
||||
unwrap_more_<PyObject*>::m_unwrapper(&static_unwrapper,&static_unwrapper);
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
@@ -21,4 +21,11 @@ unwrapper_base::~unwrapper_base()
|
||||
registry::remove(*this);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
int arbitrary;
|
||||
}
|
||||
|
||||
void* const unwrapper_base::non_null = &arbitrary;
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
Reference in New Issue
Block a user