mirror of
https://github.com/boostorg/python.git
synced 2026-01-19 16:32:16 +00:00
factored out redundant code into base class
[SVN r15399]
This commit is contained in:
@@ -28,16 +28,28 @@
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// func_stubs_base is used as a base class for all function stubs.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// func_stubs_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 func_stubs_base
|
||||
{
|
||||
func_stubs_base(char const* doc_)
|
||||
: doc(doc_) {}
|
||||
|
||||
char const* doc_string() const
|
||||
{ return doc; }
|
||||
|
||||
char const* doc;
|
||||
};
|
||||
}
|
||||
|
||||
// func_stubs_with_call_policies is generated by the
|
||||
// func_stubs_with_default_call_policies operator[]
|
||||
// (see below). This class holds a user defined call policies
|
||||
// of the stubs.
|
||||
|
||||
template <class CallPoliciesT, class StubsT>
|
||||
struct func_stubs_with_call_policies
|
||||
: public detail::func_stubs_base
|
||||
@@ -45,18 +57,40 @@ struct func_stubs_with_call_policies
|
||||
typedef typename StubsT::nv_type nv_type;
|
||||
typedef typename StubsT::v_type v_type;
|
||||
|
||||
func_stubs_with_call_policies(CallPoliciesT const& policies_, char const* doc_)
|
||||
: policies(policies_), doc(doc_) {}
|
||||
|
||||
char const* doc_string() const
|
||||
{ return doc; }
|
||||
func_stubs_with_call_policies(CallPoliciesT const& policies_, char const* doc)
|
||||
: detail::func_stubs_base(doc), policies(policies_) {}
|
||||
|
||||
CallPoliciesT
|
||||
call_policies() const
|
||||
{ return policies; }
|
||||
|
||||
CallPoliciesT policies;
|
||||
char const* doc;
|
||||
};
|
||||
|
||||
// func_stubs_with_default_call_policies 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_with_call_policies however
|
||||
// through its operator[]
|
||||
|
||||
template <class DerivedT>
|
||||
struct func_stubs_with_default_call_policies
|
||||
: public detail::func_stubs_base {
|
||||
|
||||
func_stubs_with_default_call_policies(char const* doc)
|
||||
: detail::func_stubs_base(doc) {}
|
||||
|
||||
default_call_policies
|
||||
call_policies() const
|
||||
{ return default_call_policies(); }
|
||||
|
||||
template <class CallPoliciesT>
|
||||
::boost::python::func_stubs_with_call_policies<CallPoliciesT, DerivedT>
|
||||
operator[](CallPoliciesT const& policies) const
|
||||
{
|
||||
return func_stubs_with_call_policies<CallPoliciesT, DerivedT>
|
||||
(policies, doc);
|
||||
}
|
||||
};
|
||||
|
||||
}} // namespace boost::python
|
||||
@@ -149,7 +183,7 @@ struct func_stubs_with_call_policies
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#if defined(BOOST_MSVC)
|
||||
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
|
||||
|
||||
#define BOOST_PYTHON_GEN_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \
|
||||
BOOST_PYTHON_GEN_FUNCTION \
|
||||
@@ -157,31 +191,14 @@ struct func_stubs_with_call_policies
|
||||
BOOST_PYTHON_GEN_FUNCTION \
|
||||
(fname, BOOST_PP_CAT(fstubs_name, _V), n_args, n_dflts, ;) \
|
||||
struct fstubs_name \
|
||||
: public boost::python::detail::func_stubs_base { \
|
||||
\
|
||||
: public boost::python::func_stubs_with_default_call_policies<fstubs_name> \
|
||||
{ \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _NV) nv_type; \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _V) v_type; \
|
||||
typedef fstubs_name self_t; \
|
||||
\
|
||||
fstubs_name(char const* doc_ = 0) \
|
||||
: doc(doc_) {} \
|
||||
\
|
||||
char const* doc_string() const \
|
||||
{ return doc; } \
|
||||
\
|
||||
::boost::python::default_call_policies \
|
||||
call_policies() const \
|
||||
{ return ::boost::python::default_call_policies(); } \
|
||||
\
|
||||
template <class CallPoliciesT> \
|
||||
::boost::python::func_stubs_with_call_policies<CallPoliciesT, self_t> \
|
||||
operator[](CallPoliciesT const& policies) const \
|
||||
{ \
|
||||
return ::boost::python::func_stubs_with_call_policies<CallPoliciesT, self_t> \
|
||||
(policies, doc); \
|
||||
} \
|
||||
\
|
||||
char const* doc; \
|
||||
fstubs_name(char const* doc = 0) \
|
||||
: boost::python:: \
|
||||
func_stubs_with_default_call_policies<fstubs_name>(doc) {} \
|
||||
}; \
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -191,31 +208,14 @@ struct func_stubs_with_call_policies
|
||||
BOOST_PYTHON_GEN_MEM_FUNCTION \
|
||||
(fname, BOOST_PP_CAT(fstubs_name, _V), n_args, n_dflts, ;) \
|
||||
struct fstubs_name \
|
||||
: public boost::python::detail::func_stubs_base { \
|
||||
\
|
||||
: public boost::python::func_stubs_with_default_call_policies<fstubs_name> \
|
||||
{ \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _NV) nv_type; \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _V) v_type; \
|
||||
typedef fstubs_name self_t; \
|
||||
\
|
||||
fstubs_name(char const* doc_ = 0) \
|
||||
: doc(doc_) {} \
|
||||
\
|
||||
char const* doc_string() const \
|
||||
{ return doc; } \
|
||||
\
|
||||
::boost::python::default_call_policies \
|
||||
call_policies() const \
|
||||
{ return ::boost::python::default_call_policies(); } \
|
||||
\
|
||||
template <class CallPoliciesT> \
|
||||
::boost::python::func_stubs_with_call_policies<CallPoliciesT, self_t> \
|
||||
operator[](CallPoliciesT const& policies) const \
|
||||
{ \
|
||||
return ::boost::python::func_stubs_with_call_policies<CallPoliciesT, self_t> \
|
||||
(policies, doc); \
|
||||
} \
|
||||
\
|
||||
char const* doc; \
|
||||
fstubs_name(char const* doc = 0) \
|
||||
: boost::python:: \
|
||||
func_stubs_with_default_call_policies<fstubs_name>(doc) {} \
|
||||
}; \
|
||||
|
||||
#else
|
||||
@@ -225,31 +225,14 @@ struct func_stubs_with_call_policies
|
||||
BOOST_PYTHON_GEN_FUNCTION \
|
||||
(fname, BOOST_PP_CAT(fstubs_name, _NV), n_args, n_dflts, return) \
|
||||
struct fstubs_name \
|
||||
: public boost::python::detail::func_stubs_base { \
|
||||
\
|
||||
: public boost::python::func_stubs_with_default_call_policies<fstubs_name> \
|
||||
{ \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _NV) nv_type; \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _NV) v_type; \
|
||||
typedef fstubs_name self_t; \
|
||||
\
|
||||
fstubs_name(char const* doc_ = 0) \
|
||||
: doc(doc_) {} \
|
||||
\
|
||||
char const* doc_string() const \
|
||||
{ return doc; } \
|
||||
\
|
||||
::boost::python::default_call_policies \
|
||||
call_policies() const \
|
||||
{ return ::boost::python::default_call_policies(); } \
|
||||
\
|
||||
template <class CallPoliciesT> \
|
||||
::boost::python::func_stubs_with_call_policies<CallPoliciesT, self_t> \
|
||||
operator[](CallPoliciesT const& policies) const \
|
||||
{ \
|
||||
return ::boost::python::func_stubs_with_call_policies<CallPoliciesT, self_t> \
|
||||
(policies, doc); \
|
||||
} \
|
||||
\
|
||||
char const* doc; \
|
||||
fstubs_name(char const* doc = 0) \
|
||||
: boost::python:: \
|
||||
func_stubs_with_default_call_policies<fstubs_name>(doc) {} \
|
||||
}; \
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -257,31 +240,14 @@ struct func_stubs_with_call_policies
|
||||
BOOST_PYTHON_GEN_MEM_FUNCTION \
|
||||
(fname, BOOST_PP_CAT(fstubs_name, _NV), n_args, n_dflts, return) \
|
||||
struct fstubs_name \
|
||||
: public boost::python::detail::func_stubs_base { \
|
||||
\
|
||||
: public boost::python::func_stubs_with_default_call_policies<fstubs_name> \
|
||||
{ \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _NV) nv_type; \
|
||||
typedef BOOST_PP_CAT(fstubs_name, _NV) v_type; \
|
||||
typedef fstubs_name self_t; \
|
||||
\
|
||||
fstubs_name(char const* doc_ = 0) \
|
||||
: doc(doc_) {} \
|
||||
\
|
||||
char const* doc_string() const \
|
||||
{ return doc; } \
|
||||
\
|
||||
::boost::python::default_call_policies \
|
||||
call_policies() const \
|
||||
{ return ::boost::python::default_call_policies(); } \
|
||||
\
|
||||
template <class CallPoliciesT> \
|
||||
::boost::python::func_stubs_with_call_policies<CallPoliciesT, self_t> \
|
||||
operator[](CallPoliciesT const& policies) const \
|
||||
{ \
|
||||
return ::boost::python::func_stubs_with_call_policies<CallPoliciesT, self_t> \
|
||||
(policies, doc); \
|
||||
} \
|
||||
\
|
||||
char const* doc; \
|
||||
fstubs_name(char const* doc = 0) \
|
||||
: boost::python:: \
|
||||
func_stubs_with_default_call_policies<fstubs_name>(doc) {} \
|
||||
}; \
|
||||
|
||||
#endif // defined(BOOST_MSVC)
|
||||
@@ -350,10 +316,14 @@ struct func_stubs_with_call_policies
|
||||
// };
|
||||
//
|
||||
// struct foo_stubs
|
||||
// : public boost::python::detail::func_stubs_base {
|
||||
// : public boost::python::func_stubs_with_default_call_policies<foo_stubs>
|
||||
//
|
||||
// typedef foo_stubs_NV nv_type;
|
||||
// typedef foo_stubs_NV v_type;
|
||||
//
|
||||
// fstubs_name(char const* doc = 0)
|
||||
// : boost::python::
|
||||
// func_stubs_with_default_call_policies<foo_stubs>(doc) {}
|
||||
// };
|
||||
//
|
||||
// The typedefs nv_type and v_type are used to handle compilers that
|
||||
@@ -363,6 +333,9 @@ struct func_stubs_with_call_policies
|
||||
// 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_with_default_call_policies above for a description
|
||||
// of the foo_stubs' base class.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define BOOST_PYTHON_FUNCTION_OVERLOADS(generator_name, fname, min_args, max_args) \
|
||||
BOOST_PYTHON_GEN_FUNCTION_STUB( \
|
||||
|
||||
Reference in New Issue
Block a user