sl@0: // Copyright David Abrahams 2002. sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: #ifndef KEYWORDS_DWA2002323_HPP sl@0: # define KEYWORDS_DWA2002323_HPP sl@0: sl@0: # include sl@0: sl@0: # include sl@0: # include sl@0: # include sl@0: # include sl@0: sl@0: # include sl@0: # include sl@0: # include sl@0: sl@0: # include sl@0: # include sl@0: # include sl@0: # include sl@0: sl@0: # include sl@0: # include sl@0: sl@0: # include sl@0: sl@0: # include sl@0: # include sl@0: sl@0: namespace boost { namespace python { sl@0: sl@0: typedef detail::keywords<1> arg; sl@0: typedef arg arg_; // gcc 2.96 workaround sl@0: sl@0: namespace detail sl@0: { sl@0: template sl@0: struct keywords_base sl@0: { sl@0: BOOST_STATIC_CONSTANT(std::size_t, size = nkeywords); sl@0: sl@0: keyword_range range() const sl@0: { sl@0: return keyword_range(elements, elements + nkeywords); sl@0: } sl@0: sl@0: keyword elements[nkeywords]; sl@0: sl@0: keywords sl@0: operator,(python::arg const &k) const; sl@0: sl@0: keywords sl@0: operator,(char const *name) const; sl@0: }; sl@0: sl@0: template sl@0: struct keywords : keywords_base sl@0: { sl@0: }; sl@0: sl@0: template <> sl@0: struct keywords<1> : keywords_base<1> sl@0: { sl@0: explicit keywords(char const *name) sl@0: { sl@0: elements[0].name = name; sl@0: } sl@0: sl@0: template sl@0: python::arg& operator=(T const& value) sl@0: { sl@0: object z(value); sl@0: elements[0].default_value = handle<>(python::borrowed(object(value).ptr())); sl@0: return *this; sl@0: } sl@0: sl@0: operator detail::keyword const&() const sl@0: { sl@0: return elements[0]; sl@0: } sl@0: }; sl@0: sl@0: template sl@0: inline sl@0: keywords sl@0: keywords_base::operator,(python::arg const &k) const sl@0: { sl@0: keywords const& l = *static_cast const*>(this); sl@0: python::detail::keywords res; sl@0: std::copy(l.elements, l.elements+nkeywords, res.elements); sl@0: res.elements[nkeywords] = k.elements[0]; sl@0: return res; sl@0: } sl@0: sl@0: template sl@0: inline sl@0: keywords sl@0: keywords_base::operator,(char const *name) const sl@0: { sl@0: return this->operator,(python::arg(name)); sl@0: } sl@0: sl@0: # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION sl@0: template sl@0: struct is_keywords sl@0: { sl@0: BOOST_STATIC_CONSTANT(bool, value = false); sl@0: }; sl@0: sl@0: template sl@0: struct is_keywords > sl@0: { sl@0: BOOST_STATIC_CONSTANT(bool, value = true); sl@0: }; sl@0: template sl@0: struct is_reference_to_keywords sl@0: { sl@0: BOOST_STATIC_CONSTANT(bool, is_ref = is_reference::value); sl@0: typedef typename remove_reference::type deref; sl@0: typedef typename remove_cv::type key_t; sl@0: BOOST_STATIC_CONSTANT(bool, is_key = is_keywords::value); sl@0: BOOST_STATIC_CONSTANT(bool, value = (is_ref & is_key)); sl@0: sl@0: typedef mpl::bool_ type; sl@0: BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_keywords,(T)) sl@0: }; sl@0: # else sl@0: typedef char (&yes_keywords_t)[1]; sl@0: typedef char (&no_keywords_t)[2]; sl@0: sl@0: no_keywords_t is_keywords_test(...); sl@0: sl@0: template sl@0: yes_keywords_t is_keywords_test(void (*)(keywords&)); sl@0: sl@0: template sl@0: yes_keywords_t is_keywords_test(void (*)(keywords const&)); sl@0: sl@0: template sl@0: class is_reference_to_keywords sl@0: { sl@0: public: sl@0: BOOST_STATIC_CONSTANT( sl@0: bool, value = ( sl@0: sizeof(detail::is_keywords_test( (void (*)(T))0 )) sl@0: == sizeof(detail::yes_keywords_t))); sl@0: sl@0: typedef mpl::bool_ type; sl@0: BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_keywords,(T)) sl@0: }; sl@0: # endif sl@0: } sl@0: sl@0: inline detail::keywords<1> args(char const* name) sl@0: { sl@0: return detail::keywords<1>(name); sl@0: } sl@0: sl@0: # define BOOST_PYTHON_ASSIGN_NAME(z, n, _) result.elements[n].name = name##n; sl@0: # define BOOST_PP_LOCAL_MACRO(n) \ sl@0: inline detail::keywords args(BOOST_PP_ENUM_PARAMS_Z(1, n, char const* name)) \ sl@0: { \ sl@0: detail::keywords result; \ sl@0: BOOST_PP_REPEAT_1(n, BOOST_PYTHON_ASSIGN_NAME, _) \ sl@0: return result; \ sl@0: } sl@0: # define BOOST_PP_LOCAL_LIMITS (2, BOOST_PYTHON_MAX_ARITY) sl@0: # include BOOST_PP_LOCAL_ITERATE() sl@0: sl@0: }} // namespace boost::python sl@0: sl@0: sl@0: # endif // KEYWORDS_DWA2002323_HPP