$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
accu/stat/min.hh
1 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_ACCU_STAT_MIN_HH
27 # define MLN_ACCU_STAT_MIN_HH
28 
32 
33 # include <mln/accu/internal/base.hh>
34 # include <mln/core/concept/meta_accumulator.hh>
35 # include <mln/trait/value_.hh>
36 # include <mln/util/pix.hh>
37 
38 
39 namespace mln
40 {
41 
42 
43  // Forward declaration.
44  namespace accu {
45  namespace stat {
46  template <typename T> struct min;
47  }
48  }
49 
50 
51  // Traits.
52 
53  namespace trait
54  {
55 
56  template <typename T>
57  struct accumulator_< accu::stat::min<T> >
58  {
59  typedef accumulator::has_untake::no has_untake;
60  typedef accumulator::has_set_value::yes has_set_value;
61  typedef accumulator::has_stop::no has_stop;
62  typedef accumulator::when_pix::use_v when_pix;
63  };
64 
65  } // end of namespace mln::trait
66 
67 
68  namespace accu
69  {
70 
71  namespace meta
72  {
73 
74  namespace stat
75  {
77 
78  struct min : public Meta_Accumulator< min >
79  {
80  template <typename T>
81  struct with
82  {
84  };
85  };
86 
87  } // end of namespace mln::accu::meta::stat
88 
89  } // end of namespace mln::accu::meta
90 
91 
92  namespace stat
93  {
94 
96 
101  template <typename T>
102  struct min : public mln::accu::internal::base< const T&, min<T> >
103  {
104  typedef T argument;
105 
106  min();
107 
110  void init();
111  void take_as_init_(const argument& t);
112  void take(const argument& t);
113  void take(const min<T>& other);
115 
117  void set_value(const T& t);
118 
120  const T& to_result() const;
121 
124  bool is_valid() const;
125 
126  protected:
127 
128  T t_;
129  };
130 
131 
132  template <typename I> struct min< util::pix<I> >;
133 
134 
135 # ifndef MLN_INCLUDE_ONLY
136 
137  template <typename T>
138  inline
139  min<T>::min()
140  {
141  init();
142  }
143 
144  template <typename T>
145  inline
146  void
147  min<T>::init()
148  {
149  t_ = mln_max(T);
150  }
151 
152  template <typename T>
153  inline
154  void min<T>::take_as_init_(const argument& t)
155  {
156  t_ = t;
157  }
158 
159  template <typename T>
160  inline
161  void min<T>::take(const argument& t)
162  {
163  if (t < t_)
164  t_ = t;
165  }
166 
167  template <typename T>
168  inline
169  void
170  min<T>::take(const min<T>& other)
171  {
172  if (other.t_ < t_)
173  t_ = other.t_;
174  }
175 
176  template <typename T>
177  inline
178  void
179  min<T>::set_value(const T& t)
180  {
181  t_ = t;
182  }
183 
184  template <typename T>
185  inline
186  const T&
187  min<T>::to_result() const
188  {
189  return t_;
190  }
191 
192  template <typename T>
193  inline
194  bool
195  min<T>::is_valid() const
196  {
197  return true;
198  }
199 
200 # endif // ! MLN_INCLUDE_ONLY
201 
202  } // end of namespace mln::accu::stat
203 
204  } // end of namespace mln::accu
205 
206 } // end of namespace mln
207 
208 
209 #endif // ! MLN_ACCU_STAT_MIN_HH