• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

max.hh

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
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   // Forward declaration.
00044   namespace accu {
00045     namespace stat {
00046       template <typename T> struct max;
00047     }
00048   }
00049 
00050 
00051   // Traits.
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   } // end of namespace mln::trait
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       } // end of namespace mln::accu::meta::stat
00088 
00089     } // end of namespace mln::accu::meta
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     } // end of namespace mln::accu::stat
00204 
00205   } // end of namespace mln::accu
00206 
00207 } // end of namespace mln
00208 
00209 
00210 #endif // ! MLN_ACCU_STAT_MAX_HH

Generated on Tue Oct 4 2011 15:24:03 for Milena (Olena) by  doxygen 1.7.1