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