00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef MLN_CORE_BOX_RUNSTART_PITER_HH
00027 # define MLN_CORE_BOX_RUNSTART_PITER_HH
00028
00032
00033 # include <mln/core/internal/site_iterator_base.hh>
00034 # include <mln/core/site_set/box.hh>
00035
00036
00037 #define mln_box_runstart_piter(I) typename mln::box_runstart_piter<mln_psite(I)>
00038 #define mln_box_runstart_piter_(I) mln::box_runstart_piter<mln_psite_(I)>
00039
00040
00041 namespace mln
00042 {
00043
00048 template <typename P>
00049 class box_runstart_piter :
00050 public internal::site_set_iterator_base< box<P>,
00051 box_runstart_piter<P> >
00052 {
00053 typedef box_runstart_piter<P> self_;
00054 typedef internal::site_set_iterator_base< box<P>, self_ > super_;
00055 public:
00056
00057
00058 enum { dim = super_::dim };
00059
00064 box_runstart_piter(const box<P>& b);
00065
00067 void init_(const box<P>& b);
00068
00069 box_runstart_piter();
00070
00072 bool is_valid_() const;
00073
00075 void invalidate_();
00076
00078 void start_();
00079
00081 void next_();
00082
00084 unsigned run_length() const;
00085
00086 private:
00087 using super_::p_;
00088 using super_::s_;
00089 };
00090
00091
00092 # ifndef MLN_INCLUDE_ONLY
00093
00094
00095
00096
00097 template <typename P>
00098 inline
00099 box_runstart_piter<P>::box_runstart_piter()
00100 {
00101 }
00102
00103 template <typename P>
00104 inline
00105 box_runstart_piter<P>::box_runstart_piter(const box<P>& b)
00106 {
00107 init_(b);
00108 }
00109
00110 template <typename P>
00111 inline
00112 void
00113 box_runstart_piter<P>::init_(const box<P>& b)
00114 {
00115 this->change_target(b);
00116 }
00117
00118
00119 template <typename P>
00120 inline
00121 bool
00122 box_runstart_piter<P>::is_valid_() const
00123 {
00124 return p_[0] != static_cast<mln_coord(P)>(s_->pmax()[0] + 1);
00125 }
00126
00127 template <typename P>
00128 inline
00129 void
00130 box_runstart_piter<P>::invalidate_()
00131 {
00132 p_[0] = static_cast<mln_coord(P)>(s_->pmax()[0] + 1);
00133 }
00134
00135 template <typename P>
00136 inline
00137 void
00138 box_runstart_piter<P>::start_()
00139 {
00140 p_ = s_->pmin();
00141 }
00142
00143 template <typename P>
00144 inline
00145 void
00146 box_runstart_piter<P>::next_()
00147 {
00148
00149 for (int c = dim - 2; c >= 0; --c)
00150 {
00151 if (p_[c] != s_->pmax()[c])
00152 {
00153 ++p_[c];
00154 break;
00155 }
00156 else
00157 p_[c] = s_->pmin()[c];
00158 }
00159
00160 if (p_ == s_->pmin())
00161 invalidate_();
00162 }
00163
00164 template <typename P>
00165 inline
00166 unsigned
00167 box_runstart_piter<P>::run_length() const
00168 {
00169 return s_->len(dim - 1);
00170 }
00171
00172
00173 # endif // ! MLN_INCLUDE_ONLY
00174
00175 }
00176
00177
00178 #endif // ! MLN_CORE_BOX_RUNSTART_PITER_HH