1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/python/args.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,175 @@
1.4 +// Copyright David Abrahams 2002.
1.5 +// Distributed under the Boost Software License, Version 1.0. (See
1.6 +// accompanying file LICENSE_1_0.txt or copy at
1.7 +// http://www.boost.org/LICENSE_1_0.txt)
1.8 +#ifndef KEYWORDS_DWA2002323_HPP
1.9 +# define KEYWORDS_DWA2002323_HPP
1.10 +
1.11 +# include <boost/python/detail/prefix.hpp>
1.12 +
1.13 +# include <boost/python/args_fwd.hpp>
1.14 +# include <boost/config.hpp>
1.15 +# include <boost/python/detail/preprocessor.hpp>
1.16 +# include <boost/python/detail/type_list.hpp>
1.17 +
1.18 +# include <boost/type_traits/is_reference.hpp>
1.19 +# include <boost/type_traits/remove_reference.hpp>
1.20 +# include <boost/type_traits/remove_cv.hpp>
1.21 +
1.22 +# include <boost/preprocessor/enum_params.hpp>
1.23 +# include <boost/preprocessor/repeat.hpp>
1.24 +# include <boost/preprocessor/facilities/intercept.hpp>
1.25 +# include <boost/preprocessor/iteration/local.hpp>
1.26 +
1.27 +# include <boost/python/detail/mpl_lambda.hpp>
1.28 +# include <boost/python/object_core.hpp>
1.29 +
1.30 +# include <boost/mpl/bool.hpp>
1.31 +
1.32 +# include <cstddef>
1.33 +# include <algorithm>
1.34 +
1.35 +namespace boost { namespace python {
1.36 +
1.37 +typedef detail::keywords<1> arg;
1.38 +typedef arg arg_; // gcc 2.96 workaround
1.39 +
1.40 +namespace detail
1.41 +{
1.42 + template <std::size_t nkeywords>
1.43 + struct keywords_base
1.44 + {
1.45 + BOOST_STATIC_CONSTANT(std::size_t, size = nkeywords);
1.46 +
1.47 + keyword_range range() const
1.48 + {
1.49 + return keyword_range(elements, elements + nkeywords);
1.50 + }
1.51 +
1.52 + keyword elements[nkeywords];
1.53 +
1.54 + keywords<nkeywords+1>
1.55 + operator,(python::arg const &k) const;
1.56 +
1.57 + keywords<nkeywords + 1>
1.58 + operator,(char const *name) const;
1.59 + };
1.60 +
1.61 + template <std::size_t nkeywords>
1.62 + struct keywords : keywords_base<nkeywords>
1.63 + {
1.64 + };
1.65 +
1.66 + template <>
1.67 + struct keywords<1> : keywords_base<1>
1.68 + {
1.69 + explicit keywords(char const *name)
1.70 + {
1.71 + elements[0].name = name;
1.72 + }
1.73 +
1.74 + template <class T>
1.75 + python::arg& operator=(T const& value)
1.76 + {
1.77 + object z(value);
1.78 + elements[0].default_value = handle<>(python::borrowed(object(value).ptr()));
1.79 + return *this;
1.80 + }
1.81 +
1.82 + operator detail::keyword const&() const
1.83 + {
1.84 + return elements[0];
1.85 + }
1.86 + };
1.87 +
1.88 + template <std::size_t nkeywords>
1.89 + inline
1.90 + keywords<nkeywords+1>
1.91 + keywords_base<nkeywords>::operator,(python::arg const &k) const
1.92 + {
1.93 + keywords<nkeywords> const& l = *static_cast<keywords<nkeywords> const*>(this);
1.94 + python::detail::keywords<nkeywords+1> res;
1.95 + std::copy(l.elements, l.elements+nkeywords, res.elements);
1.96 + res.elements[nkeywords] = k.elements[0];
1.97 + return res;
1.98 + }
1.99 +
1.100 + template <std::size_t nkeywords>
1.101 + inline
1.102 + keywords<nkeywords + 1>
1.103 + keywords_base<nkeywords>::operator,(char const *name) const
1.104 + {
1.105 + return this->operator,(python::arg(name));
1.106 + }
1.107 +
1.108 +# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
1.109 + template<typename T>
1.110 + struct is_keywords
1.111 + {
1.112 + BOOST_STATIC_CONSTANT(bool, value = false);
1.113 + };
1.114 +
1.115 + template<std::size_t nkeywords>
1.116 + struct is_keywords<keywords<nkeywords> >
1.117 + {
1.118 + BOOST_STATIC_CONSTANT(bool, value = true);
1.119 + };
1.120 + template <class T>
1.121 + struct is_reference_to_keywords
1.122 + {
1.123 + BOOST_STATIC_CONSTANT(bool, is_ref = is_reference<T>::value);
1.124 + typedef typename remove_reference<T>::type deref;
1.125 + typedef typename remove_cv<deref>::type key_t;
1.126 + BOOST_STATIC_CONSTANT(bool, is_key = is_keywords<key_t>::value);
1.127 + BOOST_STATIC_CONSTANT(bool, value = (is_ref & is_key));
1.128 +
1.129 + typedef mpl::bool_<value> type;
1.130 + BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_keywords,(T))
1.131 + };
1.132 +# else
1.133 + typedef char (&yes_keywords_t)[1];
1.134 + typedef char (&no_keywords_t)[2];
1.135 +
1.136 + no_keywords_t is_keywords_test(...);
1.137 +
1.138 + template<std::size_t nkeywords>
1.139 + yes_keywords_t is_keywords_test(void (*)(keywords<nkeywords>&));
1.140 +
1.141 + template<std::size_t nkeywords>
1.142 + yes_keywords_t is_keywords_test(void (*)(keywords<nkeywords> const&));
1.143 +
1.144 + template<typename T>
1.145 + class is_reference_to_keywords
1.146 + {
1.147 + public:
1.148 + BOOST_STATIC_CONSTANT(
1.149 + bool, value = (
1.150 + sizeof(detail::is_keywords_test( (void (*)(T))0 ))
1.151 + == sizeof(detail::yes_keywords_t)));
1.152 +
1.153 + typedef mpl::bool_<value> type;
1.154 + BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_keywords,(T))
1.155 + };
1.156 +# endif
1.157 +}
1.158 +
1.159 +inline detail::keywords<1> args(char const* name)
1.160 +{
1.161 + return detail::keywords<1>(name);
1.162 +}
1.163 +
1.164 +# define BOOST_PYTHON_ASSIGN_NAME(z, n, _) result.elements[n].name = name##n;
1.165 +# define BOOST_PP_LOCAL_MACRO(n) \
1.166 +inline detail::keywords<n> args(BOOST_PP_ENUM_PARAMS_Z(1, n, char const* name)) \
1.167 +{ \
1.168 + detail::keywords<n> result; \
1.169 + BOOST_PP_REPEAT_1(n, BOOST_PYTHON_ASSIGN_NAME, _) \
1.170 + return result; \
1.171 +}
1.172 +# define BOOST_PP_LOCAL_LIMITS (2, BOOST_PYTHON_MAX_ARITY)
1.173 +# include BOOST_PP_LOCAL_ITERATE()
1.174 +
1.175 +}} // namespace boost::python
1.176 +
1.177 +
1.178 +# endif // KEYWORDS_DWA2002323_HPP