File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,35 +39,6 @@ namespace registry
3939 {
4040 }
4141
42- namespace // <unnamed>
43- {
44- // A UnaryFunction type which deletes its argument
45- struct delete_item
46- {
47- template <class T >
48- void operator ()(T* x) const
49- {
50- delete x;
51- }
52- };
53-
54- // A UnaryFunction type which returns true iff its argument is a
55- // unwrapper which can convert the given Python object.
56- struct convertible
57- {
58- convertible (PyObject* p)
59- : m_p(p)
60- {}
61-
62- bool operator ()(unwrapper_base* converter) const
63- {
64- return converter->convertible (m_p);
65- }
66-
67- PyObject* m_p;
68- };
69- }
70-
7142 entry::~entry ()
7243 {
7344 if (m_wrapper != 0 )
@@ -79,12 +50,25 @@ namespace registry
7950 }
8051 }
8152
82- unwrapper_base* entry::unwrapper (PyObject* p) const
53+ std::pair<unwrapper_base*,void *>
54+ entry::unwrapper (PyObject* p) const
8355 {
84- unwrappers::const_iterator q =
85- std::find_if (m_unwrappers. begin (), m_unwrappers. end (), convertible (p)) ;
56+ unwrapper_base* body = 0 ;
57+ void * data = 0 ;
8658
87- return q == m_unwrappers.end () ? 0 : *q;
59+ for (unwrappers::const_iterator q = m_unwrappers.begin (),
60+ finish = m_unwrappers.end ();
61+ q != finish;
62+ ++q)
63+ {
64+ data = (*q)->can_convert (p);
65+ if (data != 0 )
66+ {
67+ body = *q;
68+ break ;
69+ }
70+ }
71+ return std::make_pair (body,data);
8872 }
8973
9074 wrapper_base* entry::wrapper () const
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ namespace
1313 struct pyobject_unwrapper : unwrapper_base
1414 {
1515 pyobject_unwrapper ();
16- bool convertible (PyObject*) const ;
16+ void * can_convert (PyObject*) const ;
1717 };
1818
1919 pyobject_unwrapper static_unwrapper;
@@ -23,13 +23,13 @@ namespace
2323 {
2424 }
2525
26- bool pyobject_unwrapper::convertible (PyObject*) const
26+ void * pyobject_unwrapper::can_convert (PyObject*) const
2727 {
28- return true ;
28+ return non_null ;
2929 }
3030}
3131
32- BOOST_PYTHON_EXPORT unwrapper_base*
33- unwrap_more_<PyObject*>::m_unwrapper = &static_unwrapper;
32+ BOOST_PYTHON_DECL std::pair< unwrapper_base*, void *>
33+ unwrap_more_<PyObject*>::m_unwrapper( &static_unwrapper,&static_unwrapper) ;
3434
3535}}} // namespace boost::python::converter
Original file line number Diff line number Diff line change @@ -21,4 +21,11 @@ unwrapper_base::~unwrapper_base()
2121 registry::remove (*this );
2222}
2323
24+ namespace
25+ {
26+ int arbitrary;
27+ }
28+
29+ void * const unwrapper_base::non_null = &arbitrary;
30+
2431}}} // namespace boost::python::converter
You can’t perform that action at this time.
0 commit comments