• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

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       struct couple
00057         : base<R,E>,
00058           mlc_equal(mln_argument(A1), mln_argument(A2))::check_t
00059       {
00060         typedef mln_argument(A1) argument;
00061 
00064         void init();
00065         void take_as_init(const argument& t);
00066         void take(const argument& t);
00067         void take(const E& other);
00069 
00072         bool is_valid() const;
00073 
00074         A1& first();
00075         A2& second();
00076         const A1& first() const;
00077         const A2& second() const;
00078 
00079         protected:
00080         couple();
00081 
00082         A1 a1_;
00083         A2 a2_;
00084       };
00085 
00086 
00087 # ifndef MLN_INCLUDE_ONLY
00088 
00089       template <typename A1, typename A2, typename R, typename E>
00090       inline
00091       couple<A1,A2,R,E>::couple()
00092       {
00093         init();
00094       }
00095 
00096       template <typename A1, typename A2, typename R, typename E>
00097       inline
00098       void
00099       couple<A1,A2,R,E>::init()
00100       {
00101         a1_.init();
00102         a2_.init();
00103       }
00104 
00105       template <typename A1, typename A2, typename R, typename E>
00106       inline
00107       void
00108       couple<A1,A2,R,E>::take_as_init(const argument& t)
00109       {
00110         a1_.take_as_init(t);
00111         a2_.take_as_init(t);
00112       }
00113 
00114       template <typename A1, typename A2, typename R, typename E>
00115       inline
00116       void
00117       couple<A1,A2,R,E>::take(const argument& t)
00118       {
00119         a1_.take(t);
00120         a2_.take(t);
00121       }
00122 
00123       template <typename A1, typename A2, typename R, typename E>
00124       inline
00125       void
00126       couple<A1,A2,R,E>::take(const E& other)
00127       {
00128         a1_.take(other.a1_);
00129         a2_.take(other.a2_);
00130       }
00131 
00132       template <typename A1, typename A2, typename R, typename E>
00133       inline
00134       bool
00135       couple<A1,A2,R,E>::is_valid() const
00136       {
00137         return a1_.is_valid() && a2_.is_valid();
00138       }
00139 
00140       template <typename A1, typename A2, typename R, typename E>
00141       inline
00142       A1&
00143       couple<A1,A2,R,E>::first()
00144       {
00145         return a1_;
00146       }
00147 
00148       template <typename A1, typename A2, typename R, typename E>
00149       inline
00150       const A1&
00151       couple<A1,A2,R,E>::first() const
00152       {
00153         return a1_;
00154       }
00155 
00156       template <typename A1, typename A2, typename R, typename E>
00157       inline
00158       A2&
00159       couple<A1,A2,R,E>::second()
00160       {
00161         return a2_;
00162       }
00163 
00164       template <typename A1, typename A2, typename R, typename E>
00165       inline
00166       const A2&
00167       couple<A1,A2,R,E>::second() const
00168       {
00169         return a2_;
00170       }
00171 
00172 # endif // ! MLN_INCLUDE_ONLY
00173 
00174     } // end of namespace mln::accu::internal
00175 
00176   } // end of namespace mln::accu
00177 
00178 } // end of namespace mln
00179 
00180 
00181 #endif // ! MLN_ACCU_INTERNAL_COUPLE_HH

Generated on Tue Oct 4 2011 15:23:40 for Milena (Olena) by  doxygen 1.7.1