Skip to content

Commit f2fa852

Browse files
committed
initial commit
[SVN r13837]
1 parent 59f4ddf commit f2fa852

File tree

6 files changed

+447
-0
lines changed

6 files changed

+447
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright David Abrahams 2002. Permission to copy, use,
2+
// modify, sell and distribute this software is granted provided this
3+
// copyright notice appears in all copies. This software is provided
4+
// "as is" without express or implied warranty, and with no claim as
5+
// to its suitability for any purpose.
6+
#ifndef TARGET_DWA2002513_HPP
7+
# define TARGET_DWA2002513_HPP
8+
9+
# include <boost/type.hpp>
10+
11+
namespace boost { namespace python { namespace detail {
12+
13+
//
14+
// target(x) - deduce the type of the first argument when bind(x) is
15+
// invoked.
16+
//
17+
18+
// functions
19+
template <class Target, class R>
20+
boost::type<Target>* target(R (*)(Target)) { return 0; }
21+
22+
template <class Target, class R, class A1>
23+
boost::type<Target>* target(R (*)(Target, A1)) { return 0; }
24+
25+
template <class Target, class R, class A1, class A2>
26+
boost::type<Target>* target(R (*)(Target, A1, A2)) { return 0; }
27+
28+
template <class Target, class R, class A1, class A2, class A3>
29+
boost::type<Target>* target(R (*)(Target, A1, A2, A3)) { return 0; }
30+
31+
// data member pointers
32+
template <class Target, class R>
33+
boost::type<Target&>* target(R (Target::*)) { return 0; }
34+
35+
// member Functions
36+
template <class Target, class R>
37+
boost::type<Target&>* target(R (Target::*)()) { return 0; }
38+
39+
template <class Target, class R, class A1>
40+
boost::type<Target&>* target(R (Target::*)(A1)) { return 0; }
41+
42+
template <class Target, class R, class A1, class A2>
43+
boost::type<Target&>* target(R (Target::*)(A1,A2)) { return 0; }
44+
45+
template <class Target, class R, class A1, class A2, class A3>
46+
boost::type<Target&>* target(R (Target::*)(A1,A2,A3)) { return 0; }
47+
48+
// const member functions
49+
template <class Target, class R>
50+
boost::type<Target const&>* target(R (Target::*)() const) { return 0; }
51+
52+
template <class Target, class R, class A1>
53+
boost::type<Target const&>* target(R (Target::*)(A1) const) { return 0; }
54+
55+
template <class Target, class R, class A1, class A2>
56+
boost::type<Target const&>* target(R (Target::*)(A1,A2) const) { return 0; }
57+
58+
template <class Target, class R, class A1, class A2, class A3>
59+
boost::type<Target const&>* target(R (Target::*)(A1,A2,A3) const) { return 0; }
60+
61+
// volatile member functions
62+
template <class Target, class R>
63+
boost::type<Target volatile&>* target(R (Target::*)() volatile) { return 0; }
64+
65+
template <class Target, class R, class A1>
66+
boost::type<Target volatile&>* target(R (Target::*)(A1) volatile) { return 0; }
67+
68+
template <class Target, class R, class A1, class A2>
69+
boost::type<Target volatile&>* target(R (Target::*)(A1,A2) volatile) { return 0; }
70+
71+
template <class Target, class R, class A1, class A2, class A3>
72+
boost::type<Target volatile&>* target(R (Target::*)(A1,A2,A3) volatile) { return 0; }
73+
74+
// const volatile member functions
75+
template <class Target, class R>
76+
boost::type<Target const volatile&>* target(R (Target::*)() const volatile) { return 0; }
77+
78+
template <class Target, class R, class A1>
79+
boost::type<Target const volatile&>* target(R (Target::*)(A1) const volatile) { return 0; }
80+
81+
template <class Target, class R, class A1, class A2>
82+
boost::type<Target const volatile&>* target(R (Target::*)(A1,A2) const volatile) { return 0; }
83+
84+
template <class Target, class R, class A1, class A2, class A3>
85+
boost::type<Target const volatile&>* target(R (Target::*)(A1,A2,A3) const volatile) { return 0; }
86+
87+
}}} // namespace boost::python::detail
88+
89+
#endif // TARGET_DWA2002513_HPP

