sl@0: // Copyright David Abrahams 2003. sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: #ifndef PURE_VIRTUAL_DWA2003810_HPP sl@0: # define PURE_VIRTUAL_DWA2003810_HPP sl@0: sl@0: # include sl@0: # include sl@0: # include sl@0: # include sl@0: sl@0: # include sl@0: sl@0: namespace boost { namespace python { sl@0: sl@0: namespace detail sl@0: { sl@0: // sl@0: // @group Helpers for pure_virtual_visitor. { sl@0: // sl@0: sl@0: // Raises a Python RuntimeError reporting that a pure virtual sl@0: // function was called. sl@0: void BOOST_PYTHON_DECL pure_virtual_called(); sl@0: sl@0: // Replace the two front elements of S with T1 and T2 sl@0: template sl@0: struct replace_front2 sl@0: { sl@0: // Metafunction forwarding seemed to confound vc6 sl@0: typedef typename mpl::push_front< sl@0: typename mpl::push_front< sl@0: typename mpl::pop_front< sl@0: typename mpl::pop_front< sl@0: S sl@0: >::type sl@0: >::type sl@0: , T2 sl@0: >::type sl@0: , T1 sl@0: >::type type; sl@0: }; sl@0: sl@0: // Given an MPL sequence representing a member function [object] sl@0: // signature, returns a new MPL sequence whose return type is sl@0: // replaced by void, and whose first argument is replaced by C&. sl@0: template sl@0: typename replace_front2::type sl@0: error_signature(S BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(C)) sl@0: { sl@0: typedef typename replace_front2::type r; sl@0: return r(); sl@0: } sl@0: sl@0: // sl@0: // } sl@0: // sl@0: sl@0: // sl@0: // A def_visitor which defines a method as usual, then adds a sl@0: // corresponding function which raises a "pure virtual called" sl@0: // exception unless it's been overridden. sl@0: // sl@0: template sl@0: struct pure_virtual_visitor sl@0: : def_visitor > sl@0: { sl@0: pure_virtual_visitor(PointerToMemberFunction pmf) sl@0: : m_pmf(pmf) sl@0: {} sl@0: sl@0: private: sl@0: friend class python::def_visitor_access; sl@0: sl@0: template sl@0: void visit(C_& c, char const* name, Options& options) const sl@0: { sl@0: // This should probably be a nicer error message sl@0: BOOST_STATIC_ASSERT(!Options::has_default_implementation); sl@0: sl@0: // Add the virtual function dispatcher sl@0: c.def( sl@0: name sl@0: , m_pmf sl@0: , options.doc() sl@0: , options.keywords() sl@0: , options.policies() sl@0: ); sl@0: sl@0: typedef BOOST_DEDUCED_TYPENAME C_::metadata::held_type held_type; sl@0: sl@0: // Add the default implementation which raises the exception sl@0: c.def( sl@0: name sl@0: , make_function( sl@0: detail::nullary_function_adaptor(pure_virtual_called) sl@0: , default_call_policies() sl@0: , detail::error_signature(detail::get_signature(m_pmf)) sl@0: ) sl@0: ); sl@0: } sl@0: sl@0: private: // data members sl@0: PointerToMemberFunction m_pmf; sl@0: }; sl@0: } sl@0: sl@0: // sl@0: // Passed a pointer to member function, generates a def_visitor which sl@0: // creates a method that only dispatches to Python if the function has sl@0: // been overridden, either in C++ or in Python, raising a "pure sl@0: // virtual called" exception otherwise. sl@0: // sl@0: template sl@0: detail::pure_virtual_visitor sl@0: pure_virtual(PointerToMemberFunction pmf) sl@0: { sl@0: return detail::pure_virtual_visitor(pmf); sl@0: } sl@0: sl@0: }} // namespace boost::python sl@0: sl@0: #endif // PURE_VIRTUAL_DWA2003810_HPP