Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
accu/math/sup.hh
1 // Copyright (C) 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_MATH_SUP_HH
27 # define MLN_ACCU_MATH_SUP_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 # include <mln/fun/math/sup.hh>
38 
39 namespace mln
40 {
41 
42  namespace accu
43  {
44 
45  namespace math
46  {
47 
48 
50 
55  template <typename T>
56  struct sup : public mln::accu::internal::base< const T&, sup<T> >
57  {
58  typedef T argument;
59 
60  sup();
61 
64  void init();
65  void take_as_init_(const argument& t);
66  void take(const argument& t);
67  void take(const sup<T>& other);
69 
71  const T& to_result() const;
72 
75  bool is_valid() const;
76 
77  protected:
78 
79  T t_;
80  typename mln::fun::sup::with<T, T>::ret fun_;
81  };
82 
83 
84  template <typename I> struct sup< util::pix<I> >;
85 
86 
87  } // end of mln::accu::math
88 
89 
90  namespace meta
91  {
92 
93  namespace math
94  {
95 
97 
98  struct sup : public Meta_Accumulator< sup >
99  {
100  template <typename T>
101  struct with
102  {
103  typedef accu::math::sup<T> ret;
104  };
105  };
106 
107  } // end of namespace mln::accu::meta::math
108 
109  } // end of namespace mln::accu::meta
110 
111 
112 
113 # ifndef MLN_INCLUDE_ONLY
114 
115  namespace math
116  {
117 
118  template <typename T>
119  inline
120  sup<T>::sup()
121  {
122  init();
123  }
124 
125  template <typename T>
126  inline
127  void
129  {
130  t_ = mln_min(T);
131  }
132 
133  template <typename T>
134  inline
135  void sup<T>::take_as_init_(const argument& t)
136  {
137  t_ = t;
138  }
139 
140  template <typename T>
141  inline
142  void sup<T>::take(const argument& t)
143  {
144  this->t_ = this->fun_(t_, t);
145  }
146 
147  template <typename T>
148  inline
149  void
150  sup<T>::take(const sup<T>& other)
151  {
152  this->t_ = this->fun_(t_, other.t_);
153  }
154 
155  template <typename T>
156  inline
157  const T&
159  {
160  return t_;
161  }
162 
163  template <typename T>
164  inline
165  bool
167  {
168  return true;
169  }
170 
171  } // end of namespace mln::accu::math
172 
173 # endif // ! MLN_INCLUDE_ONLY
174 
175  } // end of namespace mln::accu
176 
177 } // end of namespace mln
178 
179 
180 #endif // ! MLN_ACCU_MATH_SUP_HH