00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef MLN_ACCU_INTERNAL_COUPLE_HH
00027 # define MLN_ACCU_INTERNAL_COUPLE_HH
00028
00032
00033 # include <utility>
00034
00035 # include <mln/core/concept/accumulator.hh>
00036 # include <mln/accu/internal/base.hh>
00037
00038 # include <mln/metal/equal.hh>
00039
00040
00041 namespace mln
00042 {
00043
00044 namespace accu
00045 {
00046
00047 namespace internal
00048 {
00049
00055 template <typename A1, typename A2, typename R, typename E>
00056 class couple
00057 : public base<R,E>,
00058 public mlc_equal(mln_argument(A1), mln_argument(A2))::check_t
00059 {
00060 public:
00061 typedef mln_argument(A1) argument;
00062
00065 void init();
00066 void take_as_init(const argument& t);
00067 void take(const argument& t);
00068 void take(const E& other);
00070
00073 bool is_valid() const;
00074
00075 A1& first();
00076 A2& second();
00077 const A1& first() const;
00078 const A2& second() const;
00079
00080 protected:
00081 couple();
00082
00083 A1 a1_;
00084 A2 a2_;
00085 };
00086
00087
00088 # ifndef MLN_INCLUDE_ONLY
00089
00090 template <typename A1, typename A2, typename R, typename E>
00091 inline
00092 couple<A1,A2,R,E>::couple()
00093 {
00094 init();
00095 }
00096
00097 template <typename A1, typename A2, typename R, typename E>
00098 inline
00099 void
00100 couple<A1,A2,R,E>::init()
00101 {
00102 a1_.init();
00103 a2_.init();
00104 }
00105
00106 template <typename A1, typename A2, typename R, typename E>
00107 inline
00108 void
00109 couple<A1,A2,R,E>::take_as_init(const argument& t)
00110 {
00111 a1_.take_as_init(t);
00112 a2_.take_as_init(t);
00113 }
00114
00115 template <typename A1, typename A2, typename R, typename E>
00116 inline
00117 void
00118 couple<A1,A2,R,E>::take(const argument& t)
00119 {
00120 a1_.take(t);
00121 a2_.take(t);
00122 }
00123
00124 template <typename A1, typename A2, typename R, typename E>
00125 inline
00126 void
00127 couple<A1,A2,R,E>::take(const E& other)
00128 {
00129 a1_.take(other.a1_);
00130 a2_.take(other.a2_);
00131 }
00132
00133 template <typename A1, typename A2, typename R, typename E>
00134 inline
00135 bool
00136 couple<A1,A2,R,E>::is_valid() const
00137 {
00138 return a1_.is_valid() && a2_.is_valid();
00139 }
00140
00141 template <typename A1, typename A2, typename R, typename E>
00142 inline
00143 A1&
00144 couple<A1,A2,R,E>::first()
00145 {
00146 return a1_;
00147 }
00148
00149 template <typename A1, typename A2, typename R, typename E>
00150 inline
00151 const A1&
00152 couple<A1,A2,R,E>::first() const
00153 {
00154 return a1_;
00155 }
00156
00157 template <typename A1, typename A2, typename R, typename E>
00158 inline
00159 A2&
00160 couple<A1,A2,R,E>::second()
00161 {
00162 return a2_;
00163 }
00164
00165 template <typename A1, typename A2, typename R, typename E>
00166 inline
00167 const A2&
00168 couple<A1,A2,R,E>::second() const
00169 {
00170 return a2_;
00171 }
00172
00173 # endif // ! MLN_INCLUDE_ONLY
00174
00175 }
00176
00177 }
00178
00179 }
00180
00181
00182 #endif // ! MLN_ACCU_INTERNAL_COUPLE_HH