$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
pair.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_PAIR_HH
27 # define MLN_ACCU_PAIR_HH
28 
32 
33 # include <utility>
34 
35 # include <mln/core/concept/meta_accumulator.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 pair : public mln::accu::internal::base< std::pair<mln_result(A1), mln_result(A2)>,
59  pair<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  pair();
67 // FIXME: not implemented. Do we want it?
68 // pair(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 pair<A1,A2,T>& other);
77 
80  std::pair<mln_result(A1), mln_result(A2)> to_result() const;
81  void get_result(result_1& r1, result_2& r2) const;
83 
85  mln_result(A1) first() const;
87  mln_result(A2) second() const;
88 
90  A1 first_accu() const;
92  A2 second_accu() const;
93 
96  bool is_valid() const;
97 
98  protected:
99 
100  A1 a1_;
101  A2 a2_;
102  };
103 
104 
105  namespace meta
106  {
107 
109  template <typename A1, typename A2>
110  struct pair : public Meta_Accumulator< pair<A1,A2> >
111  {
112  template <typename T>
113  struct with
114  {
115  typedef mln_accu_with(A1, T) A1_T;
116  typedef mln_accu_with(A2, T) A2_T;
117  typedef accu::pair<A1_T, A2_T, T> ret;
118  };
119  };
120 
121  } // end of namespace mln::accu::meta
122 
123 
124 # ifndef MLN_INCLUDE_ONLY
125 
126  template <typename A1, typename A2, typename T>
127  inline
129  {
130  init();
131  }
132 
133  template <typename A1, typename A2, typename T>
134  inline
135  void
137  {
138  a1_.init();
139  a2_.init();
140  }
141 
142  template <typename A1, typename A2, typename T>
143  inline
144  void
146  {
147  a1_.take_as_init_(t);
148  a2_.take_as_init_(t);
149  }
150 
151  template <typename A1, typename A2, typename T>
152  inline
153  void
154  pair<A1,A2,T>::take(const argument& t)
155  {
156  a1_.take(t);
157  a2_.take(t);
158  }
159 
160  template <typename A1, typename A2, typename T>
161  inline
162  void
163  pair<A1,A2,T>::take(const pair<A1,A2,T>& other)
164  {
165  a1_.take(other.a1_);
166  a2_.take(other.a2_);
167  }
168 
169  template <typename A1, typename A2, typename T>
170  inline
171  std::pair<mln_result(A1), mln_result(A2)>
173  {
174  std::pair<mln_result(A1), mln_result(A2)> tmp(a1_.to_result(), a2_.to_result());
175  return tmp;
176  }
177 
178  template <typename A1, typename A2, typename T>
179  inline
180  void
181  pair<A1,A2,T>::get_result(result_1& r1,
182  result_2& r2) const
183  {
184  r1 = a1_.to_result();
185  r2 = a2_.to_result();
186  }
187 
188  template <typename A1, typename A2, typename T>
189  inline
190  mln_result(A1)
191  pair<A1,A2,T>::first() const
192  {
193  return a1_.to_result();
194  }
195 
196  template <typename A1, typename A2, typename T>
197  inline
198  mln_result(A2)
199  pair<A1,A2,T>::second() const
200  {
201  return a2_.to_result();
202  }
203 
204 
205 
206  template <typename A1, typename A2, typename T>
207  inline
208  A1
210  {
211  return a1_;
212  }
213 
214  template <typename A1, typename A2, typename T>
215  inline
216  A2
218  {
219  return a2_;
220  }
221 
222 
223  template <typename A1, typename A2, typename T>
224  inline
225  bool
227  {
228  return a1_.is_valid() && a2_.is_valid();
229  }
230 
231 # endif // ! MLN_INCLUDE_ONLY
232 
233  } // end of namespace mln::accu
234 
235 } // end of namespace mln
236 
237 
238 #endif // ! MLN_ACCU_PAIR_HH