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_VALUE_VITER_HH
00027 # define MLN_VALUE_VITER_HH
00028 
00036 # include <mln/core/concept/value_iterator.hh>
00037 # include <mln/core/concept/value_set.hh>
00038 
00039 
00040 namespace mln
00041 {
00042 
00043   namespace value
00044   {
00045 
00046 
00051     template <typename S>
00052     struct fwd_viter_ : public Value_Iterator< fwd_viter_<S> >
00053     {
00055       typedef mln_value(S) value;
00056 
00058       fwd_viter_();
00059 
00061       fwd_viter_(const Value_Set<S>& s);
00062 
00063       void change_target(const S& s);
00064 
00066       bool is_valid() const;
00067 
00069       void invalidate();
00070 
00072       void start();
00073 
00075       void next_();
00076 
00078       operator mln_value(S) () const;
00079 
00081       unsigned index_() const;
00082 
00083     private:
00084 
00085       const S* s_;
00086       unsigned i_;
00087     };
00088 
00089 
00090 
00091 
00096     template <typename S>
00097     struct bkd_viter_ : public Value_Iterator< bkd_viter_<S> >
00098     {
00100       typedef mln_value(S) value;
00101 
00103       bkd_viter_();
00104 
00106       bkd_viter_(const Value_Set<S>& s);
00107 
00108       void change_target(const S& s);
00109 
00111       bool is_valid() const;
00112 
00114       void invalidate();
00115 
00117       void start();
00118 
00120       void next_();
00121 
00123       operator mln_value(S) () const;
00124 
00126       unsigned index_() const;
00127 
00128     private:
00129 
00130       const S* s_;
00131       unsigned i_;
00132     };
00133 
00134 
00135 
00136 # ifndef MLN_INCLUDE_ONLY
00137 
00138 
00139     
00140 
00141     template <typename S>
00142     inline
00143     fwd_viter_<S>::fwd_viter_()
00144       : s_(0)
00145     {
00146     }
00147 
00148     template <typename S>
00149     inline
00150     fwd_viter_<S>::fwd_viter_(const Value_Set<S>& s)
00151     {
00152       change_target(exact(s));
00153     }
00154 
00155     template <typename S>
00156     inline
00157     void
00158     fwd_viter_<S>::change_target(const S& s)
00159     {
00160       s_ = &s;
00161       invalidate();
00162     }
00163 
00164     template <typename S>
00165     inline
00166     bool
00167     fwd_viter_<S>::is_valid() const
00168     {
00169       return s_ != 0 && i_ < s_->nvalues();
00170     }
00171 
00172     template <typename S>
00173     inline
00174     void
00175     fwd_viter_<S>::invalidate()
00176     {
00177       i_ = s_->nvalues();
00178     }
00179 
00180     template <typename S>
00181     inline
00182     void
00183     fwd_viter_<S>::start()
00184     {
00185       i_ = 0;
00186     }
00187 
00188     template <typename S>
00189     inline
00190     void
00191     fwd_viter_<S>::next_()
00192     {
00193       ++i_;
00194     }
00195 
00196     template <typename S>
00197     inline
00198     fwd_viter_<S>::operator mln_value(S) () const
00199     {
00200       mln_precondition(is_valid());
00201       return (*s_)[i_];
00202     }
00203 
00204     template <typename S>
00205     inline
00206     unsigned
00207     fwd_viter_<S>::index_() const
00208     {
00209       return i_;
00210     }
00211 
00212 
00213     
00214 
00215     template <typename S>
00216     inline
00217     bkd_viter_<S>::bkd_viter_()
00218       : s_(0)
00219     {
00220     }
00221 
00222     template <typename S>
00223     inline
00224     bkd_viter_<S>::bkd_viter_(const Value_Set<S>& s)
00225     {
00226       change_target(exact(s));
00227     }
00228 
00229     template <typename S>
00230     inline
00231     void
00232     bkd_viter_<S>::change_target(const S& s)
00233     {
00234       s_ = &s;
00235       invalidate();
00236     }
00237 
00238     template <typename S>
00239     inline
00240     bool
00241     bkd_viter_<S>::is_valid() const
00242     {
00243       return s_ != 0 && i_ != s_->nvalues();
00244     }
00245 
00246     template <typename S>
00247     inline
00248     void
00249     bkd_viter_<S>::invalidate()
00250     {
00251       i_ = s_->nvalues();
00252     }
00253 
00254     template <typename S>
00255     inline
00256     void
00257     bkd_viter_<S>::start()
00258     {
00259       i_ = s_->nvalues() - 1;
00260     }
00261 
00262     template <typename S>
00263     inline
00264     void
00265     bkd_viter_<S>::next_()
00266     {
00267       if (i_ == 0)
00268         {
00269           invalidate();
00270           return;
00271         }
00272       --i_;
00273     }
00274 
00275     template <typename S>
00276     inline
00277     bkd_viter_<S>::operator mln_value(S) () const
00278     {
00279       mln_precondition(is_valid());
00280       return (*s_)[i_];
00281     }
00282 
00283     template <typename S>
00284     inline
00285     unsigned
00286     bkd_viter_<S>::index_() const
00287     {
00288       return i_;
00289     }
00290 
00291 # endif // ! MLN_INCLUDE_ONLY
00292 
00293   } 
00294 
00295 } 
00296 
00297 
00298 #endif // ! MLN_VALUE_VITER_HH