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