Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:37

0001 // Copyright David Abrahams 2002.
0002 // Distributed under the Boost Software License, Version 1.0. (See
0003 // accompanying file LICENSE_1_0.txt or copy at
0004 // http://www.boost.org/LICENSE_1_0.txt)
0005 #ifndef DEF_HELPER_DWA200287_HPP
0006 # define DEF_HELPER_DWA200287_HPP
0007 
0008 # include <boost/python/args.hpp>
0009 # include <boost/python/detail/indirect_traits.hpp>
0010 # include <boost/python/detail/type_traits.hpp>
0011 # include <boost/mpl/not.hpp>
0012 # include <boost/mpl/and.hpp>
0013 # include <boost/mpl/or.hpp>
0014 # include <boost/mpl/lambda.hpp>
0015 # include <boost/mpl/apply.hpp>
0016 # include <boost/tuple/tuple.hpp>
0017 # include <boost/python/detail/not_specified.hpp>
0018 # include <boost/python/detail/def_helper_fwd.hpp>
0019 
0020 namespace boost { namespace python {
0021 
0022 struct default_call_policies;
0023 
0024 namespace detail
0025 {
0026   // tuple_extract<Tuple,Predicate>::extract(t) returns the first
0027   // element of a Tuple whose type E satisfies the given Predicate
0028   // applied to add_reference<E>. The Predicate must be an MPL
0029   // metafunction class.
0030   template <class Tuple, class Predicate>
0031   struct tuple_extract;
0032 
0033   // Implementation class for when the tuple's head type does not
0034   // satisfy the Predicate
0035   template <bool matched>
0036   struct tuple_extract_impl
0037   {
0038       template <class Tuple, class Predicate>
0039       struct apply
0040       {
0041           typedef typename Tuple::head_type result_type;
0042           
0043           static typename Tuple::head_type extract(Tuple const& x)
0044           {
0045               return x.get_head();
0046           }
0047       };
0048   };
0049 
0050   // Implementation specialization for when the tuple's head type
0051   // satisfies the predicate
0052   template <>
0053   struct tuple_extract_impl<false>
0054   {
0055       template <class Tuple, class Predicate>
0056       struct apply
0057       {
0058           // recursive application of tuple_extract on the tail of the tuple
0059           typedef tuple_extract<typename Tuple::tail_type, Predicate> next;
0060           typedef typename next::result_type result_type;
0061           
0062           static result_type extract(Tuple const& x)
0063           {
0064               return next::extract(x.get_tail());
0065           }
0066       };
0067   };
0068 
0069   // A metafunction which selects a version of tuple_extract_impl to
0070   // use for the implementation of tuple_extract
0071   template <class Tuple, class Predicate>
0072   struct tuple_extract_base_select
0073   {
0074       typedef typename Tuple::head_type head_type;
0075       typedef typename mpl::apply1<Predicate,
0076               typename add_lvalue_reference<head_type>::type>::type match_t;
0077       BOOST_STATIC_CONSTANT(bool, match = match_t::value);
0078       typedef typename tuple_extract_impl<match>::template apply<Tuple,Predicate> type;
0079   };
0080   
0081   template <class Tuple, class Predicate>
0082   struct tuple_extract
0083       : tuple_extract_base_select<
0084          Tuple
0085          , typename mpl::lambda<Predicate>::type
0086       >::type
0087   {
0088   };
0089 
0090 
0091   //
0092   // Specialized extractors for the docstring, keywords, CallPolicies,
0093   // and default implementation of virtual functions
0094   //
0095 
0096   template <class Tuple>
0097   struct doc_extract
0098       : tuple_extract<
0099         Tuple
0100         , mpl::not_<
0101            mpl::or_<
0102                indirect_traits::is_reference_to_class<mpl::_1>
0103              , indirect_traits::is_reference_to_member_function_pointer<mpl::_1 >
0104            >
0105         >
0106      >
0107   {
0108   };
0109   
0110   template <class Tuple>
0111   struct keyword_extract
0112       : tuple_extract<Tuple, is_reference_to_keywords<mpl::_1 > >
0113   {
0114   };
0115 
0116   template <class Tuple>
0117   struct policy_extract
0118       : tuple_extract<
0119           Tuple
0120           , mpl::and_<
0121              mpl::not_<is_same<not_specified const&,mpl::_1> >
0122               , indirect_traits::is_reference_to_class<mpl::_1 >
0123               , mpl::not_<is_reference_to_keywords<mpl::_1 > >
0124           >
0125         >
0126   {
0127   };
0128 
0129   template <class Tuple>
0130   struct default_implementation_extract
0131       : tuple_extract<
0132           Tuple
0133           , indirect_traits::is_reference_to_member_function_pointer<mpl::_1 >
0134           >
0135   {
0136   };
0137 
0138   //
0139   // A helper class for decoding the optional arguments to def()
0140   // invocations, which can be supplied in any order and are
0141   // discriminated by their type properties. The template parameters
0142   // are expected to be the types of the actual (optional) arguments
0143   // passed to def().
0144   //
0145   template <class T1, class T2, class T3, class T4>
0146   struct def_helper
0147   {
0148       // A tuple type which begins with references to the supplied
0149       // arguments and ends with actual representatives of the default
0150       // types.
0151       typedef boost::tuples::tuple<
0152           T1 const&
0153           , T2 const&
0154           , T3 const&
0155           , T4 const&
0156           , default_call_policies
0157           , detail::keywords<0>
0158           , char const*
0159           , void(not_specified::*)()   // A function pointer type which is never an
0160                                        // appropriate default implementation
0161           > all_t;
0162 
0163       // Constructors; these initialize an member of the tuple type
0164       // shown above.
0165       def_helper(T1 const& a1) : m_all(a1,m_nil,m_nil,m_nil) {}
0166       def_helper(T1 const& a1, T2 const& a2) : m_all(a1,a2,m_nil,m_nil) {}
0167       def_helper(T1 const& a1, T2 const& a2, T3 const& a3) : m_all(a1,a2,a3,m_nil) {}
0168       def_helper(T1 const& a1, T2 const& a2, T3 const& a3, T4 const& a4) : m_all(a1,a2,a3,a4) {}
0169 
0170    private: // types
0171       typedef typename default_implementation_extract<all_t>::result_type default_implementation_t;
0172       
0173    public: // Constants which can be used for static assertions.
0174 
0175       // Users must not supply a default implementation for non-class
0176       // methods.
0177       BOOST_STATIC_CONSTANT(
0178           bool, has_default_implementation = (
0179               !is_same<default_implementation_t, void(not_specified::*)()>::value));
0180       
0181    public: // Extractor functions which pull the appropriate value out
0182            // of the tuple
0183       char const* doc() const
0184       {
0185           return doc_extract<all_t>::extract(m_all);
0186       }
0187       
0188       typename keyword_extract<all_t>::result_type keywords() const
0189       {
0190           return keyword_extract<all_t>::extract(m_all);
0191       }
0192       
0193       typename policy_extract<all_t>::result_type policies() const
0194       {
0195           return policy_extract<all_t>::extract(m_all);
0196       }
0197 
0198       default_implementation_t default_implementation() const
0199       {
0200           return default_implementation_extract<all_t>::extract(m_all);
0201       }
0202       
0203    private: // data members
0204       all_t m_all; 
0205       not_specified m_nil; // for filling in not_specified slots
0206   };
0207 }
0208 
0209 }} // namespace boost::python::detail
0210 
0211 #endif // DEF_HELPER_DWA200287_HPP