$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
next/solve_unary.hh
1 // Copyright (C) 2006, 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_TRAIT_NEXT_SOLVE_UNARY_HH
27 # define MLN_TRAIT_NEXT_SOLVE_UNARY_HH
28 
37 # include <mln/core/category.hh>
38 # include <mln/core/routine/exact.hh>
39 # include <mln/metal/equal.hh>
40 # include <mln/metal/if.hh>
41 # include <mln/metal/ret.hh>
42 # include <mln/trait/next/solve.hh>
43 
44 
45 // FIXME: Just for the record (use it...)
46 
47 # ifndef MLN_DEBUG_TRAITS
48 # endif // ! MLN_DEBUG_TRAITS
49 
50 
51 
52 namespace mln
53 {
54 
55  namespace trait
56  {
57 
58  namespace next
59  {
60 
61  namespace internal
62  {
63 
64 
65  template < typename Name,
66  typename Category,
67  typename T >
68  struct trait_set_unary_;
69 
70  template < typename Name,
71  template <class> class Category, typename _,
72  typename T >
73  struct trait_set_unary_< Name, Category<_>, T >
74  {
76  };
77 
78 
79  // Fwd decls.
80  template < typename Name,
81  typename Category, typename T >
82  struct get_unary_;
83 
84 
85  template < typename user_ret, /* != not_found and != undefined */
86  typename Name,
87  typename Category, typename T >
88  struct helper_get_unary_
89  {
90  typedef user_ret ret; // The user has defined 'ret' so we return it.
91  };
92 
93 
94  template < typename Name,
95  typename Category, typename T >
96  struct helper_get_unary_< /* user_ret == */ not_found,
97  Name, Category, T >
98  {
99  typedef not_found ret; // End of search due to a blocker; 'ret' is not found.
100  };
101 
102 
103  template < typename Name,
104  typename Category, typename T >
105  struct helper_get_unary_< /* user_ret == */ undefined,
106  Name, Category, T >
107  {
108  typedef typename mln::internal::super_category_< Category, T >::ret Super_Category;
109  typedef typename get_unary_<Name, Super_Category, T>::ret ret; // No user ret definition => Recursion.
110  };
111 
112 
113  template < typename Name,
114  typename Category, typename T >
115  struct get_unary_
116  {
117  typedef typename trait_set_unary_<Name, Category, T>::ret user_ret; // First get 'user_ret'
118  typedef helper_get_unary_<user_ret, Name, Category, T> helper; // Set the helper to make a decision.
119  typedef mlc_ret(helper) ret; // Return.
120  };
121 
122 
123  template < typename precise_ret,
124  typename Name,
125  typename Category, typename T >
126  struct helper_choose_unary_wrt_ /* precise_ret != undefined */
127  {
128  typedef precise_ret ret; // -> A precise ret has been defined so it is it.
129  };
130 
131  template < typename Name,
132  typename Category, typename T >
133  struct helper_choose_unary_wrt_< /* precise_ret == */ undefined,
134  Name, Category, T >
135  {
136  typedef typename get_unary_<Name, Category, T>::ret ret; // -> Go up into the category inheritance
137  // to fetch a ret from 'set_unary_'s.
138  };
139 
140  template < typename Name,
141  typename Category, typename T >
142  struct helper_solve_unary_
143  {
144  typedef typename set_precise_unary_<Name, T>::ret precise_ret;
145  typedef helper_choose_unary_wrt_< precise_ret, /* undefined or not (?) */
146  Name, Category, T> helper;
147  typedef mlc_ret(helper) ret;
148  };
149 
150  } // end of namespace mln::trait::next::internal
151 
152 
153  template < typename Name,
154  typename T_ >
155  struct solve_unary
156  {
157  typedef mln_exact(T_) T;
158  typedef typename mln::category<T>::ret Category;
159  typedef internal::helper_solve_unary_< Name, Category, T > meta_code;
160  typedef typename meta_code::ret ret;
161  };
162 
163  } // end of namespace mln::trait::next
164 
165  } // end of namespace mln::trait
166 
167 } // end of namespace mln
168 
169 
170 #endif // ! MLN_TRAIT_NEXT_SOLVE_UNARY_HH