1 // Copyright David Abrahams 2002.
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 #ifndef KEYWORDS_DWA2002323_HPP
6 # define KEYWORDS_DWA2002323_HPP
8 # include <boost/python/detail/prefix.hpp>
10 # include <boost/python/args_fwd.hpp>
11 # include <boost/config.hpp>
12 # include <boost/python/detail/preprocessor.hpp>
13 # include <boost/python/detail/type_list.hpp>
15 # include <boost/type_traits/is_reference.hpp>
16 # include <boost/type_traits/remove_reference.hpp>
17 # include <boost/type_traits/remove_cv.hpp>
19 # include <boost/preprocessor/enum_params.hpp>
20 # include <boost/preprocessor/repeat.hpp>
21 # include <boost/preprocessor/facilities/intercept.hpp>
22 # include <boost/preprocessor/iteration/local.hpp>
24 # include <boost/python/detail/mpl_lambda.hpp>
25 # include <boost/python/object_core.hpp>
27 # include <boost/mpl/bool.hpp>
32 namespace boost { namespace python {
34 typedef detail::keywords<1> arg;
35 typedef arg arg_; // gcc 2.96 workaround
39 template <std::size_t nkeywords>
42 BOOST_STATIC_CONSTANT(std::size_t, size = nkeywords);
44 keyword_range range() const
46 return keyword_range(elements, elements + nkeywords);
49 keyword elements[nkeywords];
52 operator,(python::arg const &k) const;
54 keywords<nkeywords + 1>
55 operator,(char const *name) const;
58 template <std::size_t nkeywords>
59 struct keywords : keywords_base<nkeywords>
64 struct keywords<1> : keywords_base<1>
66 explicit keywords(char const *name)
68 elements[0].name = name;
72 python::arg& operator=(T const& value)
75 elements[0].default_value = handle<>(python::borrowed(object(value).ptr()));
79 operator detail::keyword const&() const
85 template <std::size_t nkeywords>
88 keywords_base<nkeywords>::operator,(python::arg const &k) const
90 keywords<nkeywords> const& l = *static_cast<keywords<nkeywords> const*>(this);
91 python::detail::keywords<nkeywords+1> res;
92 std::copy(l.elements, l.elements+nkeywords, res.elements);
93 res.elements[nkeywords] = k.elements[0];
97 template <std::size_t nkeywords>
99 keywords<nkeywords + 1>
100 keywords_base<nkeywords>::operator,(char const *name) const
102 return this->operator,(python::arg(name));
108 BOOST_STATIC_CONSTANT(bool, value = false);
111 template<std::size_t nkeywords>
112 struct is_keywords<keywords<nkeywords> >
114 BOOST_STATIC_CONSTANT(bool, value = true);
117 struct is_reference_to_keywords
119 BOOST_STATIC_CONSTANT(bool, is_ref = is_reference<T>::value);
120 typedef typename remove_reference<T>::type deref;
121 typedef typename remove_cv<deref>::type key_t;
122 BOOST_STATIC_CONSTANT(bool, is_key = is_keywords<key_t>::value);
123 BOOST_STATIC_CONSTANT(bool, value = (is_ref & is_key));
125 typedef mpl::bool_<value> type;
126 BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_keywords,(T))
130 inline detail::keywords<1> args(char const* name)
132 return detail::keywords<1>(name);
135 # define BOOST_PYTHON_ASSIGN_NAME(z, n, _) result.elements[n].name = name##n;
136 # define BOOST_PP_LOCAL_MACRO(n) \
137 inline detail::keywords<n> args(BOOST_PP_ENUM_PARAMS_Z(1, n, char const* name)) \
139 detail::keywords<n> result; \
140 BOOST_PP_REPEAT_1(n, BOOST_PYTHON_ASSIGN_NAME, _) \
143 # define BOOST_PP_LOCAL_LIMITS (2, BOOST_PYTHON_MAX_ARITY)
144 # include BOOST_PP_LOCAL_ITERATE()
146 }} // namespace boost::python
149 # endif // KEYWORDS_DWA2002323_HPP