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

solve_unary.hh

00001 // Copyright (C) 2006, 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_TRAIT_NEXT_SOLVE_UNARY_HH
00027 # define MLN_TRAIT_NEXT_SOLVE_UNARY_HH
00028 
00037 # include <mln/core/category.hh>
00038 # include <mln/core/routine/exact.hh>
00039 # include <mln/metal/equal.hh>
00040 # include <mln/metal/if.hh>
00041 # include <mln/metal/ret.hh>
00042 # include <mln/trait/next/solve.hh>
00043 
00044 
00045 // FIXME: Just for the record (use it...)
00046 
00047 #  ifndef MLN_DEBUG_TRAITS
00048 #  endif // ! MLN_DEBUG_TRAITS
00049 
00050 
00051 
00052 namespace mln
00053 {
00054 
00055   namespace trait
00056   {
00057 
00058     namespace next
00059     {
00060 
00061       namespace internal
00062       {
00063 
00064 
00065         template < typename Name,
00066                    typename Category,
00067                    typename T >
00068         struct trait_set_unary_;
00069 
00070         template < typename Name,
00071                    template <class> class Category, typename _,
00072                    typename T >
00073         struct trait_set_unary_< Name, Category<_>, T >
00074         {
00075           typedef typename mln::trait::next::set_unary_<Name, Category, T>::ret ret;
00076         };
00077 
00078 
00079         // Fwd decls.
00080         template < typename Name,
00081                    typename Category, typename T >
00082         struct get_unary_;
00083 
00084 
00085         template < typename user_ret, /* != not_found and != undefined */
00086                    typename Name,
00087                    typename Category, typename T >
00088         struct helper_get_unary_
00089         {
00090           typedef user_ret ret;  // The user has defined 'ret' so we return it.
00091         };
00092 
00093 
00094         template < typename Name,
00095                    typename Category, typename T >
00096         struct helper_get_unary_< /* user_ret == */ not_found,
00097                                   Name, Category, T >
00098         {
00099           typedef not_found ret;  // End of search due to a blocker; 'ret' is not found.
00100         };
00101 
00102 
00103         template < typename Name,
00104                    typename Category, typename T >
00105         struct helper_get_unary_< /* user_ret == */ undefined,
00106                                   Name, Category, T >
00107         {
00108           typedef typename mln::internal::super_category_< Category, T >::ret Super_Category;
00109           typedef typename get_unary_<Name, Super_Category, T>::ret ret;   // No user ret definition => Recursion.
00110         };
00111 
00112 
00113         template < typename Name,
00114                    typename Category, typename T >
00115         struct get_unary_
00116         {
00117           typedef typename trait_set_unary_<Name, Category, T>::ret user_ret;  // First get 'user_ret'
00118           typedef helper_get_unary_<user_ret, Name, Category, T> helper;       // Set the helper to make a decision.
00119           typedef mlc_ret(helper) ret;                                         // Return.
00120         };
00121 
00122 
00123         template < typename precise_ret,
00124                    typename Name,
00125                    typename Category, typename T >
00126         struct helper_choose_unary_wrt_ /* precise_ret != undefined */
00127         {
00128           typedef precise_ret ret;                                 // -> A precise ret has been defined so it is it.
00129         };
00130 
00131         template < typename Name,
00132                    typename Category, typename T >
00133         struct helper_choose_unary_wrt_< /* precise_ret == */ undefined,
00134                                         Name, Category, T >
00135         {
00136           typedef typename get_unary_<Name, Category, T>::ret ret; // -> Go up into the category inheritance
00137                                                                   //    to fetch a ret from 'set_unary_'s.
00138         };
00139 
00140         template < typename Name,
00141                    typename Category, typename T >
00142         struct helper_solve_unary_
00143         {
00144           typedef typename set_precise_unary_<Name, T>::ret precise_ret;
00145           typedef helper_choose_unary_wrt_< precise_ret, /* undefined or not (?) */
00146                                             Name, Category, T> helper;
00147           typedef mlc_ret(helper) ret;
00148         };
00149 
00150       } // end of namespace mln::trait::next::internal
00151 
00152 
00153       template < typename Name,
00154                 typename T_ >
00155       struct solve_unary
00156       {
00157         typedef mln_exact(T_) T;
00158         typedef typename mln::category<T>::ret Category;
00159         typedef internal::helper_solve_unary_< Name, Category, T > meta_code;
00160         typedef typename meta_code::ret ret;
00161       };
00162 
00163     } // end of namespace mln::trait::next
00164 
00165   } // end of namespace mln::trait
00166 
00167 } // end of namespace mln
00168 
00169 
00170 #endif // ! MLN_TRAIT_NEXT_SOLVE_UNARY_HH

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