Milena (Olena)  User documentation 2.0a Id
couple.hh
00001 // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
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     } // end of namespace mln::accu::internal
00176 
00177   } // end of namespace mln::accu
00178 
00179 } // end of namespace mln
00180 
00181 
00182 #endif // ! MLN_ACCU_INTERNAL_COUPLE_HH
 All Classes Namespaces Functions Variables Typedefs Enumerator