iterator_points_to_compact.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. Copyright 2008 Intel Corporation
  3. Use, modification and distribution are subject to the Boost Software License,
  4. Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. */
  7. #ifndef BOOST_POLYGON_ITERATOR_POINTS_TO_COMPACT_HPP
  8. #define BOOST_POLYGON_ITERATOR_POINTS_TO_COMPACT_HPP
  9. namespace boost { namespace polygon{
  10. template <typename iT, typename point_type>
  11. class iterator_points_to_compact {
  12. private:
  13. iT iter_, iterEnd_;
  14. orientation_2d orient_;
  15. mutable typename point_traits<point_type>::coordinate_type coord_;
  16. public:
  17. typedef typename point_traits<point_type>::coordinate_type coordinate_type;
  18. typedef std::forward_iterator_tag iterator_category;
  19. typedef coordinate_type value_type;
  20. typedef std::ptrdiff_t difference_type;
  21. typedef const coordinate_type* pointer; //immutable
  22. typedef const coordinate_type& reference; //immutable
  23. inline iterator_points_to_compact() : iter_(), iterEnd_(), orient_(), coord_() {}
  24. inline iterator_points_to_compact(iT iter, iT iterEnd) :
  25. iter_(iter), iterEnd_(iterEnd), orient_(HORIZONTAL), coord_() {}
  26. inline iterator_points_to_compact(const iterator_points_to_compact& that) :
  27. iter_(that.iter_), iterEnd_(that.iterEnd_), orient_(that.orient_), coord_(that.coord_) {}
  28. //use bitwise copy and assign provided by the compiler
  29. inline iterator_points_to_compact& operator++() {
  30. //iT tmp = iter_;
  31. ++iter_;
  32. //iT tmp2 = iter_;
  33. orient_.turn_90();
  34. //while(tmp2 != iterEnd_ && get(*tmp2, orient_) == get(*tmp, orient_)) {
  35. // iter_ = tmp2;
  36. // ++tmp2;
  37. //}
  38. return *this;
  39. }
  40. inline const iterator_points_to_compact operator++(int) {
  41. iT tmp(*this);
  42. ++(*this);
  43. return tmp;
  44. }
  45. inline bool operator==(const iterator_points_to_compact& that) const {
  46. return (iter_ == that.iter_);
  47. }
  48. inline bool operator!=(const iterator_points_to_compact& that) const {
  49. return (iter_ != that.iter_);
  50. }
  51. inline reference operator*() const { coord_ = get(*iter_, orient_);
  52. return coord_;
  53. }
  54. };
  55. }
  56. }
  57. #endif