$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
accu/stat/max.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_MAX_HH
27 # define MLN_ACCU_STAT_MAX_HH
28 
32 
33 # include <mln/core/concept/meta_accumulator.hh>
34 # include <mln/accu/internal/base.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 max;
47  }
48  }
49 
50 
51  // Traits.
52 
53  namespace trait
54  {
55 
56  template <typename T>
57  struct accumulator_< accu::stat::max<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  {
76 
78  struct max : public Meta_Accumulator< max >
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 
100  template <typename T>
101  struct max : public mln::accu::internal::base< const T& , max<T> >
102  {
103  typedef T argument;
104 
105  max();
106 
109  void init();
110  void take_as_init_(const argument& t);
111  void take(const argument& t);
112  void take(const max<T>& other);
114 
116  void set_value(const T& t);
117 
119  const T& to_result() const;
120 
123  bool is_valid() const;
124 
125  protected:
126 
127  T t_;
128  };
129 
130 
131  template <typename I> struct max< util::pix<I> >;
132 
133 
134 # ifndef MLN_INCLUDE_ONLY
135 
136  template <typename T>
137  inline
138  max<T>::max()
139  {
140  init();
141  }
142 
143  template <typename T>
144  inline
145  void
146  max<T>::init()
147  {
148  t_ = mln_min(T);
149  }
150 
151  template <typename T>
152  inline
153  void
154  max<T>::take_as_init_(const argument& t)
155  {
156  t_ = t;
157  }
158 
159  template <typename T>
160  inline
161  void
162  max<T>::take(const argument& t)
163  {
164  if (t > t_)
165  t_ = t;
166  }
167 
168  template <typename T>
169  inline
170  void
171  max<T>::take(const max<T>& other)
172  {
173  if (other.t_ > t_)
174  t_ = other.t_;
175  }
176 
177  template <typename T>
178  inline
179  void
180  max<T>::set_value(const T& t)
181  {
182  t_ = t;
183  }
184 
185  template <typename T>
186  inline
187  const T&
188  max<T>::to_result() const
189  {
190  return t_;
191  }
192 
193  template <typename T>
194  inline
195  bool
196  max<T>::is_valid() const
197  {
198  return true;
199  }
200 
201 # endif // ! MLN_INCLUDE_ONLY
202 
203  } // end of namespace mln::accu::stat
204 
205  } // end of namespace mln::accu
206 
207 } // end of namespace mln
208 
209 
210 #endif // ! MLN_ACCU_STAT_MAX_HH