annotate DEPENDENCIES/generic/include/boost/python/detail/def_helper.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // Copyright David Abrahams 2002.
Chris@16 2 // Distributed under the Boost Software License, Version 1.0. (See
Chris@16 3 // accompanying file LICENSE_1_0.txt or copy at
Chris@16 4 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 5 #ifndef DEF_HELPER_DWA200287_HPP
Chris@16 6 # define DEF_HELPER_DWA200287_HPP
Chris@16 7
Chris@16 8 # include <boost/python/args.hpp>
Chris@16 9 # include <boost/type_traits/ice.hpp>
Chris@16 10 # include <boost/type_traits/same_traits.hpp>
Chris@16 11 # include <boost/python/detail/indirect_traits.hpp>
Chris@16 12 # include <boost/mpl/not.hpp>
Chris@16 13 # include <boost/mpl/and.hpp>
Chris@16 14 # include <boost/mpl/or.hpp>
Chris@16 15 # include <boost/type_traits/add_reference.hpp>
Chris@16 16 # include <boost/mpl/lambda.hpp>
Chris@16 17 # include <boost/mpl/apply.hpp>
Chris@16 18 # include <boost/tuple/tuple.hpp>
Chris@16 19 # include <boost/python/detail/not_specified.hpp>
Chris@16 20 # include <boost/python/detail/def_helper_fwd.hpp>
Chris@16 21
Chris@16 22 namespace boost { namespace python {
Chris@16 23
Chris@16 24 struct default_call_policies;
Chris@16 25
Chris@16 26 namespace detail
Chris@16 27 {
Chris@16 28 // tuple_extract<Tuple,Predicate>::extract(t) returns the first
Chris@16 29 // element of a Tuple whose type E satisfies the given Predicate
Chris@16 30 // applied to add_reference<E>. The Predicate must be an MPL
Chris@16 31 // metafunction class.
Chris@16 32 template <class Tuple, class Predicate>
Chris@16 33 struct tuple_extract;
Chris@16 34
Chris@16 35 // Implementation class for when the tuple's head type does not
Chris@16 36 // satisfy the Predicate
Chris@16 37 template <bool matched>
Chris@16 38 struct tuple_extract_impl
Chris@16 39 {
Chris@16 40 template <class Tuple, class Predicate>
Chris@16 41 struct apply
Chris@16 42 {
Chris@16 43 typedef typename Tuple::head_type result_type;
Chris@16 44
Chris@16 45 static typename Tuple::head_type extract(Tuple const& x)
Chris@16 46 {
Chris@16 47 return x.get_head();
Chris@16 48 }
Chris@16 49 };
Chris@16 50 };
Chris@16 51
Chris@16 52 // Implementation specialization for when the tuple's head type
Chris@16 53 // satisfies the predicate
Chris@16 54 template <>
Chris@16 55 struct tuple_extract_impl<false>
Chris@16 56 {
Chris@16 57 template <class Tuple, class Predicate>
Chris@16 58 struct apply
Chris@16 59 {
Chris@16 60 // recursive application of tuple_extract on the tail of the tuple
Chris@16 61 typedef tuple_extract<typename Tuple::tail_type, Predicate> next;
Chris@16 62 typedef typename next::result_type result_type;
Chris@16 63
Chris@16 64 static result_type extract(Tuple const& x)
Chris@16 65 {
Chris@16 66 return next::extract(x.get_tail());
Chris@16 67 }
Chris@16 68 };
Chris@16 69 };
Chris@16 70
Chris@16 71 // A metafunction which selects a version of tuple_extract_impl to
Chris@16 72 // use for the implementation of tuple_extract
Chris@16 73 template <class Tuple, class Predicate>
Chris@16 74 struct tuple_extract_base_select
Chris@16 75 {
Chris@16 76 typedef typename Tuple::head_type head_type;
Chris@16 77 typedef typename mpl::apply1<Predicate, typename add_reference<head_type>::type>::type match_t;
Chris@16 78 BOOST_STATIC_CONSTANT(bool, match = match_t::value);
Chris@16 79 typedef typename tuple_extract_impl<match>::template apply<Tuple,Predicate> type;
Chris@16 80 };
Chris@16 81
Chris@16 82 template <class Tuple, class Predicate>
Chris@16 83 struct tuple_extract
Chris@16 84 : tuple_extract_base_select<
Chris@16 85 Tuple
Chris@16 86 , typename mpl::lambda<Predicate>::type
Chris@16 87 >::type
Chris@16 88 {
Chris@16 89 };
Chris@16 90
Chris@16 91
Chris@16 92 //
Chris@16 93 // Specialized extractors for the docstring, keywords, CallPolicies,
Chris@16 94 // and default implementation of virtual functions
Chris@16 95 //
Chris@16 96
Chris@16 97 template <class Tuple>
Chris@16 98 struct doc_extract
Chris@16 99 : tuple_extract<
Chris@16 100 Tuple
Chris@16 101 , mpl::not_<
Chris@16 102 mpl::or_<
Chris@16 103 indirect_traits::is_reference_to_class<mpl::_1>
Chris@16 104 , indirect_traits::is_reference_to_member_function_pointer<mpl::_1 >
Chris@16 105 >
Chris@16 106 >
Chris@16 107 >
Chris@16 108 {
Chris@16 109 };
Chris@16 110
Chris@16 111 template <class Tuple>
Chris@16 112 struct keyword_extract
Chris@16 113 : tuple_extract<Tuple, is_reference_to_keywords<mpl::_1 > >
Chris@16 114 {
Chris@16 115 };
Chris@16 116
Chris@16 117 template <class Tuple>
Chris@16 118 struct policy_extract
Chris@16 119 : tuple_extract<
Chris@16 120 Tuple
Chris@16 121 , mpl::and_<
Chris@16 122 mpl::not_<is_same<not_specified const&,mpl::_1> >
Chris@16 123 , indirect_traits::is_reference_to_class<mpl::_1 >
Chris@16 124 , mpl::not_<is_reference_to_keywords<mpl::_1 > >
Chris@16 125 >
Chris@16 126 >
Chris@16 127 {
Chris@16 128 };
Chris@16 129
Chris@16 130 template <class Tuple>
Chris@16 131 struct default_implementation_extract
Chris@16 132 : tuple_extract<
Chris@16 133 Tuple
Chris@16 134 , indirect_traits::is_reference_to_member_function_pointer<mpl::_1 >
Chris@16 135 >
Chris@16 136 {
Chris@16 137 };
Chris@16 138
Chris@16 139 //
Chris@16 140 // A helper class for decoding the optional arguments to def()
Chris@16 141 // invocations, which can be supplied in any order and are
Chris@16 142 // discriminated by their type properties. The template parameters
Chris@16 143 // are expected to be the types of the actual (optional) arguments
Chris@16 144 // passed to def().
Chris@16 145 //
Chris@16 146 template <class T1, class T2, class T3, class T4>
Chris@16 147 struct def_helper
Chris@16 148 {
Chris@16 149 // A tuple type which begins with references to the supplied
Chris@16 150 // arguments and ends with actual representatives of the default
Chris@16 151 // types.
Chris@16 152 typedef boost::tuples::tuple<
Chris@16 153 T1 const&
Chris@16 154 , T2 const&
Chris@16 155 , T3 const&
Chris@16 156 , T4 const&
Chris@16 157 , default_call_policies
Chris@16 158 , detail::keywords<0>
Chris@16 159 , char const*
Chris@16 160 , void(not_specified::*)() // A function pointer type which is never an
Chris@16 161 // appropriate default implementation
Chris@16 162 > all_t;
Chris@16 163
Chris@16 164 // Constructors; these initialize an member of the tuple type
Chris@16 165 // shown above.
Chris@16 166 def_helper(T1 const& a1) : m_all(a1,m_nil,m_nil,m_nil) {}
Chris@16 167 def_helper(T1 const& a1, T2 const& a2) : m_all(a1,a2,m_nil,m_nil) {}
Chris@16 168 def_helper(T1 const& a1, T2 const& a2, T3 const& a3) : m_all(a1,a2,a3,m_nil) {}
Chris@16 169 def_helper(T1 const& a1, T2 const& a2, T3 const& a3, T4 const& a4) : m_all(a1,a2,a3,a4) {}
Chris@16 170
Chris@16 171 private: // types
Chris@16 172 typedef typename default_implementation_extract<all_t>::result_type default_implementation_t;
Chris@16 173
Chris@16 174 public: // Constants which can be used for static assertions.
Chris@16 175
Chris@16 176 // Users must not supply a default implementation for non-class
Chris@16 177 // methods.
Chris@16 178 BOOST_STATIC_CONSTANT(
Chris@16 179 bool, has_default_implementation = (
Chris@16 180 !is_same<default_implementation_t, void(not_specified::*)()>::value));
Chris@16 181
Chris@16 182 public: // Extractor functions which pull the appropriate value out
Chris@16 183 // of the tuple
Chris@16 184 char const* doc() const
Chris@16 185 {
Chris@16 186 return doc_extract<all_t>::extract(m_all);
Chris@16 187 }
Chris@16 188
Chris@16 189 typename keyword_extract<all_t>::result_type keywords() const
Chris@16 190 {
Chris@16 191 return keyword_extract<all_t>::extract(m_all);
Chris@16 192 }
Chris@16 193
Chris@16 194 typename policy_extract<all_t>::result_type policies() const
Chris@16 195 {
Chris@16 196 return policy_extract<all_t>::extract(m_all);
Chris@16 197 }
Chris@16 198
Chris@16 199 default_implementation_t default_implementation() const
Chris@16 200 {
Chris@16 201 return default_implementation_extract<all_t>::extract(m_all);
Chris@16 202 }
Chris@16 203
Chris@16 204 private: // data members
Chris@16 205 all_t m_all;
Chris@16 206 not_specified m_nil; // for filling in not_specified slots
Chris@16 207 };
Chris@16 208 }
Chris@16 209
Chris@16 210 }} // namespace boost::python::detail
Chris@16 211
Chris@16 212 #endif // DEF_HELPER_DWA200287_HPP