$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
category.hh
1 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_CORE_CATEGORY_HH
27 # define MLN_CORE_CATEGORY_HH
28 
32 
33 # include <mln/metal/equal.hh>
34 
35 
36 
37 namespace mln
38 {
39 
40  // FIXME: Doc!
41 
42 
43  template <typename E>
44  struct Unknown;
45 
46 
47  template <>
48  struct Unknown<void>
49  {
51  // Unknown is used to terminate the meta-program that solves a
52  // call to a trait. This meta-program can browse several branches
53  // at the same time---if the trait takes 2 types as arguments, the
54  // program runs over the trellis formed by the "couples of
55  // categories"--- and when the end of one branch is reached, we do
56  // not want the program to end; so it continues on that branch
57  // with the no-op "jump to the super type of Unknown"!
58  };
59 
60 
61  template <typename T>
62  struct category
63  {
64  typedef typename T::category ret; // FIXME: if found or Unknown<void> => write a meta-program...
65  };
66 
67  template <typename T>
68  struct category< const T >
69  {
70  typedef typename category<T>::ret ret;
71  };
72 
73 
74 
75  // Utility meta-function: from a category and a type, get the super category.
76 
77  namespace internal
78  {
79 
80  // The code above could be merged into a couple of structures.
81  // Yet g++-2.95 needs help so we first decompose Category<S>
82  // into (Category, S) then we solve.
83 
84  template < template <class> class Category, typename S, typename T >
85  struct helper_super_category_solve_
86  :
87  private metal::equal< typename Category<void>::super, void* >::check_t
88  {
89  // New case.
90  typedef S ret;
91  };
92 
93  template < template <class> class Category, typename T >
94  struct helper_super_category_solve_< Category, void, T >
95  {
96  typedef typename Category<void>::super ret; // One super category: keep it.
97  };
98 
99  template < typename Category, typename T >
100  struct helper_super_category_;
101 
102  template < template <class> class Category, typename S, typename T >
103  struct helper_super_category_< Category<S>, T > : helper_super_category_solve_< Category, S, T >
104  {
105  };
106 
107 
108 
109  // For bwd in-compatibility.
110  template < template <class> class Category, typename T >
111  struct helper_super_category_< Category<void*>, T >;
112 
113 
114  template < typename Category, typename T >
115  struct super_category_ // Entry.
116  {
117  typedef typename helper_super_category_< Category, T >::ret ret;
118  };
119 
120  } // end of namespace mln::internal
121 
122 
123 } // end of namespace mln
124 
125 
126 #endif // ! MLN_CORE_CATEGORY_HH