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_MAX_HH
00027 # define MLN_ACCU_STAT_MAX_HH
00028 
00032 
00033 # include <mln/core/concept/meta_accumulator.hh>
00034 # include <mln/accu/internal/base.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 max;
00047     }
00048   }
00049 
00050 
00051   
00052 
00053   namespace trait
00054   {
00055 
00056     template <typename T>
00057     struct accumulator_< accu::stat::max<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       {
00076 
00078         struct max : public Meta_Accumulator< max >
00079         {
00080           template <typename T>
00081           struct with
00082           {
00083             typedef accu::stat::max<T> ret;
00084           };
00085         };
00086 
00087       } 
00088 
00089     } 
00090 
00091 
00092     namespace stat
00093     {
00094 
00100       template <typename T>
00101       struct max : public mln::accu::internal::base< const T& , max<T> >
00102       {
00103         typedef T argument;
00104 
00105         max();
00106 
00109         void init();
00110         void take_as_init_(const argument& t);
00111         void take(const argument& t);
00112         void take(const max<T>& other);
00114 
00116         void set_value(const T& t);
00117 
00119         const T& to_result() const;
00120 
00123         bool is_valid() const;
00124 
00125       protected:
00126 
00127         T t_;
00128       };
00129 
00130 
00131       template <typename I> struct max< util::pix<I> >;
00132 
00133 
00134 # ifndef MLN_INCLUDE_ONLY
00135 
00136       template <typename T>
00137       inline
00138       max<T>::max()
00139       {
00140         init();
00141       }
00142 
00143       template <typename T>
00144       inline
00145       void
00146       max<T>::init()
00147       {
00148         t_ = mln_min(T);
00149       }
00150 
00151       template <typename T>
00152       inline
00153       void
00154       max<T>::take_as_init_(const argument& t)
00155       {
00156         t_ = t;
00157       }
00158 
00159       template <typename T>
00160       inline
00161       void
00162       max<T>::take(const argument& t)
00163       {
00164         if (t > t_)
00165           t_ = t;
00166       }
00167 
00168       template <typename T>
00169       inline
00170       void
00171       max<T>::take(const max<T>& other)
00172       {
00173         if (other.t_ > t_)
00174           t_ = other.t_;
00175       }
00176 
00177       template <typename T>
00178       inline
00179       void
00180       max<T>::set_value(const T& t)
00181       {
00182         t_ = t;
00183       }
00184 
00185       template <typename T>
00186       inline
00187       const T&
00188       max<T>::to_result() const
00189       {
00190         return t_;
00191       }
00192 
00193       template <typename T>
00194       inline
00195       bool
00196       max<T>::is_valid() const
00197       {
00198         return true;
00199       }
00200 
00201 # endif // ! MLN_INCLUDE_ONLY
00202 
00203     } 
00204 
00205   } 
00206 
00207 } 
00208 
00209 
00210 #endif // ! MLN_ACCU_STAT_MAX_HH