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