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

ch_value.hh

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development
00002 // Laboratory (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
00026 
00027 #ifndef MLN_TRAIT_CH_VALUE_HH
00028 # define MLN_TRAIT_CH_VALUE_HH
00029 
00033 
00034 # include <mln/tag/skeleton.hh>
00035 # include <mln/trait/image_from_grid.hh>
00036 # include <mln/trait/ch_function_value.hh>
00037 
00038 
00039 # define mln_ch_value(I, V)  typename mln::trait::ch_value< I, V >::ret
00040 # define mln_ch_value_(I, V)          mln::trait::ch_value< I, V >::ret
00041 
00042 
00043 
00044 namespace mln
00045 {
00046 
00047   // Forward declarations.
00048   namespace algebra { template <unsigned n, typename T> class vec; }
00049   template <typename G, typename F> class p_edges;
00050   template <typename G, typename F> class p_vertices;
00051   template <typename P, typename V, typename G> class vertex_image;
00052   template <typename P, typename V, typename G> class edge_image;
00053   template <typename I> class labeled_image;
00054   namespace pw { template <typename F, typename S> class image; }
00055 
00056 
00057 
00058   namespace trait
00059   {
00060 
00061     // Forward declaration.
00062     template <typename I, typename V> struct ch_value;
00063 
00064 
00065     namespace impl
00066     {
00067 
00068       // Declaration.
00069       template <typename I, typename V> struct ch_value_;
00070 
00071       template <typename I, typename V>
00072       struct ch_value_< tag::image_<I>,  V  >
00073       {
00074         typedef mln_ch_value(I, V) ret;
00075       };
00076 
00077       template < template <class> class M, typename T,
00078                  typename V >
00079       struct ch_value_<  M< tag::value_<T> >,  V  >
00080       {
00081         typedef M< V > ret;
00082       };
00083 
00084       template < template <class> class M, typename I,
00085                  typename V >
00086       struct ch_value_<  M< tag::image_<I> >,  V  >
00087       {
00088         typedef M< mln_ch_value(I, V) > ret;
00089       };
00090 
00091       template < template <class, class> class M, typename T, typename I,
00092                  typename V >
00093       struct ch_value_<  M< tag::value_<T>, tag::image_<I> >,  V  >
00094       {
00095         typedef mln_ch_value(I, V) ret;
00096       };
00097 
00098       template < template <class, class> class M, typename P, typename T,
00099                  typename V >
00100       struct ch_value_<  M< tag::psite_<P>, tag::value_<T> >,  V  >
00101       {
00102         typedef M< P, V > ret;
00103       };
00104 
00105       template < template <class, class> class M, typename I1, typename I2,
00106                  typename V >
00107       struct ch_value_<  M< tag::image_<I1>, tag::image_<I2> >,  V  >
00108       {
00109         typedef M< mln_ch_value(I1, V), mln_ch_value(I2, V) > ret;
00110       };
00111 
00112       template < template <class, class> class M, typename I, typename E,
00113                  typename V >
00114       struct ch_value_<  M< tag::image_<I>, tag::ext_<E> >,  V  >
00115       {
00116         typedef M< mln_ch_value(I, V), E > ret;
00117       };
00118 
00119 //<<lrde
00120       // For mln::value::stack_image<n,I>.
00121       template < template <unsigned, class> class M, unsigned n, typename I,
00122                  typename V >
00123       struct ch_value_<  M< n, tag::image_<I> >,  V  >
00124       {
00125         /* FIXME: The code used to read
00126 
00127              typedef algebra::vec<n, V> value;
00128              typedef mln_ch_value(I, value) ret;
00129 
00130            here.  But this is wrong IMHO (Roland).  Changing the value
00131            type of a stack image (in fact, a vectorial image) shall
00132            alter the *value type* of the image, not the type of the
00133            *components* of the vector.  Hence the current definition.  */
00134         typedef mln_ch_value(I, V) ret;
00135       };
00136 //>>
00137 
00138       // For mln::complex_image<D, G, T>.
00139       template < template <unsigned, class, class> class M,
00140                  unsigned D, typename G, typename T, typename V >
00141       struct ch_value_<  M< D, tag::psite_<G>, tag::value_<T> >,  V  >
00142       {
00143         typedef M< D, G, V > ret;
00144       };
00145 
00146       // For mln::neighb::image<I, N>.
00147       template < template <class, class> class M, typename I, typename N,
00148                  typename V >
00149       struct ch_value_<  M< tag::image_<I>, tag::neighb_<N> >,  V  >
00150       {
00151         typedef M < mln_ch_value(I, V), N > ret;
00152       };
00153 
00154       template < template <class, class> class M, typename I, typename S,
00155                  typename V >
00156       struct ch_value_<  M< tag::image_<I>, tag::domain_<S> >,  V  >
00157       {
00158         typedef M< mln_ch_value(I, V), S > ret;
00159       };
00160 
00161       template < template <class, class> class M, typename F, typename S,
00162                  typename V >
00163       struct ch_value_<  M< tag::function_<F>, tag::domain_<S> >,  V  >
00164       {
00165         // FIXME: what about S::site having no grid?
00166         typedef mln_deduce(S, site, grid) grid;
00167         typedef typename image_from_grid< grid, V >::ret ret;
00168       };
00169 
00170 
00171       // Graph image based on p_edges
00172       template < typename F,
00173                  typename G, typename FP,
00174                  typename V >
00175       struct ch_value_<  pw::image< tag::function_<F>, tag::domain_<p_edges<G, FP> > >,  V  >
00176       {
00177         typedef pw::image< mln_ch_function_value(F, V), p_edges<G, FP> > ret;
00178       };
00179 
00180       // Graph image based on p_vertices
00181       template < typename F,
00182                  typename G, typename FP,
00183                  typename V >
00184       struct ch_value_<  pw::image< tag::function_<F>, tag::domain_<p_vertices<G, FP> > >,  V  >
00185 
00186       {
00187         typedef pw::image< mln_ch_function_value(F, V), p_vertices<G, FP> > ret;
00188       };
00189 
00190       // Vertex Image
00191       template < typename P, typename V1, typename G, typename V2>
00192       struct ch_value_< vertex_image< tag::psite_<P>,
00193                                       tag::value_<V1>,
00194                                       tag::graph_<G> >,
00195                         V2 >
00196       {
00197         typedef vertex_image< P, V2, G > ret;
00198       };
00199 
00200       // Edge Image
00201       template < typename P, typename V1, typename G, typename V2>
00202       struct ch_value_< edge_image< tag::psite_<P>,
00203                                     tag::value_<V1>,
00204                                     tag::graph_<G> >,
00205                         V2 >
00206       {
00207         typedef edge_image< P, V2, G > ret;
00208       };
00209 
00210       // Labeled image
00211       template < typename I, typename V>
00212       struct ch_value_< labeled_image< tag::image_<I> >,
00213                         V >
00214       {
00215         typedef mln_ch_value(I,V) ret;
00216       };
00217 
00218 
00219       template < template <class, class> class M, typename T, typename S,
00220                  typename V >
00221       struct ch_value_<  M< tag::value_<T>, tag::domain_<S> >,  V  >
00222       {
00223         // FIXME: what about S::site having no grid?
00224         typedef mln_deduce(S, site, grid) grid;
00225         typedef typename image_from_grid< grid, V >::ret ret;
00226       };
00227 
00228 
00229       template < template <class, class> class M, typename I, typename F,
00230                  typename V >
00231       struct ch_value_<  M< tag::image_<I>, tag::function_<F> >,  V  >
00232       {
00233         typedef M< mln_ch_value(I, V), F > ret;
00234       };
00235 
00236     } // end of namespace mln::trait::impl
00237 
00238 
00239     template <typename I, typename V>
00240     struct ch_value
00241     {
00242       typedef typename I::skeleton skeleton;
00243       typedef typename impl::ch_value_<skeleton, V>::ret ret;
00244     };
00245 
00246   } // end of namespace mln::trait
00247 
00248 } // end of namespace mln
00249 
00250 
00251 #endif // ! MLN_TRAIT_CH_VALUE_HH

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