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_ACCU_MAX_SITE_HH
00027 # define MLN_ACCU_MAX_SITE_HH
00028 
00035 
00036 # include <mln/core/concept/meta_accumulator.hh>
00037 # include <mln/accu/internal/base.hh>
00038 # include <mln/util/pix.hh>
00039 
00040 namespace mln
00041 {
00042 
00043   namespace accu
00044   {
00045 
00046 
00051     
00052     template <typename I>
00053     struct max_site : public mln::accu::internal::base< mln_psite(I), max_site<I> >
00054     {
00055       typedef mln::util::pix<I> argument;
00056       typedef mln_psite(I) result;
00057 
00058       max_site();
00059 
00062       void init();
00063       void take(const argument& t);
00064       void take(const max_site<I>& other);
00066 
00068       mln_psite(I) to_result() const;
00069       operator mln_psite(I) () const;
00070 
00072       mln_value(I) value_() const;
00073 
00076       bool is_valid() const;
00077 
00078     protected:
00079       bool is_valid_;
00080       mln_psite(I) max_p_;
00081       mln_value(I) max_v_;
00082     };
00083 
00084 
00085 
00086     namespace meta
00087     {
00088 
00090       struct max_site : public Meta_Accumulator< max_site >
00091       {
00092         template <typename I>
00093         struct with
00094         {
00095           typedef accu::max_site<I> ret;
00096         };
00097       };
00098 
00099     } 
00100 
00101 
00102 # ifndef MLN_INCLUDE_ONLY
00103 
00104     template <typename I>
00105     inline
00106     max_site<I>::max_site()
00107     {
00108       init();
00109     }
00110 
00111     template <typename I>
00112     inline
00113     void
00114     max_site<I>::init()
00115     {
00116       is_valid_ = false;
00117       max_v_ = mln_min(mln_value(I));
00118     }
00119 
00120     template <typename I>
00121     inline
00122     void max_site<I>::take(const argument& t)
00123     {
00124       if (t.v() > max_v_)
00125       {
00126         max_v_ = t.v();
00127         max_p_ = t.p();
00128         is_valid_ = true;
00129       }
00130     }
00131 
00132     template <typename I>
00133     inline
00134     void
00135     max_site<I>::take(const max_site<I>& other)
00136     {
00137       mln_precondition(other.is_valid());
00138 
00139       if (other.value_() > max_v_)
00140       {
00141         max_v_ = other.value_();
00142         max_p_ = other.to_result();
00143         is_valid_ = true;
00144       }
00145     }
00146 
00147     template <typename I>
00148     inline
00149     mln_psite(I)
00150     max_site<I>::to_result() const
00151     {
00152       mln_precondition(is_valid());
00153       return max_p_;
00154     }
00155 
00156     template <typename I>
00157     inline
00158     max_site<I>::operator mln_psite(I)() const
00159     {
00160       return to_result();
00161     }
00162 
00163     template <typename I>
00164     inline
00165     mln_value(I)
00166     max_site<I>::value_() const
00167     {
00168       return max_v_;
00169     }
00170 
00171     template <typename I>
00172     inline
00173     bool
00174     max_site<I>::is_valid() const
00175     {
00176       return is_valid_;
00177     }
00178 
00179 # endif // ! MLN_INCLUDE_ONLY
00180 
00181   } 
00182 
00183 } 
00184 
00185 
00186 #endif // ! MLN_ACCU_MAX_SITE_HH