Milena (Olena)
User documentation 2.0a Id
|
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 00043 // Forward declaration. 00044 namespace accu { 00045 namespace stat { 00046 template <typename T> struct min; 00047 } 00048 } 00049 00050 00051 // Traits. 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 } // end of namespace mln::trait 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 } // end of namespace mln::accu::meta::stat 00088 00089 } // end of namespace mln::accu::meta 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 } // end of namespace mln::accu::stat 00203 00204 } // end of namespace mln::accu 00205 00206 } // end of namespace mln 00207 00208 00209 #endif // ! MLN_ACCU_STAT_MIN_HH