os/ossrv/ossrv_pub/boost_apis/boost/python/iterator.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/python/iterator.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,127 @@
     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 ITERATOR_DWA2002512_HPP
     1.9 +# define ITERATOR_DWA2002512_HPP
    1.10 +
    1.11 +# include <boost/python/detail/prefix.hpp>
    1.12 +
    1.13 +# include <boost/python/detail/target.hpp>
    1.14 +# include <boost/python/object/iterator.hpp>
    1.15 +# include <boost/python/object_core.hpp>
    1.16 +
    1.17 +# include <boost/type_traits/cv_traits.hpp>
    1.18 +# include <boost/type_traits/transform_traits.hpp>
    1.19 +
    1.20 +# include <boost/bind.hpp>
    1.21 +# include <boost/bind/protect.hpp>
    1.22 +
    1.23 +namespace boost { namespace python { 
    1.24 +
    1.25 +namespace detail
    1.26 +{
    1.27 +  // Adds an additional layer of binding to
    1.28 +  // objects::make_iterator(...), which allows us to pass member
    1.29 +  // function and member data pointers.
    1.30 +  template <class Target, class Accessor1, class Accessor2, class NextPolicies>
    1.31 +  inline object make_iterator(
    1.32 +      Accessor1 get_start
    1.33 +    , Accessor2 get_finish
    1.34 +    , NextPolicies next_policies
    1.35 +    , Target&(*)()
    1.36 +  )
    1.37 +  {
    1.38 +      return objects::make_iterator_function<Target>(
    1.39 +          boost::protect(boost::bind(get_start, _1))
    1.40 +        , boost::protect(boost::bind(get_finish, _1))
    1.41 +        , next_policies
    1.42 +      );
    1.43 +  }
    1.44 +
    1.45 +  // Guts of template class iterators<>, below.
    1.46 +  template <bool const_ = false>
    1.47 +  struct iterators_impl
    1.48 +  {
    1.49 +      template <class T>
    1.50 +      struct apply
    1.51 +      {
    1.52 +          typedef typename T::iterator iterator;
    1.53 +          static iterator begin(T& x) { return x.begin(); }
    1.54 +          static iterator end(T& x) { return x.end(); }
    1.55 +      };
    1.56 +  };
    1.57 +
    1.58 +  template <>
    1.59 +  struct iterators_impl<true>
    1.60 +  {
    1.61 +      template <class T>
    1.62 +      struct apply
    1.63 +      {
    1.64 +          typedef typename T::const_iterator iterator;
    1.65 +          static iterator begin(T& x) { return x.begin(); }
    1.66 +          static iterator end(T& x) { return x.end(); }
    1.67 +      };
    1.68 +  };
    1.69 +}
    1.70 +
    1.71 +// An "ordinary function generator" which contains static begin(x) and
    1.72 +// end(x) functions that invoke T::begin() and T::end(), respectively.
    1.73 +template <class T>
    1.74 +struct iterators
    1.75 +    : detail::iterators_impl<
    1.76 +        boost::is_const<T>::value
    1.77 +      >::template apply<T>
    1.78 +{
    1.79 +};
    1.80 +
    1.81 +// Create an iterator-building function which uses the given
    1.82 +// accessors. Deduce the Target type from the accessors. The iterator
    1.83 +// returns copies of the inderlying elements.
    1.84 +template <class Accessor1, class Accessor2>
    1.85 +object range(Accessor1 start, Accessor2 finish)
    1.86 +{
    1.87 +    return detail::make_iterator(
    1.88 +        start, finish
    1.89 +      , objects::default_iterator_call_policies()
    1.90 +      , detail::target(start)
    1.91 +    );
    1.92 +}
    1.93 +
    1.94 +// Create an iterator-building function which uses the given accessors
    1.95 +// and next() policies. Deduce the Target type.
    1.96 +template <class NextPolicies, class Accessor1, class Accessor2>
    1.97 +object range(Accessor1 start, Accessor2 finish, NextPolicies* = 0)
    1.98 +{
    1.99 +    return detail::make_iterator(start, finish, NextPolicies(), detail::target(start));
   1.100 +}
   1.101 +
   1.102 +// Create an iterator-building function which uses the given accessors
   1.103 +// and next() policies, operating on the given Target type
   1.104 +template <class NextPolicies, class Target, class Accessor1, class Accessor2>
   1.105 +object range(Accessor1 start, Accessor2 finish, NextPolicies* = 0, boost::type<Target>* = 0)
   1.106 +{
   1.107 +    // typedef typename add_reference<Target>::type target;
   1.108 +    return detail::make_iterator(start, finish, NextPolicies(), (Target&(*)())0);
   1.109 +}
   1.110 +
   1.111 +// A Python callable object which produces an iterator traversing
   1.112 +// [x.begin(), x.end()), where x is an instance of the Container
   1.113 +// type. NextPolicies are used as the CallPolicies for the iterator's
   1.114 +// next() function.
   1.115 +template <class Container
   1.116 +          , class NextPolicies = objects::default_iterator_call_policies>
   1.117 +struct iterator : object
   1.118 +{
   1.119 +    iterator()
   1.120 +        : object(
   1.121 +            python::range<NextPolicies>(
   1.122 +                &iterators<Container>::begin, &iterators<Container>::end
   1.123 +                ))
   1.124 +    {
   1.125 +    }
   1.126 +};
   1.127 +
   1.128 +}} // namespace boost::python
   1.129 +
   1.130 +#endif // ITERATOR_DWA2002512_HPP