Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
accu/internal/couple.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_INTERNAL_COUPLE_HH
27 # define MLN_ACCU_INTERNAL_COUPLE_HH
28 
32 
33 # include <utility>
34 
35 # include <mln/core/concept/accumulator.hh>
36 # include <mln/accu/internal/base.hh>
37 
38 # include <mln/metal/equal.hh>
39 
40 
41 namespace mln
42 {
43 
44  namespace accu
45  {
46 
47  namespace internal
48  {
49 
55  template <typename A1, typename A2, typename R, typename E>
56  class couple
57  : public base<R,E>,
58  public mlc_equal(mln_argument(A1), mln_argument(A2))::check_t
59  {
60  public:
61  typedef mln_argument(A1) argument;
62 
65  void init();
66  void take_as_init(const argument& t);
67  void take(const argument& t);
68  void take(const E& other);
70 
73  bool is_valid() const;
74 
75  A1& first();
76  A2& second();
77  const A1& first() const;
78  const A2& second() const;
79 
80  protected:
81  couple();
82 
83  A1 a1_;
84  A2 a2_;
85  };
86 
87 
88 # ifndef MLN_INCLUDE_ONLY
89 
90  template <typename A1, typename A2, typename R, typename E>
91  inline
92  couple<A1,A2,R,E>::couple()
93  {
94  init();
95  }
96 
97  template <typename A1, typename A2, typename R, typename E>
98  inline
99  void
100  couple<A1,A2,R,E>::init()
101  {
102  a1_.init();
103  a2_.init();
104  }
105 
106  template <typename A1, typename A2, typename R, typename E>
107  inline
108  void
109  couple<A1,A2,R,E>::take_as_init(const argument& t)
110  {
111  a1_.take_as_init(t);
112  a2_.take_as_init(t);
113  }
114 
115  template <typename A1, typename A2, typename R, typename E>
116  inline
117  void
118  couple<A1,A2,R,E>::take(const argument& t)
119  {
120  a1_.take(t);
121  a2_.take(t);
122  }
123 
124  template <typename A1, typename A2, typename R, typename E>
125  inline
126  void
127  couple<A1,A2,R,E>::take(const E& other)
128  {
129  a1_.take(other.a1_);
130  a2_.take(other.a2_);
131  }
132 
133  template <typename A1, typename A2, typename R, typename E>
134  inline
135  bool
136  couple<A1,A2,R,E>::is_valid() const
137  {
138  return a1_.is_valid() && a2_.is_valid();
139  }
140 
141  template <typename A1, typename A2, typename R, typename E>
142  inline
143  A1&
144  couple<A1,A2,R,E>::first()
145  {
146  return a1_;
147  }
148 
149  template <typename A1, typename A2, typename R, typename E>
150  inline
151  const A1&
152  couple<A1,A2,R,E>::first() const
153  {
154  return a1_;
155  }
156 
157  template <typename A1, typename A2, typename R, typename E>
158  inline
159  A2&
160  couple<A1,A2,R,E>::second()
161  {
162  return a2_;
163  }
164 
165  template <typename A1, typename A2, typename R, typename E>
166  inline
167  const A2&
168  couple<A1,A2,R,E>::second() const
169  {
170  return a2_;
171  }
172 
173 # endif // ! MLN_INCLUDE_ONLY
174 
175  } // end of namespace mln::accu::internal
176 
177  } // end of namespace mln::accu
178 
179 } // end of namespace mln
180 
181 
182 #endif // ! MLN_ACCU_INTERNAL_COUPLE_HH