23 #ifndef BOOST_PYTHON_INDEXING_ALGORITHMS_HPP 24 #define BOOST_PYTHON_INDEXING_ALGORITHMS_HPP 26 #include <indexing_suite/suite_utils.hpp> 28 #include <boost/type_traits.hpp> 29 #include <boost/python/errors.hpp> 30 #include <indexing_suite/int_slice_helper.hpp> 31 #include <indexing_suite/slice.hpp> 32 #include <boost/mpl/if.hpp> 33 #include <boost/limits.hpp> 40 namespace boost {
namespace python {
namespace indexing {
41 template<
typename ContainerTraits,
typename Ovr = detail::no_overr
ide>
49 typedef ContainerTraits container_traits;
52 typedef typename ContainerTraits::container container;
53 typedef typename ContainerTraits::iterator iterator;
54 typedef typename ContainerTraits::reference reference;
55 typedef typename ContainerTraits::size_type size_type;
56 typedef typename ContainerTraits::value_type value_type;
57 typedef typename ContainerTraits::value_param value_param;
58 typedef typename ContainerTraits::index_param index_param;
59 typedef typename ContainerTraits::key_param key_param;
69 BOOST_STATIC_CONSTANT(
71 supported_methods = ContainerTraits::supported_methods);
73 static size_type size (container &);
74 static iterator find (container &, key_param);
75 static size_type get_index (container &, key_param);
76 static size_type count (container &, key_param);
77 static bool contains (container &, key_param);
78 static void reverse (container &);
79 static reference
get (container &, index_param);
80 static void assign (container &, index_param, value_param);
81 static void insert (container &, index_param, value_param);
82 static void erase_one (container &, index_param);
83 static void erase_range(container &, index_param, index_param);
84 static void push_back (container &, value_param);
85 static void sort (container &);
88 static iterator begin (container &c) {
return c.begin(); }
89 static iterator end (container &c) {
return c.end(); }
94 static slice_helper make_slice_helper (container &c,
slice const &);
97 template<
typename PythonClass,
typename Policy>
98 static void visit_container_class(
99 PythonClass &pyClass, Policy
const &policy)
101 container_traits::visit_container_class (pyClass, policy);
104 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) 111 static size_type bounds_check(
112 container &, index_param,
char const *msg,
113 bool one_past =
false,
114 bool truncate =
false);
127 template<
typename ContainerTraits,
typename Ovr = detail::no_overr
ide>
131 BOOST_DEDUCED_TYPENAME detail::maybe_override
132 <assoc_algorithms<ContainerTraits, Ovr>, Ovr>
141 typedef typename Parent::iterator iterator;
142 typedef typename Parent::size_type size_type;
143 typedef typename Parent::container container;
144 typedef typename Parent::reference reference;
145 typedef typename Parent::key_param key_param;
146 typedef typename Parent::value_param value_param;
147 typedef typename Parent::index_param index_param;
149 static reference
get (container &, index_param);
152 static void erase_one (container &, key_param);
153 static iterator find (container &, key_param);
154 static size_type count (container &, key_param);
155 static bool contains (container &, key_param);
158 template<
typename PythonClass,
typename Policy>
159 static void visit_container_class( PythonClass &pyClass, Policy
const &policy)
161 ContainerTraits::visit_container_class (pyClass, policy);
166 static iterator find_or_throw (container &, index_param);
173 template<
typename ContainerTraits,
typename Ovr>
174 BOOST_DEDUCED_TYPENAME default_algorithms<ContainerTraits, Ovr>::size_type
184 template<
typename ContainerTraits,
typename Ovr>
185 BOOST_DEDUCED_TYPENAME default_algorithms<ContainerTraits, Ovr>::size_type
193 size_type bound = most_derived::size(c) + (one_past ? 1 : 0);
207 if ((result >= bound) && (bound > 0))
216 if (size_type(-ix) > bound)
218 throw std::out_of_range (msg);
231 throw std::out_of_range (msg);
241 template<
typename ContainerTraits,
typename Ovr>
242 BOOST_DEDUCED_TYPENAME default_algorithms<ContainerTraits, Ovr>::iterator
244 container &c, key_param key)
246 typedef typename container_traits::value_traits_type vtraits;
247 typedef typename vtraits::equal_to comparison;
250 most_derived::begin(c),
251 most_derived::end(c),
252 std::bind1st (comparison(), key));
259 template<
typename ContainerTraits,
typename Ovr>
260 BOOST_DEDUCED_TYPENAME default_algorithms<ContainerTraits, Ovr>::size_type
262 container &c, key_param key)
264 iterator found (most_derived::find (c, key));
266 if (found == most_derived::end(c))
269 PyExc_ValueError,
"get_index: element not found");
271 boost::python::throw_error_already_set ();
274 iterator start (most_derived::begin (c));
275 return std::distance (start, found);
282 template<
typename ContainerTraits,
typename Ovr>
283 BOOST_DEDUCED_TYPENAME default_algorithms<ContainerTraits, Ovr>::size_type
285 container &c, key_param key)
287 typedef typename container_traits::value_traits_type vtraits;
288 typedef typename vtraits::equal_to comparison;
290 return std::count_if(
291 most_derived::begin(c),
292 most_derived::end(c),
293 std::bind1st (comparison(), key));
300 template<
typename ContainerTraits,
typename Ovr>
303 container &c, key_param key)
305 return most_derived::find (c, key) != most_derived::end(c);
312 template<
typename ContainerTraits,
typename Ovr>
313 BOOST_DEDUCED_TYPENAME default_algorithms<ContainerTraits, Ovr>::reference
315 container &c, index_param ix)
317 return c[most_derived::bounds_check (c, ix,
"get")];
324 template<
typename ContainerTraits,
typename Ovr>
327 container &c, index_param ix, value_param val)
329 c[most_derived::bounds_check (c, ix,
"assign")] = val;
336 template<
typename ContainerTraits,
typename Ovr>
339 container &c, value_param v)
348 template<
typename ContainerTraits,
typename Ovr>
351 container &c, index_param i, value_param v)
353 iterator insert_pos (most_derived::begin(c));
357 insert_pos, most_derived::bounds_check (c, i,
"insert",
true,
true));
359 c.insert (insert_pos, v);
366 template<
typename ContainerTraits,
typename Ovr>
369 container &c, index_param from, index_param to)
371 iterator start (most_derived::begin(c));
372 iterator finish (most_derived::begin(c));
376 (start, most_derived::bounds_check (c, from,
"erase_range (from)"));
380 (finish, most_derived::bounds_check (c, to,
"erase_range (to)",
true));
382 c.erase (start, finish);
389 template<
typename ContainerTraits,
typename Ovr>
392 container &c, index_param ix)
394 iterator iter (most_derived::begin(c));
395 std::advance (iter, most_derived::bounds_check (c, ix,
"erase_one"));
403 template<
typename ContainerTraits,
typename Ovr>
406 std::reverse (most_derived::begin(c), most_derived::end(c));
413 template<
typename ContainerTraits,
typename Ovr>
416 typedef typename container_traits::value_traits_type vtraits;
417 typedef typename vtraits::less comparison;
418 std::sort (most_derived::begin(c), most_derived::end(c), comparison());
425 template<
typename ContainerTraits,
typename Ovr>
437 template<
typename ContainerTraits,
typename Ovr>
438 BOOST_DEDUCED_TYPENAME assoc_algorithms<ContainerTraits, Ovr>::reference
441 return *most_derived::find_or_throw (c, ix);
448 template<
typename ContainerTraits,
typename Ovr>
451 container &c, key_param key)
453 if (c.erase (key) == 0)
456 PyExc_ValueError,
"Container does not hold value to be erased");
458 boost::python::throw_error_already_set ();
466 template<
typename ContainerTraits,
typename Ovr>
467 BOOST_DEDUCED_TYPENAME assoc_algorithms<ContainerTraits, Ovr>::iterator
469 ::find (container &c, key_param key)
478 template<
typename ContainerTraits,
typename Ovr>
481 container &c, key_param key)
483 return most_derived::find (c, key) != most_derived::end(c);
491 template<
typename ContainerTraits,
typename Ovr>
492 BOOST_DEDUCED_TYPENAME assoc_algorithms<ContainerTraits, Ovr>::iterator
494 container &c, index_param ix)
496 iterator iter = most_derived::find (c, ix);
498 if (iter == most_derived::end(c))
501 PyExc_ValueError,
"associative container: key not found");
503 boost::python::throw_error_already_set ();
513 template<
typename ContainerTraits,
typename Ovr>
514 BOOST_DEDUCED_TYPENAME assoc_algorithms<ContainerTraits, Ovr>::size_type
516 container &c, key_param key)
518 return c.count (key);
533 # if defined(BOOST_MPL_MSVC_ETI_BUG)
547 template<
class Container>
553 # if !defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) 558 template<
class Container>
566 #endif // BOOST_PYTHON_INDEXING_ALGORITHMS_HPP Definition: algorithms.hpp:42
Definition: algorithms.hpp:128
Definition: python_CEGUI.h:11
Definition: algorithms.hpp:548
Definition: algorithms.hpp:532
Definition: suite_utils.hpp:97
Definition: int_slice_helper.hpp:27