sweep.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2015, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  4. // Licensed under the Boost Software License version 1.0.
  5. // http://www.boost.org/users/license.html
  6. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_SWEEP_HPP
  7. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_SWEEP_HPP
  8. #include <boost/core/ignore_unused.hpp>
  9. namespace boost { namespace geometry
  10. {
  11. #ifndef DOXYGEN_NO_DETAIL
  12. namespace detail { namespace sweep
  13. {
  14. struct no_interrupt_policy
  15. {
  16. static bool const enabled = false;
  17. template <typename Event>
  18. static inline bool apply(Event const&)
  19. {
  20. return false;
  21. }
  22. };
  23. }} // namespace detail::sweep
  24. #endif // DOXYGEN_NO_DETAIL
  25. template
  26. <
  27. typename Range,
  28. typename PriorityQueue,
  29. typename InitializationVisitor,
  30. typename EventVisitor,
  31. typename InterruptPolicy
  32. >
  33. inline void sweep(Range const& range, PriorityQueue& queue,
  34. InitializationVisitor& initialization_visitor,
  35. EventVisitor& event_visitor,
  36. InterruptPolicy const& interrupt_policy)
  37. {
  38. typedef typename PriorityQueue::value_type event_type;
  39. initialization_visitor.apply(range, queue, event_visitor);
  40. while (! queue.empty())
  41. {
  42. event_type event = queue.top();
  43. queue.pop();
  44. event_visitor.apply(event, queue);
  45. if (interrupt_policy.enabled && interrupt_policy.apply(event))
  46. {
  47. break;
  48. }
  49. }
  50. boost::ignore_unused(interrupt_policy);
  51. }
  52. template
  53. <
  54. typename Range,
  55. typename PriorityQueue,
  56. typename InitializationVisitor,
  57. typename EventVisitor
  58. >
  59. inline void sweep(Range const& range, PriorityQueue& queue,
  60. InitializationVisitor& initialization_visitor,
  61. EventVisitor& event_visitor)
  62. {
  63. sweep(range, queue, initialization_visitor, event_visitor,
  64. detail::sweep::no_interrupt_policy());
  65. }
  66. }} // namespace boost::geometry
  67. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_SWEEP_HPP