include/boost/python/iterator.hpp

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Copyright David Abrahams 2002. Permission to copy, use,
2+
// modify, sell and distribute this software is granted provided this
3+
// copyright notice appears in all copies. This software is provided
4+
// "as is" without express or implied warranty, and with no claim as
5+
// to its suitability for any purpose.
6+
#ifndef ITERATOR_DWA2002512_HPP
7+
# define ITERATOR_DWA2002512_HPP
8+
9+
# include <boost/python/detail/target.hpp>
10+
# include <boost/python/object/iterator.hpp>
11+
# include <boost/type_traits/cv_traits.hpp>
12+
# include <boost/type_traits/transform_traits.hpp>
13+
14+
namespace boost { namespace python {
15+
16+
namespace detail
17+
{
18+
// Adds an additional layer of binding to
19+
// objects::make_iterator(...), which allows us to pass member
20+
// function and member data pointers.
21+
template <class Target, class NextPolicies, class Accessor1, class Accessor2>
22+
inline ref make_iterator(
23+
Accessor1 get_start, Accessor2 get_finish, NextPolicies* = 0, boost::type<Target>* target = 0)
24+
{
25+
return objects::make_iterator_function(
26+
boost::protect(boost::bind(get_start, _1))
27+
, boost::protect(boost::bind(get_finish, _1))
28+
, (NextPolicies*)0
29+
, target);
30+
}
31+
32+
// Guts of template class iterators<>, below.
33+
template <bool const_ = false>
34+
struct iterators_impl
35+
{
36+
template <class T>
37+
struct apply
38+
{
39+
typedef typename T::iterator iterator;
40+
static iterator begin(T& x) { return x.begin(); }
41+
static iterator end(T& x) { return x.end(); }
42+
};
43+
};
44+
45+
template <>
46+
struct iterators_impl<true>
47+
{
48+
template <class T>
49+
struct apply
50+
{
51+
typedef typename T::const_iterator iterator;
52+
static iterator begin(T& x) { return x.begin(); }
53+
static iterator end(T& x) { return x.end(); }
54+
};
55+
};
56+
}
57+
58+
// An "ordinary function generator" which contains static begin(x) and
59+
// end(x) functions that invoke T::begin() and T::end(), respectively.
60+
template <class T>
61+
struct iterators
62+
: detail::iterators_impl<
63+
boost::is_const<T>::value
64+
>::template apply<T>
65+
{
66+
};
67+
68+
// Create an iterator-building function which uses the given
69+
// accessors. Deduce the Target type from the accessors. The iterator
70+
// returns copies of the inderlying elements.
71+
template <class Accessor1, class Accessor2>
72+
ref range(Accessor1 start, Accessor2 finish)
73+
{
74+
return detail::make_iterator(start, finish, (objects::default_iterator_call_policies*)0, detail::target(start));
75+
}
76+
77+
// Create an iterator-building function which uses the given accessors
78+
// and next() policies. Deduce the Target type.
79+
template <class NextPolicies, class Accessor1, class Accessor2>
80+
ref range(Accessor1 start, Accessor2 finish, NextPolicies* = 0)
81+
{
82+
return detail::make_iterator(start, finish, (NextPolicies*)0, detail::target(start));
83+
}
84+
85+
// Create an iterator-building function which uses the given accessors
86+
// and next() policies, operating on the given Target type
87+
template <class NextPolicies, class Target, class Accessor1, class Accessor2>
88+
ref range(Accessor1 start, Accessor2 finish, NextPolicies* = 0, boost::type<Target>* = 0)
89+
{
90+
typedef typename add_reference<Target>::type target;
91+
return detail::make_iterator(start, finish, (NextPolicies*)0,
92+
(boost::type<target>*)0);
93+
}
94+
95+
// A Python callable object which produces an iterator traversing
96+
// [x.begin(), x.end()), where x is an instance of the Container
97+
// type. NextPolicies are used as the CallPolicies for the iterator's
98+
// next() function.
99+
template <class Container
100+
, class NextPolicies = objects::default_iterator_call_policies>
101+
struct iterator : ref
102+
{
103+
iterator()
104+
: ref(
105+
range<NextPolicies>(
106+
&iterators<Container>::begin, &iterators<Container>::end
107+
))
108+
{
109+
}
110+
};
111+
112+
}} // namespace boost::python
113+
114+
#endif // ITERATOR_DWA2002512_HPP

0 commit comments

Comments
 (0)