mirror of
https://github.com/boostorg/python.git
synced 2026-01-19 16:32:16 +00:00
Finalizing....
[SVN r15426]
This commit is contained in:
@@ -209,7 +209,8 @@ class class_ : public objects::class_base
|
||||
self& def(char const* name, Arg1T arg1, Arg2T const& arg2, Arg3T const& arg3)
|
||||
{
|
||||
// The arguments are definitely:
|
||||
// def(name, function, policy, doc_string) // TODO: exchange policy, doc_string position
|
||||
// def(name, function, policy, doc_string)
|
||||
// def(name, function, doc_string, policy)
|
||||
|
||||
dispatch_def(&arg2, name, arg1, arg2, arg3);
|
||||
return *this;
|
||||
@@ -334,25 +335,9 @@ class class_ : public objects::class_base
|
||||
|
||||
inline void register_() const;
|
||||
|
||||
template <class Fn, class CallPolicyOrDoc>
|
||||
void dispatch_def(
|
||||
void const*,
|
||||
char const* name,
|
||||
Fn fn,
|
||||
CallPolicyOrDoc const& policy_or_doc,
|
||||
char const* doc = 0)
|
||||
{
|
||||
typedef detail::def_helper<CallPolicyOrDoc> helper;
|
||||
|
||||
this->def_impl(
|
||||
name, fn, helper::get_policy(policy_or_doc),
|
||||
helper::get_doc(policy_or_doc, doc), &fn);
|
||||
|
||||
}
|
||||
|
||||
template <class StubsT, class SigT>
|
||||
void dispatch_def(
|
||||
detail::func_stubs_base const*,
|
||||
detail::overloads_base const*,
|
||||
char const* name,
|
||||
SigT sig,
|
||||
StubsT const& stubs)
|
||||
@@ -362,6 +347,35 @@ class class_ : public objects::class_base
|
||||
detail::define_with_defaults(
|
||||
name, stubs, *this, detail::get_signature(sig));
|
||||
}
|
||||
|
||||
template <class Fn, class CallPolicyOrDoc>
|
||||
void dispatch_def(
|
||||
void const*,
|
||||
char const* name,
|
||||
Fn fn,
|
||||
CallPolicyOrDoc const& policy_or_doc)
|
||||
{
|
||||
typedef detail::def_helper<CallPolicyOrDoc> helper;
|
||||
this->def_impl(
|
||||
name, fn, helper::get_policy(policy_or_doc),
|
||||
helper::get_doc(policy_or_doc, 0), &fn);
|
||||
|
||||
}
|
||||
|
||||
template <class Fn, class CallPolicyOrDoc1, class CallPolicyOrDoc2>
|
||||
void dispatch_def(
|
||||
void const*,
|
||||
char const* name,
|
||||
Fn fn,
|
||||
CallPolicyOrDoc1 const& policy_or_doc1,
|
||||
CallPolicyOrDoc2 const& policy_or_doc2)
|
||||
{
|
||||
typedef detail::def_helper<CallPolicyOrDoc1> helper;
|
||||
|
||||
this->def_impl(
|
||||
name, fn, helper::get_policy(policy_or_doc1, policy_or_doc2),
|
||||
helper::get_doc(policy_or_doc1, policy_or_doc2), &fn);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -19,25 +19,40 @@ namespace detail
|
||||
{
|
||||
void BOOST_PYTHON_DECL scope_setattr_doc(char const* name, object const& obj, char const* doc);
|
||||
|
||||
template <class Fn, class CallPolicyOrDoc>
|
||||
void
|
||||
dispatch_def(
|
||||
void const*,
|
||||
char const* name,
|
||||
Fn fn,
|
||||
CallPolicyOrDoc const& policy_or_doc,
|
||||
char const* doc = 0)
|
||||
{
|
||||
typedef detail::def_helper<CallPolicyOrDoc> helper;
|
||||
template <class Fn, class CallPolicyOrDoc>
|
||||
void
|
||||
dispatch_def(
|
||||
void const*,
|
||||
char const* name,
|
||||
Fn fn,
|
||||
CallPolicyOrDoc const& policy_or_doc)
|
||||
{
|
||||
typedef detail::def_helper<CallPolicyOrDoc> helper;
|
||||
|
||||
detail::scope_setattr_doc(
|
||||
name, boost::python::make_function(fn, helper::get_policy(policy_or_doc)),
|
||||
helper::get_doc(policy_or_doc, doc));
|
||||
}
|
||||
detail::scope_setattr_doc(
|
||||
name, boost::python::make_function(fn, helper::get_policy(policy_or_doc)),
|
||||
helper::get_doc(policy_or_doc, 0));
|
||||
}
|
||||
|
||||
template <class Fn, class CallPolicyOrDoc1, class CallPolicyOrDoc2>
|
||||
void dispatch_def(
|
||||
void const*,
|
||||
char const* name,
|
||||
Fn fn,
|
||||
CallPolicyOrDoc1 const& policy_or_doc1,
|
||||
CallPolicyOrDoc2 const& policy_or_doc2)
|
||||
{
|
||||
typedef detail::def_helper<CallPolicyOrDoc1> helper;
|
||||
|
||||
detail::scope_setattr_doc(
|
||||
name, boost::python::make_function(
|
||||
fn, helper::get_policy(policy_or_doc1, policy_or_doc2)),
|
||||
helper::get_doc(policy_or_doc1, policy_or_doc2));
|
||||
}
|
||||
|
||||
template <class StubsT, class SigT>
|
||||
void dispatch_def(
|
||||
detail::func_stubs_base const*,
|
||||
detail::overloads_base const*,
|
||||
char const* name,
|
||||
SigT sig,
|
||||
StubsT const& stubs)
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
# include <boost/type_traits/same_traits.hpp>
|
||||
# include <boost/python/detail/string_literal.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
//
|
||||
// def_helper<T> --
|
||||
@@ -32,19 +32,35 @@ template <bool is_string = false>
|
||||
struct def_helper_impl
|
||||
{
|
||||
template <class P>
|
||||
static P const& get_policy(P const& x) { return x; }
|
||||
|
||||
static P const&
|
||||
get_policy(P const& x) { return x; }
|
||||
|
||||
template <class P1, class P2>
|
||||
static P1 const&
|
||||
get_policy(P1 const& x, P2 const&) { return x; } // select left
|
||||
|
||||
template <class P>
|
||||
static char const* get_doc(P const&, char const* doc) { return doc; }
|
||||
static char const*
|
||||
get_doc(P const&, char const* doc) { return doc; } // select right
|
||||
};
|
||||
|
||||
template <>
|
||||
struct def_helper_impl<true>
|
||||
{
|
||||
static python::default_call_policies get_policy(char const*) { return default_call_policies(); }
|
||||
static char const* get_doc(char const* doc, char const*) { return doc; }
|
||||
static python::default_call_policies
|
||||
get_policy(char const*)
|
||||
{ return default_call_policies(); }
|
||||
|
||||
template <class P1, class P2>
|
||||
static P2 const&
|
||||
get_policy(P1 const&, P2 const& y) { return y; } // select right
|
||||
|
||||
template <class P>
|
||||
static char const*
|
||||
get_doc(char const* doc, P const&) // select left
|
||||
{ return doc; }
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
struct def_helper
|
||||
: def_helper_impl<
|
||||
|
||||
@@ -200,13 +200,13 @@ struct define_stub_function {};
|
||||
SigT sig)
|
||||
{
|
||||
typedef typename mpl::front<SigT>::type return_type;
|
||||
typedef typename StubsT::v_type v_type;
|
||||
typedef typename StubsT::nv_type nv_type;
|
||||
typedef typename StubsT::void_return_type void_return_type;
|
||||
typedef typename StubsT::non_void_return_type non_void_return_type;
|
||||
|
||||
typedef typename mpl::if_c<
|
||||
boost::is_same<void, return_type>::value
|
||||
, v_type
|
||||
, nv_type
|
||||
, void_return_type
|
||||
, non_void_return_type
|
||||
>::type stubs_type;
|
||||
|
||||
BOOST_STATIC_ASSERT(
|
||||
|
||||
@@ -28,14 +28,14 @@
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
// func_stubs_base is used as a base class for all function
|
||||
// overloads_base is used as a base class for all function
|
||||
// stubs. This class holds the doc_string of the stubs.
|
||||
|
||||
namespace detail
|
||||
{
|
||||
struct func_stubs_base
|
||||
struct overloads_base
|
||||
{
|
||||
func_stubs_base(char const* doc_)
|
||||
overloads_base(char const* doc_)
|
||||
: doc(doc_) {}
|
||||
|
||||
char const* doc_string() const
|
||||
@@ -45,18 +45,18 @@ namespace boost { namespace python {
|
||||
};
|
||||
}
|
||||
|
||||
// func_stubs_proxy is generated by the func_stubs_common operator[] (see
|
||||
// overloads_proxy is generated by the overloads_common operator[] (see
|
||||
// below). This class holds a user defined call policies of the stubs.
|
||||
|
||||
template <class CallPoliciesT, class StubsT>
|
||||
struct func_stubs_proxy
|
||||
: public detail::func_stubs_base
|
||||
template <class CallPoliciesT, class OverloadsT>
|
||||
struct overloads_proxy
|
||||
: public detail::overloads_base
|
||||
{
|
||||
typedef typename StubsT::nv_type nv_type;
|
||||
typedef typename StubsT::v_type v_type;
|
||||
typedef typename OverloadsT::non_void_return_type non_void_return_type;
|
||||
typedef typename OverloadsT::void_return_type void_return_type;
|
||||
|
||||
func_stubs_proxy(CallPoliciesT const& policies_, char const* doc)
|
||||
: detail::func_stubs_base(doc), policies(policies_) {}
|
||||
overloads_proxy(CallPoliciesT const& policies_, char const* doc)
|
||||
: detail::overloads_base(doc), policies(policies_) {}
|
||||
|
||||
CallPoliciesT
|
||||
call_policies() const
|
||||
@@ -65,26 +65,26 @@ struct func_stubs_proxy
|
||||
CallPoliciesT policies;
|
||||
};
|
||||
|
||||
// func_stubs_common is our default function stubs base class. This class
|
||||
// overloads_common is our default function stubs base class. This class
|
||||
// returns the default_call_policies in its call_policies() member function.
|
||||
// It can generate a func_stubs_proxy however through its operator[]
|
||||
// It can generate a overloads_proxy however through its operator[]
|
||||
|
||||
template <class DerivedT>
|
||||
struct func_stubs_common
|
||||
: public detail::func_stubs_base {
|
||||
struct overloads_common
|
||||
: public detail::overloads_base {
|
||||
|
||||
func_stubs_common(char const* doc)
|
||||
: detail::func_stubs_base(doc) {}
|
||||
overloads_common(char const* doc)
|
||||
: detail::overloads_base(doc) {}
|
||||
|
||||
default_call_policies
|
||||
call_policies() const
|
||||
{ return default_call_policies(); }
|
||||
|
||||
template <class CallPoliciesT>
|
||||
::boost::python::func_stubs_proxy<CallPoliciesT, DerivedT>
|
||||
::boost::python::overloads_proxy<CallPoliciesT, DerivedT>
|
||||
operator[](CallPoliciesT const& policies) const
|
||||
{
|
||||
return func_stubs_proxy<CallPoliciesT, DerivedT>
|
||||
return overloads_proxy<CallPoliciesT, DerivedT>
|
||||
(policies, doc);
|
||||
}
|
||||
};
|
||||
@@ -179,7 +179,7 @@ struct func_stubs_common
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
|
||||
#if defined(BOOST_NO_VOID_RETURNS)
|
||||
|
||||
#define BOOST_PYTHON_GEN_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \
|
||||
BOOST_PYTHON_GEN_FUNCTION \
|
||||
@@ -187,14 +187,14 @@ struct func_stubs_common
|
||||
BOOST_PYTHON_GEN_FUNCTION \
|
||||
(fname, BOOST_PP_CAT(fstubs_name, _V), n_args, n_dflts, ;) \
|
||||
struct fstubs_name \
|
||||
: public boost::python::func_stubs_common<fstubs_name> \
|
||||
: public boost::python::overloads_common<fstubs_name> \
|
||||
{ \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _NV) nv_type; \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _V) v_type; \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _NV) non_void_return_type; \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _V) void_return_type; \
|
||||
\
|
||||
fstubs_name(char const* doc = 0) \
|
||||
: boost::python:: \
|
||||
func_stubs_common<fstubs_name>(doc) {} \
|
||||
overloads_common<fstubs_name>(doc) {} \
|
||||
}; \
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -204,14 +204,14 @@ struct func_stubs_common
|
||||
BOOST_PYTHON_GEN_MEM_FUNCTION \
|
||||
(fname, BOOST_PP_CAT(fstubs_name, _V), n_args, n_dflts, ;) \
|
||||
struct fstubs_name \
|
||||
: public boost::python::func_stubs_common<fstubs_name> \
|
||||
: public boost::python::overloads_common<fstubs_name> \
|
||||
{ \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _NV) nv_type; \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _V) v_type; \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _NV) non_void_return_type; \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _V) void_return_type; \
|
||||
\
|
||||
fstubs_name(char const* doc = 0) \
|
||||
: boost::python:: \
|
||||
func_stubs_common<fstubs_name>(doc) {} \
|
||||
overloads_common<fstubs_name>(doc) {} \
|
||||
}; \
|
||||
|
||||
#else
|
||||
@@ -221,14 +221,14 @@ struct func_stubs_common
|
||||
BOOST_PYTHON_GEN_FUNCTION \
|
||||
(fname, BOOST_PP_CAT(fstubs_name, _NV), n_args, n_dflts, return) \
|
||||
struct fstubs_name \
|
||||
: public boost::python::func_stubs_common<fstubs_name> \
|
||||
: public boost::python::overloads_common<fstubs_name> \
|
||||
{ \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _NV) nv_type; \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _NV) v_type; \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _NV) non_void_return_type; \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _NV) void_return_type; \
|
||||
\
|
||||
fstubs_name(char const* doc = 0) \
|
||||
: boost::python:: \
|
||||
func_stubs_common<fstubs_name>(doc) {} \
|
||||
overloads_common<fstubs_name>(doc) {} \
|
||||
}; \
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -236,14 +236,14 @@ struct func_stubs_common
|
||||
BOOST_PYTHON_GEN_MEM_FUNCTION \
|
||||
(fname, BOOST_PP_CAT(fstubs_name, _NV), n_args, n_dflts, return) \
|
||||
struct fstubs_name \
|
||||
: public boost::python::func_stubs_common<fstubs_name> \
|
||||
: public boost::python::overloads_common<fstubs_name> \
|
||||
{ \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _NV) nv_type; \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _NV) v_type; \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _NV) non_void_return_type; \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _NV) void_return_type; \
|
||||
\
|
||||
fstubs_name(char const* doc = 0) \
|
||||
: boost::python:: \
|
||||
func_stubs_common<fstubs_name>(doc) {} \
|
||||
overloads_common<fstubs_name>(doc) {} \
|
||||
}; \
|
||||
|
||||
#endif // defined(BOOST_MSVC)
|
||||
@@ -312,24 +312,24 @@ struct func_stubs_common
|
||||
// };
|
||||
//
|
||||
// struct foo_stubs
|
||||
// : public boost::python::func_stubs_common<foo_stubs>
|
||||
// : public boost::python::overloads_common<foo_stubs>
|
||||
//
|
||||
// typedef foo_stubs_NV nv_type;
|
||||
// typedef foo_stubs_NV v_type;
|
||||
// typedef foo_stubs_NV non_void_return_type;
|
||||
// typedef foo_stubs_NV void_return_type;
|
||||
//
|
||||
// fstubs_name(char const* doc = 0)
|
||||
// : boost::python::
|
||||
// func_stubs_common<foo_stubs>(doc) {}
|
||||
// overloads_common<foo_stubs>(doc) {}
|
||||
// };
|
||||
//
|
||||
// The typedefs nv_type and v_type are used to handle compilers that
|
||||
// do not support void returns. The example above typedefs nv_type
|
||||
// and v_type to foo_stubs_NV. On compilers that do not support
|
||||
// The typedefs non_void_return_type and void_return_type are used to handle compilers that
|
||||
// do not support void returns. The example above typedefs non_void_return_type
|
||||
// and void_return_type to foo_stubs_NV. On compilers that do not support
|
||||
// void returns, there are two versions: foo_stubs_NV and foo_stubs_V.
|
||||
// The "V" version is almost identical to the "NV" version except
|
||||
// for the return type (void) and the lack of the return keyword.
|
||||
//
|
||||
// See the func_stubs_common above for a description of the foo_stubs'
|
||||
// See the overloads_common above for a description of the foo_stubs'
|
||||
// base class.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -85,7 +85,7 @@ class module : public detail::module_base
|
||||
SigT sig,
|
||||
StubsT const& stubs,
|
||||
char const* doc,
|
||||
detail::func_stubs_base const*)
|
||||
detail::overloads_base const*)
|
||||
{
|
||||
// convert sig to a type_list (see detail::get_signature in signature.hpp)
|
||||
// before calling detail::define_with_defaults.
|
||||
|
||||
Reference in New Issue
Block a user