Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/python/iterator.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 ITERATOR_DWA2002512_HPP
0006 # define ITERATOR_DWA2002512_HPP
0007 
0008 # include <boost/python/detail/prefix.hpp>
0009 
0010 # include <boost/python/detail/target.hpp>
0011 # include <boost/python/detail/type_traits.hpp>
0012 # include <boost/python/object/iterator.hpp>
0013 # include <boost/python/object_core.hpp>
0014 
0015 # if defined(BOOST_MSVC) && (BOOST_MSVC == 1400) /*
0016 > warning C4180: qualifier applied to function type has no meaning; ignored
0017 Peter Dimov wrote:
0018 This warning is caused by an overload resolution bug in VC8 that cannot be
0019 worked around and will probably not be fixed by MS in the VC8 line. The
0020 problematic overload is only instantiated and never called, and the code
0021 works correctly. */
0022 #  pragma warning(disable: 4180)
0023 # endif
0024 
0025 # include <boost/bind/bind.hpp>
0026 # include <boost/bind/protect.hpp>
0027 
0028 namespace boost { namespace python { 
0029 
0030 namespace detail
0031 {
0032   // Adds an additional layer of binding to
0033   // objects::make_iterator(...), which allows us to pass member
0034   // function and member data pointers.
0035   template <class Target, class Accessor1, class Accessor2, class NextPolicies>
0036   inline object make_iterator(
0037       Accessor1 get_start
0038     , Accessor2 get_finish
0039     , NextPolicies next_policies
0040     , Target&(*)()
0041   )
0042   {
0043       using namespace boost::placeholders;
0044       return objects::make_iterator_function<Target>(
0045           boost::protect(boost::bind(get_start, _1))
0046         , boost::protect(boost::bind(get_finish, _1))
0047         , next_policies
0048       );
0049   }
0050 
0051   // Guts of template class iterators<>, below.
0052   template <bool const_ = false>
0053   struct iterators_impl
0054   {
0055       template <class T>
0056       struct apply
0057       {
0058           typedef typename T::iterator iterator;
0059           static iterator begin(T& x) { return x.begin(); }
0060           static iterator end(T& x) { return x.end(); }
0061       };
0062   };
0063 
0064   template <>
0065   struct iterators_impl<true>
0066   {
0067       template <class T>
0068       struct apply
0069       {
0070           typedef typename T::const_iterator iterator;
0071           static iterator begin(T& x) { return x.begin(); }
0072           static iterator end(T& x) { return x.end(); }
0073       };
0074   };
0075 }
0076 
0077 // An "ordinary function generator" which contains static begin(x) and
0078 // end(x) functions that invoke T::begin() and T::end(), respectively.
0079 template <class T>
0080 struct iterators
0081     : detail::iterators_impl<
0082         detail::is_const<T>::value
0083       >::template apply<T>
0084 {
0085 };
0086 
0087 // Create an iterator-building function which uses the given
0088 // accessors. Deduce the Target type from the accessors. The iterator
0089 // returns copies of the inderlying elements.
0090 template <class Accessor1, class Accessor2>
0091 object range(Accessor1 start, Accessor2 finish)
0092 {
0093     return detail::make_iterator(
0094         start, finish
0095       , objects::default_iterator_call_policies()
0096       , detail::target(start)
0097     );
0098 }
0099 
0100 // Create an iterator-building function which uses the given accessors
0101 // and next() policies. Deduce the Target type.
0102 template <class NextPolicies, class Accessor1, class Accessor2>
0103 object range(Accessor1 start, Accessor2 finish, NextPolicies* = 0)
0104 {
0105     return detail::make_iterator(start, finish, NextPolicies(), detail::target(start));
0106 }
0107 
0108 // Create an iterator-building function which uses the given accessors
0109 // and next() policies, operating on the given Target type
0110 template <class NextPolicies, class Target, class Accessor1, class Accessor2>
0111 object range(Accessor1 start, Accessor2 finish, NextPolicies* = 0, boost::type<Target>* = 0)
0112 {
0113     // typedef typename add_reference<Target>::type target;
0114     return detail::make_iterator(start, finish, NextPolicies(), (Target&(*)())0);
0115 }
0116 
0117 // A Python callable object which produces an iterator traversing
0118 // [x.begin(), x.end()), where x is an instance of the Container
0119 // type. NextPolicies are used as the CallPolicies for the iterator's
0120 // next() function.
0121 template <class Container
0122           , class NextPolicies = objects::default_iterator_call_policies>
0123 struct iterator : object
0124 {
0125     iterator()
0126         : object(
0127             python::range<NextPolicies>(
0128                 &iterators<Container>::begin, &iterators<Container>::end
0129                 ))
0130     {
0131     }
0132 };
0133 
0134 }} // namespace boost::python
0135 
0136 #endif // ITERATOR_DWA2002512_HPP