1 /* 2 Copyright 2008 Intel Corporation 3 4 Use, modification and distribution are subject to the Boost Software License, 5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 http://www.boost.org/LICENSE_1_0.txt). 7 */ 8 #ifndef BOOST_POLYGON_ITERATOR_COMPACT_TO_POINTS_HPP 9 #define BOOST_POLYGON_ITERATOR_COMPACT_TO_POINTS_HPP 10 namespace boost { namespace polygon{ 11 template <typename iterator_type, typename point_type> 12 class iterator_compact_to_points { 13 private: 14 iterator_type iter_; 15 iterator_type iter_end_; 16 point_type pt_; 17 typename point_traits<point_type>::coordinate_type firstX_; 18 orientation_2d orient_; 19 public: 20 typedef std::forward_iterator_tag iterator_category; 21 typedef point_type value_type; 22 typedef std::ptrdiff_t difference_type; 23 typedef const point_type* pointer; //immutable 24 typedef const point_type& reference; //immutable 25 iterator_compact_to_points()26 inline iterator_compact_to_points() : iter_(), iter_end_(), pt_(), firstX_(), orient_() {} iterator_compact_to_points(iterator_type iter,iterator_type iter_end)27 inline iterator_compact_to_points(iterator_type iter, iterator_type iter_end) : 28 iter_(iter), iter_end_(iter_end), pt_(), firstX_(), orient_(HORIZONTAL) { 29 if(iter_ != iter_end_) { 30 firstX_ = *iter_; 31 x(pt_, firstX_); 32 ++iter_; 33 if(iter_ != iter_end_) { 34 y(pt_, *iter_); 35 } 36 } 37 } 38 //use bitwise copy and assign provided by the compiler operator ++()39 inline iterator_compact_to_points& operator++() { 40 iterator_type prev_iter = iter_; 41 ++iter_; 42 if(iter_ == iter_end_) { 43 if(x(pt_) != firstX_) { 44 iter_ = prev_iter; 45 x(pt_, firstX_); 46 } 47 } else { 48 set(pt_, orient_, *iter_); 49 orient_.turn_90(); 50 } 51 return *this; 52 } operator ++(int)53 inline const iterator_compact_to_points operator++(int) { 54 iterator_compact_to_points tmp(*this); 55 ++(*this); 56 return tmp; 57 } operator ==(const iterator_compact_to_points & that) const58 inline bool operator==(const iterator_compact_to_points& that) const { 59 if (iter_ == iter_end_) { 60 return iter_ == that.iter_; 61 } 62 return (iter_ == that.iter_) && (x(pt_) == x(that.pt_)); 63 } operator !=(const iterator_compact_to_points & that) const64 inline bool operator!=(const iterator_compact_to_points& that) const { 65 if (iter_ == iter_end_) { 66 return iter_ != that.iter_; 67 } 68 return (iter_ != that.iter_) || (x(pt_) != x(that.pt_)); 69 } operator *() const70 inline reference operator*() const { return pt_; } 71 }; 72 } 73 } 74 #endif 75