mirror of
https://github.com/boostorg/python.git
synced 2026-01-24 06:02:14 +00:00
Added the new arg class from
"nickm-at-sitius.com" (Nikolay Mladenov) which supplies the ability to wrap functions that can be called with ommitted arguments in the middle. [SVN r19441]
This commit is contained in:
@@ -23,11 +23,12 @@
|
||||
# include <boost/preprocessor/iteration/local.hpp>
|
||||
|
||||
# include <boost/python/detail/mpl_lambda.hpp>
|
||||
# include <boost/python/object_core.hpp>
|
||||
|
||||
# include <boost/mpl/bool.hpp>
|
||||
|
||||
# include <cstddef>
|
||||
|
||||
# include <algorithm>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
@@ -42,6 +43,16 @@ namespace detail
|
||||
{
|
||||
return keyword_range(elements, elements + nkeywords);
|
||||
}
|
||||
|
||||
keywords<nkeywords+1> operator,(const keywords<1> &k) const
|
||||
{
|
||||
python::detail::keywords<size+1> res;
|
||||
std::copy(elements, elements+size, res.elements);
|
||||
res.elements[size] = k.elements[0];
|
||||
return res;
|
||||
}
|
||||
|
||||
keywords<nkeywords+1> operator,(const char *name) const;
|
||||
|
||||
keyword elements[nkeywords];
|
||||
};
|
||||
@@ -97,6 +108,37 @@ namespace detail
|
||||
# endif
|
||||
}
|
||||
|
||||
struct arg : detail::keywords<1>
|
||||
{
|
||||
explicit arg(char const *name)
|
||||
{
|
||||
elements[0].name = name;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
arg& operator=(T const& value)
|
||||
{
|
||||
object z(value);
|
||||
elements[0].default_value = handle<>(python::borrowed(object(value).ptr()));
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator detail::keyword const&() const
|
||||
{
|
||||
return elements[0];
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <std::size_t nkeywords>
|
||||
inline keywords<nkeywords + 1>
|
||||
keywords<nkeywords>::operator,(const char *name) const
|
||||
{
|
||||
return this->operator,(arg(name));
|
||||
}
|
||||
}
|
||||
|
||||
# define BOOST_PYTHON_ASSIGN_NAME(z, n, _) result.elements[n].name = name##n;
|
||||
# define BOOST_PP_LOCAL_MACRO(n) \
|
||||
inline detail::keywords<n> args(BOOST_PP_ENUM_PARAMS_Z(1, n, char const* name)) \
|
||||
|
||||
@@ -19,6 +19,10 @@ namespace detail
|
||||
{
|
||||
struct keyword
|
||||
{
|
||||
keyword(char const* name_=0)
|
||||
: name(name_)
|
||||
{}
|
||||
|
||||
char const* name;
|
||||
handle<> default_value;
|
||||
};
|
||||
|
||||
@@ -51,6 +51,7 @@ struct BOOST_PYTHON_DECL function : PyObject
|
||||
object m_namespace;
|
||||
object m_doc;
|
||||
object m_arg_names;
|
||||
unsigned m_nkeyword_values;
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user