• 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   namespace accu
00043   {
00044 
00045     namespace stat
00046     {
00047 
00048       // Forward declaration.
00049       template <typename T>
00050       struct max;
00051 
00052     } // end of namespace mln::accu::stat
00053 
00054 
00055     namespace meta
00056     {
00057 
00058       namespace stat
00059       {
00060 
00062         struct max : public Meta_Accumulator< max >
00063         {
00064           template <typename T>
00065           struct with
00066           {
00067             typedef accu::stat::max<T> ret;
00068           };
00069         };
00070 
00071       } // end of namespace mln::accu::meta::stat
00072 
00073     } // end of namespace mln::accu::meta
00074 
00075 
00076     namespace stat
00077     {
00078 
00084       template <typename T>
00085       struct max : public mln::accu::internal::base< const T& , max<T> >
00086       {
00087         typedef T argument;
00088 
00089         max();
00090 
00093         void init();
00094         void take_as_init_(const argument& t);
00095         void take(const argument& t);
00096         void take(const max<T>& other);
00098 
00100         const T& to_result() const;
00101 
00104         bool is_valid() const;
00105 
00106       protected:
00107 
00108         T t_;
00109       };
00110 
00111 
00112       template <typename I> struct max< util::pix<I> >;
00113 
00114 # ifndef MLN_INCLUDE_ONLY
00115 
00116       template <typename T>
00117       inline
00118       max<T>::max()
00119       {
00120         init();
00121       }
00122 
00123       template <typename T>
00124       inline
00125       void
00126       max<T>::init()
00127       {
00128         t_ = mln_min(T);
00129       }
00130 
00131       template <typename T>
00132       inline
00133       void
00134       max<T>::take_as_init_(const argument& t)
00135       {
00136         t_ = t;
00137       }
00138 
00139       template <typename T>
00140       inline
00141       void
00142       max<T>::take(const argument& t)
00143       {
00144         if (t > t_)
00145           t_ = t;
00146       }
00147 
00148       template <typename T>
00149       inline
00150       void
00151       max<T>::take(const max<T>& other)
00152       {
00153         if (other.t_ > t_)
00154           t_ = other.t_;
00155       }
00156 
00157       template <typename T>
00158       inline
00159       const T&
00160       max<T>::to_result() const
00161       {
00162         return t_;
00163       }
00164 
00165       template <typename T>
00166       inline
00167       bool
00168       max<T>::is_valid() const
00169       {
00170         return true;
00171       }
00172 
00173 # endif // ! MLN_INCLUDE_ONLY
00174 
00175     } // end of namespace mln::accu::stat
00176 
00177   } // end of namespace mln::accu
00178 
00179 } // end of namespace mln
00180 
00181 
00182 #endif // ! MLN_ACCU_STAT_MAX_HH

Generated on Thu Sep 8 2011 18:32:05 for Milena (Olena) by  doxygen 1.7.1