• 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 
00085       mln_result(A1) first() const;
00087       mln_result(A2) second() const;
00088 
00090       A1 first_accu() const;
00092       A2 second_accu() const;
00093 
00096       bool is_valid() const;
00097 
00098     protected:
00099 
00100       A1 a1_;
00101       A2 a2_;
00102     };
00103 
00104 
00105     namespace meta
00106     {
00107 
00109       template <typename A1, typename A2>
00110       struct pair : public Meta_Accumulator< pair<A1,A2> >
00111       {
00112         template <typename T>
00113         struct with
00114         {
00115           typedef mln_accu_with(A1, T) A1_T;
00116           typedef mln_accu_with(A2, T) A2_T;
00117           typedef accu::pair<A1_T, A2_T, T> ret;
00118         };
00119       };
00120 
00121     } // end of namespace mln::accu::meta
00122 
00123 
00124 # ifndef MLN_INCLUDE_ONLY
00125 
00126     template <typename A1, typename A2, typename T>
00127     inline
00128     pair<A1,A2,T>::pair()
00129     {
00130       init();
00131     }
00132 
00133     template <typename A1, typename A2, typename T>
00134     inline
00135     void
00136     pair<A1,A2,T>::init()
00137     {
00138       a1_.init();
00139       a2_.init();
00140     }
00141 
00142     template <typename A1, typename A2, typename T>
00143     inline
00144     void
00145     pair<A1,A2,T>::take_as_init_(const argument& t)
00146     {
00147       a1_.take_as_init_(t);
00148       a2_.take_as_init_(t);
00149     }
00150 
00151     template <typename A1, typename A2, typename T>
00152     inline
00153     void
00154     pair<A1,A2,T>::take(const argument& t)
00155     {
00156       a1_.take(t);
00157       a2_.take(t);
00158     }
00159 
00160     template <typename A1, typename A2, typename T>
00161     inline
00162     void
00163     pair<A1,A2,T>::take(const pair<A1,A2,T>& other)
00164     {
00165       a1_.take(other.a1_);
00166       a2_.take(other.a2_);
00167     }
00168 
00169     template <typename A1, typename A2, typename T>
00170     inline
00171     std::pair<mln_result(A1), mln_result(A2)>
00172     pair<A1,A2,T>::to_result() const
00173     {
00174       std::pair<mln_result(A1), mln_result(A2)> tmp(a1_.to_result(), a2_.to_result());
00175       return tmp;
00176     }
00177 
00178     template <typename A1, typename A2, typename T>
00179     inline
00180     void
00181     pair<A1,A2,T>::get_result(result_1& r1,
00182                                result_2& r2) const
00183     {
00184       r1 = a1_.to_result();
00185       r2 = a2_.to_result();
00186     }
00187 
00188     template <typename A1, typename A2, typename T>
00189     inline
00190     mln_result(A1)
00191     pair<A1,A2,T>::first() const
00192     {
00193       return a1_.to_result();
00194     }
00195 
00196     template <typename A1, typename A2, typename T>
00197     inline
00198     mln_result(A2)
00199     pair<A1,A2,T>::second() const
00200     {
00201       return a2_.to_result();
00202     }
00203 
00204 
00205 
00206     template <typename A1, typename A2, typename T>
00207     inline
00208     A1
00209     pair<A1,A2,T>::first_accu() const
00210     {
00211       return a1_;
00212     }
00213 
00214     template <typename A1, typename A2, typename T>
00215     inline
00216     A2
00217     pair<A1,A2,T>::second_accu() const
00218     {
00219       return a2_;
00220     }
00221 
00222 
00223     template <typename A1, typename A2, typename T>
00224     inline
00225     bool
00226     pair<A1,A2,T>::is_valid() const
00227     {
00228       return a1_.is_valid() && a2_.is_valid();
00229     }
00230 
00231 # endif // ! MLN_INCLUDE_ONLY
00232 
00233   } // end of namespace mln::accu
00234 
00235 } // end of namespace mln
00236 
00237 
00238 #endif // ! MLN_ACCU_PAIR_HH

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