1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/python/pure_virtual.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,124 @@
1.4 +// Copyright David Abrahams 2003.
1.5 +// Distributed under the Boost Software License, Version 1.0. (See
1.6 +// accompanying file LICENSE_1_0.txt or copy at
1.7 +// http://www.boost.org/LICENSE_1_0.txt)
1.8 +#ifndef PURE_VIRTUAL_DWA2003810_HPP
1.9 +# define PURE_VIRTUAL_DWA2003810_HPP
1.10 +
1.11 +# include <boost/python/def_visitor.hpp>
1.12 +# include <boost/python/default_call_policies.hpp>
1.13 +# include <boost/mpl/push_front.hpp>
1.14 +# include <boost/mpl/pop_front.hpp>
1.15 +
1.16 +# include <boost/python/detail/nullary_function_adaptor.hpp>
1.17 +
1.18 +namespace boost { namespace python {
1.19 +
1.20 +namespace detail
1.21 +{
1.22 + //
1.23 + // @group Helpers for pure_virtual_visitor. {
1.24 + //
1.25 +
1.26 + // Raises a Python RuntimeError reporting that a pure virtual
1.27 + // function was called.
1.28 + void BOOST_PYTHON_DECL pure_virtual_called();
1.29 +
1.30 + // Replace the two front elements of S with T1 and T2
1.31 + template <class S, class T1, class T2>
1.32 + struct replace_front2
1.33 + {
1.34 + // Metafunction forwarding seemed to confound vc6
1.35 + typedef typename mpl::push_front<
1.36 + typename mpl::push_front<
1.37 + typename mpl::pop_front<
1.38 + typename mpl::pop_front<
1.39 + S
1.40 + >::type
1.41 + >::type
1.42 + , T2
1.43 + >::type
1.44 + , T1
1.45 + >::type type;
1.46 + };
1.47 +
1.48 + // Given an MPL sequence representing a member function [object]
1.49 + // signature, returns a new MPL sequence whose return type is
1.50 + // replaced by void, and whose first argument is replaced by C&.
1.51 + template <class C, class S>
1.52 + typename replace_front2<S,void,C&>::type
1.53 + error_signature(S BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(C))
1.54 + {
1.55 + typedef typename replace_front2<S,void,C&>::type r;
1.56 + return r();
1.57 + }
1.58 +
1.59 + //
1.60 + // }
1.61 + //
1.62 +
1.63 + //
1.64 + // A def_visitor which defines a method as usual, then adds a
1.65 + // corresponding function which raises a "pure virtual called"
1.66 + // exception unless it's been overridden.
1.67 + //
1.68 + template <class PointerToMemberFunction>
1.69 + struct pure_virtual_visitor
1.70 + : def_visitor<pure_virtual_visitor<PointerToMemberFunction> >
1.71 + {
1.72 + pure_virtual_visitor(PointerToMemberFunction pmf)
1.73 + : m_pmf(pmf)
1.74 + {}
1.75 +
1.76 + private:
1.77 + friend class python::def_visitor_access;
1.78 +
1.79 + template <class C_, class Options>
1.80 + void visit(C_& c, char const* name, Options& options) const
1.81 + {
1.82 + // This should probably be a nicer error message
1.83 + BOOST_STATIC_ASSERT(!Options::has_default_implementation);
1.84 +
1.85 + // Add the virtual function dispatcher
1.86 + c.def(
1.87 + name
1.88 + , m_pmf
1.89 + , options.doc()
1.90 + , options.keywords()
1.91 + , options.policies()
1.92 + );
1.93 +
1.94 + typedef BOOST_DEDUCED_TYPENAME C_::metadata::held_type held_type;
1.95 +
1.96 + // Add the default implementation which raises the exception
1.97 + c.def(
1.98 + name
1.99 + , make_function(
1.100 + detail::nullary_function_adaptor<void(*)()>(pure_virtual_called)
1.101 + , default_call_policies()
1.102 + , detail::error_signature<held_type>(detail::get_signature(m_pmf))
1.103 + )
1.104 + );
1.105 + }
1.106 +
1.107 + private: // data members
1.108 + PointerToMemberFunction m_pmf;
1.109 + };
1.110 +}
1.111 +
1.112 +//
1.113 +// Passed a pointer to member function, generates a def_visitor which
1.114 +// creates a method that only dispatches to Python if the function has
1.115 +// been overridden, either in C++ or in Python, raising a "pure
1.116 +// virtual called" exception otherwise.
1.117 +//
1.118 +template <class PointerToMemberFunction>
1.119 +detail::pure_virtual_visitor<PointerToMemberFunction>
1.120 +pure_virtual(PointerToMemberFunction pmf)
1.121 +{
1.122 + return detail::pure_virtual_visitor<PointerToMemberFunction>(pmf);
1.123 +}
1.124 +
1.125 +}} // namespace boost::python
1.126 +
1.127 +#endif // PURE_VIRTUAL_DWA2003810_HPP