os/ossrv/ossrv_pub/boost_apis/boost/python/def.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/python/def.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,114 @@
     1.4 +// Copyright David Abrahams 2002.
     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 DEF_DWA200292_HPP
     1.9 +# define DEF_DWA200292_HPP
    1.10 +
    1.11 +# include <boost/python/detail/prefix.hpp>
    1.12 +
    1.13 +# include <boost/python/object_fwd.hpp>
    1.14 +# include <boost/python/make_function.hpp>
    1.15 +# include <boost/python/detail/def_helper.hpp>
    1.16 +# include <boost/python/detail/overloads_fwd.hpp>
    1.17 +# include <boost/python/scope.hpp>
    1.18 +# include <boost/python/signature.hpp>
    1.19 +# include <boost/python/detail/scope.hpp>
    1.20 +
    1.21 +namespace boost { namespace python {
    1.22 +
    1.23 +namespace detail
    1.24 +{
    1.25 +  namespace error
    1.26 +  {
    1.27 +    // Compile-time error messages
    1.28 +    template <bool> struct multiple_functions_passed_to_def;
    1.29 +    template <> struct multiple_functions_passed_to_def<false> { typedef char type; };
    1.30 +  }
    1.31 +  
    1.32 +  //
    1.33 +  // def_from_helper --
    1.34 +  //
    1.35 +  // Use a def_helper to define a regular wrapped function in the current scope.
    1.36 +  template <class F, class Helper>
    1.37 +  void def_from_helper(
    1.38 +      char const* name, F const& fn, Helper const& helper)
    1.39 +  {
    1.40 +      // Must not try to use default implementations except with method definitions.
    1.41 +      typedef typename error::multiple_functions_passed_to_def<
    1.42 +          Helper::has_default_implementation
    1.43 +          >::type assertion;
    1.44 +      
    1.45 +      detail::scope_setattr_doc(
    1.46 +          name, boost::python::make_function(
    1.47 +              fn
    1.48 +              , helper.policies()
    1.49 +              , helper.keywords())
    1.50 +          , helper.doc()
    1.51 +          );
    1.52 +  }
    1.53 +
    1.54 +  //
    1.55 +  // These two overloads discriminate between def() as applied to
    1.56 +  // regular functions and def() as applied to the result of
    1.57 +  // BOOST_PYTHON_FUNCTION_OVERLOADS(). The final argument is used to
    1.58 +  // discriminate.
    1.59 +  //
    1.60 +  template <class Fn, class A1>
    1.61 +  void
    1.62 +  def_maybe_overloads(
    1.63 +      char const* name
    1.64 +      , Fn fn
    1.65 +      , A1 const& a1
    1.66 +      , ...)
    1.67 +  {
    1.68 +      detail::def_from_helper(name, fn, def_helper<A1>(a1));
    1.69 +  }
    1.70 +
    1.71 +  template <class StubsT, class SigT>
    1.72 +  void def_maybe_overloads(
    1.73 +      char const* name
    1.74 +      , SigT sig
    1.75 +      , StubsT const& stubs
    1.76 +      , detail::overloads_base const*)
    1.77 +  {
    1.78 +      scope current;
    1.79 +      
    1.80 +      detail::define_with_defaults(
    1.81 +          name, stubs, current, detail::get_signature(sig));
    1.82 +  }
    1.83 +
    1.84 +  template <class T>
    1.85 +  object make_function1(T fn, ...) { return make_function(fn); }
    1.86 +
    1.87 +  inline
    1.88 +  object make_function1(object const& x, object const*) { return x; }
    1.89 +}
    1.90 +
    1.91 +template <class Fn>
    1.92 +void def(char const* name, Fn fn)
    1.93 +{
    1.94 +    detail::scope_setattr_doc(name, detail::make_function1(fn, &fn), 0);
    1.95 +}
    1.96 +
    1.97 +template <class Arg1T, class Arg2T>
    1.98 +void def(char const* name, Arg1T arg1, Arg2T const& arg2)
    1.99 +{
   1.100 +    detail::def_maybe_overloads(name, arg1, arg2, &arg2);
   1.101 +}
   1.102 +
   1.103 +template <class F, class A1, class A2>
   1.104 +void def(char const* name, F f, A1 const& a1, A2 const& a2)
   1.105 +{
   1.106 +    detail::def_from_helper(name, f, detail::def_helper<A1,A2>(a1,a2));
   1.107 +}
   1.108 +
   1.109 +template <class F, class A1, class A2, class A3>
   1.110 +void def(char const* name, F f, A1 const& a1, A2 const& a2, A3 const& a3)
   1.111 +{
   1.112 +    detail::def_from_helper(name, f, detail::def_helper<A1,A2,A3>(a1,a2,a3));
   1.113 +}
   1.114 +
   1.115 +}} // namespace boost::python
   1.116 +
   1.117 +#endif // DEF_DWA200292_HPP