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_STAT_MIN_HH
00027 # define MLN_ACCU_STAT_MIN_HH
00028 
00032 
00033 # include <mln/accu/internal/base.hh>
00034 # include <mln/core/concept/meta_accumulator.hh>
00035 # include <mln/trait/value_.hh>
00036 # include <mln/util/pix.hh>
00037 
00038 
00039 namespace mln
00040 {
00041 
00042 
00043   
00044   namespace accu {
00045     namespace stat {
00046       template <typename T> struct min;
00047     }
00048   }
00049 
00050 
00051   
00052 
00053   namespace trait
00054   {
00055 
00056     template <typename T>
00057     struct accumulator_< accu::stat::min<T> >
00058     {
00059       typedef accumulator::has_untake::no     has_untake;
00060       typedef accumulator::has_set_value::yes has_set_value;
00061       typedef accumulator::has_stop::no       has_stop;
00062       typedef accumulator::when_pix::use_v    when_pix;
00063     };
00064 
00065   } 
00066 
00067 
00068   namespace accu
00069   {
00070 
00071     namespace meta
00072     {
00073 
00074       namespace stat
00075       {
00077 
00078         struct min : public Meta_Accumulator< min >
00079         {
00080           template <typename T>
00081           struct with
00082           {
00083             typedef accu::stat::min<T> ret;
00084           };
00085         };
00086 
00087       } 
00088 
00089     } 
00090 
00091 
00092     namespace stat
00093     {
00094 
00096 
00101       template <typename T>
00102       struct min : public mln::accu::internal::base< const T&, min<T> >
00103       {
00104         typedef T argument;
00105 
00106         min();
00107 
00110         void init();
00111         void take_as_init_(const argument& t);
00112         void take(const argument& t);
00113         void take(const min<T>& other);
00115 
00117         void set_value(const T& t);
00118 
00120         const T& to_result() const;
00121 
00124         bool is_valid() const;
00125 
00126       protected:
00127 
00128         T t_;
00129       };
00130 
00131 
00132       template <typename I> struct min< util::pix<I> >;
00133 
00134 
00135 # ifndef MLN_INCLUDE_ONLY
00136 
00137       template <typename T>
00138       inline
00139       min<T>::min()
00140       {
00141         init();
00142       }
00143 
00144       template <typename T>
00145       inline
00146       void
00147       min<T>::init()
00148       {
00149         t_ = mln_max(T);
00150       }
00151 
00152       template <typename T>
00153       inline
00154       void min<T>::take_as_init_(const argument& t)
00155       {
00156         t_ = t;
00157       }
00158 
00159       template <typename T>
00160       inline
00161       void min<T>::take(const argument& t)
00162       {
00163         if (t < t_)
00164           t_ = t;
00165       }
00166 
00167       template <typename T>
00168       inline
00169       void
00170       min<T>::take(const min<T>& other)
00171       {
00172         if (other.t_ < t_)
00173           t_ = other.t_;
00174       }
00175 
00176       template <typename T>
00177       inline
00178       void
00179       min<T>::set_value(const T& t)
00180       {
00181         t_ = t;
00182       }
00183 
00184       template <typename T>
00185       inline
00186       const T&
00187       min<T>::to_result() const
00188       {
00189         return t_;
00190       }
00191 
00192       template <typename T>
00193       inline
00194       bool
00195       min<T>::is_valid() const
00196       {
00197         return true;
00198       }
00199 
00200 # endif // ! MLN_INCLUDE_ONLY
00201 
00202     } 
00203 
00204   } 
00205 
00206 } 
00207 
00208 
00209 #endif // ! MLN_ACCU_STAT_MIN_HH