iterator_compact_to_points.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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_COMPACT_TO_POINTS_HPP
  8. #define BOOST_POLYGON_ITERATOR_COMPACT_TO_POINTS_HPP
  9. namespace boost { namespace polygon{
  10. template <typename iterator_type, typename point_type>
  11. class iterator_compact_to_points {
  12. private:
  13. iterator_type iter_;
  14. iterator_type iter_end_;
  15. point_type pt_;
  16. typename point_traits<point_type>::coordinate_type firstX_;
  17. orientation_2d orient_;
  18. public:
  19. typedef std::forward_iterator_tag iterator_category;
  20. typedef point_type value_type;
  21. typedef std::ptrdiff_t difference_type;
  22. typedef const point_type* pointer; //immutable
  23. typedef const point_type& reference; //immutable
  24. inline iterator_compact_to_points() : iter_(), iter_end_(), pt_(), firstX_(), orient_() {}
  25. inline iterator_compact_to_points(iterator_type iter, iterator_type iter_end) :
  26. iter_(iter), iter_end_(iter_end), pt_(), firstX_(), orient_(HORIZONTAL) {
  27. if(iter_ != iter_end_) {
  28. firstX_ = *iter_;
  29. x(pt_, firstX_);
  30. ++iter_;
  31. if(iter_ != iter_end_) {
  32. y(pt_, *iter_);
  33. }
  34. }
  35. }
  36. //use bitwise copy and assign provided by the compiler
  37. inline iterator_compact_to_points& operator++() {
  38. iterator_type prev_iter = iter_;
  39. ++iter_;
  40. if(iter_ == iter_end_) {
  41. if(x(pt_) != firstX_) {
  42. iter_ = prev_iter;
  43. x(pt_, firstX_);
  44. }
  45. } else {
  46. set(pt_, orient_, *iter_);
  47. orient_.turn_90();
  48. }
  49. return *this;
  50. }
  51. inline const iterator_compact_to_points operator++(int) {
  52. iterator_compact_to_points tmp(*this);
  53. ++(*this);
  54. return tmp;
  55. }
  56. inline bool operator==(const iterator_compact_to_points& that) const {
  57. if (iter_ == iter_end_) {
  58. return iter_ == that.iter_;
  59. }
  60. return (iter_ == that.iter_) && (x(pt_) == x(that.pt_));
  61. }
  62. inline bool operator!=(const iterator_compact_to_points& that) const {
  63. if (iter_ == iter_end_) {
  64. return iter_ != that.iter_;
  65. }
  66. return (iter_ != that.iter_) || (x(pt_) != x(that.pt_));
  67. }
  68. inline reference operator*() const { return pt_; }
  69. };
  70. }
  71. }
  72. #endif