$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
apps/bench/minus.hh
1 // Copyright (C) 2010 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_MINUS_HH
27 # define MLN_ACCU_MINUS_HH
28 
32 
33 # include <mln/core/concept/meta_accumulator.hh>
34 
35 # include <mln/arith/minus.hh>
36 
37 # include <mln/accu/internal/base.hh>
38 # include <mln/metal/is_a.hh>
39 # include <mln/metal/unqualif.hh>
40 
41 
42 namespace mln
43 {
44 
45  namespace accu
46  {
47 
48 
57  //
58  template <typename A1, typename A2, typename T = mln_argument(A1)>
59  struct minus
60  : public mln::accu::internal::base< mln_result(A1), minus<A1,A2,T> >
61  {
62  typedef T argument;
63 
64  typedef mln_result(A1) result_1;
65  typedef mln_result(A2) result_2;
66 
67  minus();
68 // FIXME: not implemented. Do we want it?
69 // minus(const A1& a1, const A2& a2);
70 
73  void init();
74  void take_as_init_(const argument& t);
75  void take(const argument& t);
76  void take(const minus<A1,A2,T>& other);
77  void untake(const argument& t);
79 
82  mln_result(A1) to_result() const;
83  void get_result(result_1& r1, result_2& r2) const;
85 
87  mln_result(A1) first() const;
89  mln_result(A2) second() const;
90 
92  A1 first_accu() const;
94  A2 second_accu() const;
95 
98  bool is_valid() const;
99 
100  protected:
101 
102  A1 a1_;
103  A2 a2_;
104  };
105 
106 
107  namespace meta
108  {
109 
111  template <typename A1, typename A2>
112  struct minus : public Meta_Accumulator< minus<A1,A2> >
113  {
114  template <typename T>
115  struct with
116  {
117  typedef mln_accu_with(A1, T) A1_T;
118  typedef mln_accu_with(A2, T) A2_T;
119  typedef accu::minus<A1_T, A2_T, T> ret;
120  };
121  };
122 
123  } // end of namespace mln::accu::meta
124 
125 
126 # ifndef MLN_INCLUDE_ONLY
127 
128  template <typename A1, typename A2, typename T>
129  inline
131  {
132  init();
133  }
134 
135  template <typename A1, typename A2, typename T>
136  inline
137  void
139  {
140  a1_.init();
141  a2_.init();
142  }
143 
144  template <typename A1, typename A2, typename T>
145  inline
146  void
148  {
149  a1_.take_as_init_(t);
150  a2_.take_as_init_(t);
151  }
152 
153  template <typename A1, typename A2, typename T>
154  inline
155  void
157  {
158  a1_.take(t);
159  a2_.take(t);
160  }
161 
162  template <typename A1, typename A2, typename T>
163  inline
164  void
165  minus<A1,A2,T>::take(const minus<A1,A2,T>& other)
166  {
167  a1_.take(other.a1_);
168  a2_.take(other.a2_);
169  }
170 
171  template <typename A1, typename A2, typename T>
172  inline
173  void
175  {
176  a1_.untake(t);
177  a2_.untake(t);
178  }
179 
180  template <typename A1, typename A2, typename T>
181  inline
182  mln_result(A1)
183  minus<A1,A2,T>::to_result() const
184  {
185  mln_result(A1) tmp = a1_.to_result() - a2_.to_result();
186  return tmp;
187  }
188 
189  template <typename A1, typename A2, typename T>
190  inline
191  void
192  minus<A1,A2,T>::get_result(result_1& r1,
193  result_2& r2) const
194  {
195  r1 = a1_.to_result();
196  r2 = a2_.to_result();
197  }
198 
199  template <typename A1, typename A2, typename T>
200  inline
201  mln_result(A1)
202  minus<A1,A2,T>::first() const
203  {
204  return a1_.to_result();
205  }
206 
207  template <typename A1, typename A2, typename T>
208  inline
209  mln_result(A2)
210  minus<A1,A2,T>::second() const
211  {
212  return a2_.to_result();
213  }
214 
215 
216 
217  template <typename A1, typename A2, typename T>
218  inline
219  A1
221  {
222  return a1_;
223  }
224 
225  template <typename A1, typename A2, typename T>
226  inline
227  A2
229  {
230  return a2_;
231  }
232 
233 
234  template <typename A1, typename A2, typename T>
235  inline
236  bool
238  {
239  return a1_.is_valid() && a2_.is_valid();
240  }
241 
242 # endif // ! MLN_INCLUDE_ONLY
243 
244  } // end of namespace mln::accu
245 
246 } // end of namespace mln
247 
248 
249 #endif // ! MLN_ACCU_MINUS_HH