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

category.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_CORE_CATEGORY_HH
00027 # define MLN_CORE_CATEGORY_HH
00028 
00032 
00033 # include <mln/metal/equal.hh>
00034 
00035 
00036 
00037 namespace mln
00038 {
00039 
00040   // FIXME: Doc!
00041 
00042 
00043   template <typename E>
00044   struct Unknown;
00045 
00046 
00047   template <>
00048   struct Unknown<void>
00049   {
00050     typedef Unknown<void> super;
00051     // Unknown is used to terminate the meta-program that solves a
00052     // call to a trait.  This meta-program can browse several branches
00053     // at the same time---if the trait takes 2 types as arguments, the
00054     // program runs over the trellis formed by the "couples of
00055     // categories"--- and when the end of one branch is reached, we do
00056     // not want the program to end; so it continues on that branch
00057     // with the no-op "jump to the super type of Unknown"!
00058   };
00059 
00060 
00061   template <typename T>
00062   struct category
00063   {
00064     typedef typename T::category ret; // FIXME: if found or Unknown<void> => write a meta-program...
00065   };
00066 
00067   template <typename T>
00068   struct category< const T >
00069   {
00070     typedef typename category<T>::ret ret;
00071   };
00072 
00073 
00074 
00075   // Utility meta-function: from a category and a type, get the super category.
00076 
00077   namespace internal
00078   {
00079 
00080     // The code above could be merged into a couple of structures.
00081     // Yet g++-2.95 needs help so we first decompose Category<S>
00082     // into (Category, S) then we solve.
00083 
00084     template < template <class> class Category, typename S, typename T >
00085     struct helper_super_category_solve_
00086       :
00087       private metal::equal< typename Category<void>::super, void* >::check_t
00088     {
00089       // New case.
00090       typedef S ret;
00091     };
00092 
00093     template < template <class> class Category, typename T >
00094     struct helper_super_category_solve_< Category, void, T >
00095     {
00096       typedef typename Category<void>::super ret; // One super category: keep it.
00097     };
00098 
00099     template < typename Category, typename T >
00100     struct helper_super_category_;
00101 
00102     template < template <class> class Category, typename S, typename T >
00103     struct helper_super_category_< Category<S>, T > : helper_super_category_solve_< Category, S, T >
00104     {
00105     };
00106 
00107 
00108 
00109     // For bwd in-compatibility.
00110     template < template <class> class Category, typename T >
00111     struct helper_super_category_< Category<void*>, T >; 
00112 
00113 
00114     template < typename Category, typename T >
00115     struct super_category_ // Entry.
00116     {
00117       typedef typename helper_super_category_< Category, T >::ret ret;
00118     };
00119 
00120   } // end of namespace mln::internal
00121 
00122 
00123 } // end of namespace mln
00124 
00125 
00126 #endif // ! MLN_CORE_CATEGORY_HH

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