$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
accu/internal/couple.hh
1 // Copyright (C) 2009, 2012 EPITA Research and Development Laboratory
2 // (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_ACCU_INTERNAL_COUPLE_HH
28 # define MLN_ACCU_INTERNAL_COUPLE_HH
29 
33 
34 # include <utility>
35 
36 # include <mln/core/concept/accumulator.hh>
37 # include <mln/accu/internal/base.hh>
38 
39 # include <mln/metal/equal.hh>
40 
41 
42 namespace mln
43 {
44 
45  namespace accu
46  {
47 
48  namespace internal
49  {
50 
59  template <typename A1, typename A2, typename R, typename E>
60  class couple
61  : public base<R,E>,
62  public mlc_equal(mln_argument(A1), mln_argument(A2))::check_t
63  {
64  public:
65  typedef mln_argument(A1) argument;
66 
69  void init();
70  void take_as_init(const argument& t);
71  void take(const argument& t);
72  void take(const E& other);
74 
77  bool is_valid() const;
78 
79  A1& first();
80  A2& second();
81  const A1& first() const;
82  const A2& second() const;
83 
84  protected:
85  couple();
86 
87  A1 a1_;
88  A2 a2_;
89  };
90 
91 
92 # ifndef MLN_INCLUDE_ONLY
93 
94  template <typename A1, typename A2, typename R, typename E>
95  inline
97  {
98  init();
99  }
100 
101  template <typename A1, typename A2, typename R, typename E>
102  inline
103  void
105  {
106  a1_.init();
107  a2_.init();
108  }
109 
110  template <typename A1, typename A2, typename R, typename E>
111  inline
112  void
113  couple<A1,A2,R,E>::take_as_init(const argument& t)
114  {
115  a1_.take_as_init(t);
116  a2_.take_as_init(t);
117  }
118 
119  template <typename A1, typename A2, typename R, typename E>
120  inline
121  void
122  couple<A1,A2,R,E>::take(const argument& t)
123  {
124  a1_.take(t);
125  a2_.take(t);
126  }
127 
128  template <typename A1, typename A2, typename R, typename E>
129  inline
130  void
131  couple<A1,A2,R,E>::take(const E& other)
132  {
133  a1_.take(other.a1_);
134  a2_.take(other.a2_);
135  }
136 
137  template <typename A1, typename A2, typename R, typename E>
138  inline
139  bool
141  {
142  return a1_.is_valid() && a2_.is_valid();
143  }
144 
145  template <typename A1, typename A2, typename R, typename E>
146  inline
147  A1&
149  {
150  return a1_;
151  }
152 
153  template <typename A1, typename A2, typename R, typename E>
154  inline
155  const A1&
157  {
158  return a1_;
159  }
160 
161  template <typename A1, typename A2, typename R, typename E>
162  inline
163  A2&
165  {
166  return a2_;
167  }
168 
169  template <typename A1, typename A2, typename R, typename E>
170  inline
171  const A2&
173  {
174  return a2_;
175  }
176 
177 # endif // ! MLN_INCLUDE_ONLY
178 
179  } // end of namespace mln::accu::internal
180 
181  } // end of namespace mln::accu
182 
183 } // end of namespace mln
184 
185 
186 #endif // ! MLN_ACCU_INTERNAL_COUPLE_HH