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

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

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