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

pair.hh

00001 // Copyright (C) 2007, 2008, 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_PAIR_HH
00027 # define MLN_ACCU_PAIR_HH
00028 
00032 
00033 # include <utility>
00034 
00035 # include <mln/core/concept/meta_accumulator.hh>
00036 
00037 # include <mln/accu/internal/base.hh>
00038 # include <mln/metal/is_a.hh>
00039 # include <mln/metal/unqualif.hh>
00040 
00041 
00042 namespace mln
00043 {
00044 
00045   namespace accu
00046   {
00047 
00048 
00056     //
00057     template <typename A1, typename A2, typename T = mln_argument(A1)>
00058     struct pair : public mln::accu::internal::base< std::pair<mln_result(A1), mln_result(A2)>,
00059                                                     pair<A1,A2,T> >
00060     {
00061       typedef T argument;
00062 
00063       typedef mln_result(A1) result_1;
00064       typedef mln_result(A2) result_2;
00065 
00066       pair();
00067 // FIXME: not implemented. Do we want it?
00068 //      pair(const A1& a1, const A2& a2);
00069 
00072       void init();
00073       void take_as_init_(const argument& t);
00074       void take(const argument& t);
00075       void take(const pair<A1,A2,T>& other);
00077 
00080       std::pair<mln_result(A1), mln_result(A2)> to_result() const;
00081       void get_result(result_1& r1, result_2& r2) const;
00083 
00084       mln_result(A1) first() const;
00085       mln_result(A2) second() const;
00086 
00089       bool is_valid() const;
00090 
00091     protected:
00092 
00093       A1 a1_;
00094       A2 a2_;
00095     };
00096 
00097 
00098     namespace meta
00099     {
00100 
00102       template <typename A1, typename A2>
00103       struct pair : public Meta_Accumulator< pair<A1,A2> >
00104       {
00105         template <typename T>
00106         struct with
00107         {
00108           typedef mln_accu_with(A1, T) A1_T;
00109           typedef mln_accu_with(A2, T) A2_T;
00110           typedef accu::pair<A1_T, A2_T, T> ret;
00111         };
00112       };
00113 
00114     } // end of namespace mln::accu::meta
00115 
00116 
00117 # ifndef MLN_INCLUDE_ONLY
00118 
00119     template <typename A1, typename A2, typename T>
00120     inline
00121     pair<A1,A2,T>::pair()
00122     {
00123       init();
00124     }
00125 
00126     template <typename A1, typename A2, typename T>
00127     inline
00128     void
00129     pair<A1,A2,T>::init()
00130     {
00131       a1_.init();
00132       a2_.init();
00133     }
00134 
00135     template <typename A1, typename A2, typename T>
00136     inline
00137     void
00138     pair<A1,A2,T>::take_as_init_(const argument& t)
00139     {
00140       a1_.take_as_init_(t);
00141       a2_.take_as_init_(t);
00142     }
00143 
00144     template <typename A1, typename A2, typename T>
00145     inline
00146     void
00147     pair<A1,A2,T>::take(const argument& t)
00148     {
00149       a1_.take(t);
00150       a2_.take(t);
00151     }
00152 
00153     template <typename A1, typename A2, typename T>
00154     inline
00155     void
00156     pair<A1,A2,T>::take(const pair<A1,A2,T>& other)
00157     {
00158       a1_.take(other.a1_);
00159       a2_.take(other.a2_);
00160     }
00161 
00162     template <typename A1, typename A2, typename T>
00163     inline
00164     std::pair<mln_result(A1), mln_result(A2)>
00165     pair<A1,A2,T>::to_result() const
00166     {
00167       std::pair<mln_result(A1), mln_result(A2)> tmp(a1_.to_result(), a2_.to_result());
00168       return tmp;
00169     }
00170 
00171     template <typename A1, typename A2, typename T>
00172     inline
00173     void
00174     pair<A1,A2,T>::get_result(result_1& r1,
00175                                result_2& r2) const
00176     {
00177       r1 = a1_.to_result();
00178       r2 = a2_.to_result();
00179     }
00180 
00181     template <typename A1, typename A2, typename T>
00182     inline
00183     mln_result(A1)
00184     pair<A1,A2,T>::first() const
00185     {
00186       return a1_.to_result();
00187     }
00188 
00189     template <typename A1, typename A2, typename T>
00190     inline
00191     mln_result(A2)
00192     pair<A1,A2,T>::second() const
00193     {
00194       return a2_.to_result();
00195     }
00196 
00197     template <typename A1, typename A2, typename T>
00198     inline
00199     bool
00200     pair<A1,A2,T>::is_valid() const
00201     {
00202       return a1_.is_valid() && a2_.is_valid();
00203     }
00204 
00205 # endif // ! MLN_INCLUDE_ONLY
00206 
00207   } // end of namespace mln::accu
00208 
00209 } // end of namespace mln
00210 
00211 
00212 #endif // ! MLN_ACCU_PAIR_HH

Generated on Thu Sep 8 2011 18:32:19 for Milena (Olena) by  doxygen 1.7.1