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

point_from_value.hh

00001 // Copyright (C) 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_HISTO_POINT_FROM_VALUE_HH
00027 # define MLN_HISTO_POINT_FROM_VALUE_HH
00028 
00032 
00033 # include <mln/core/grids.hh>
00034 # include <mln/core/point.hh>
00035 # include <mln/fun/v2i/index_of_value.hh>
00036 # include <mln/fun/v2v/component.hh>
00037 # include <mln/trait/value/comp.hh>
00038 
00039 
00040 # define mln_histo_point_type_from(T) typename mln::histo::point_type_from<T>::ret
00041 
00042 
00043 namespace mln
00044 {
00045 
00046   namespace histo
00047   {
00048 
00049 
00050     template <typename T>
00051     struct point_type_from
00052     {
00053     private:
00054       enum { d = mln_dim(T) };
00055       typedef mln_regular_grid_from_dim(d) G;
00056 
00057     public:
00058       typedef mln::point<G, def::coord> ret;
00059     };
00060 
00061 
00062     template <typename T>
00063     struct point_from_value : Function_v2v< point_from_value<T> >
00064     {
00065       typedef mln_histo_point_type_from(T) result;
00066       result operator()(const T& v) const;
00067     };
00068 
00069     template <typename T>
00070     mln_histo_point_type_from(T)
00071     meta_point_from_value(const T& v);
00072 
00073 
00074 # ifndef MLN_INCLUDE_ONLY
00075 
00076     namespace internal
00077     {
00078 
00079       template <unsigned d>
00080       struct point_from_value;
00081 
00082       template <>
00083       struct point_from_value< 1 >
00084       {
00085         template <typename T, typename P>
00086         static void run(const T& v, P& p)
00087         {
00088           p[0] = fun::v2i::meta_index_of_value(v);
00089         }
00090       };
00091 
00092       template <>
00093       struct point_from_value< 2 >
00094       {
00095         template <typename T, typename P>
00096         static void run(const T& v, P& p)
00097         {
00098           p[0] = fun::v2i::meta_index_of_value( fun::v2v::component<T,0>()(v) );
00099           p[1] = fun::v2i::meta_index_of_value( fun::v2v::component<T,1>()(v) );
00100         }
00101       };
00102 
00103       template <>
00104       struct point_from_value< 3 >
00105       {
00106         template <typename T, typename P>
00107         static void run(const T& v, P& p)
00108         {
00109           p[0] = fun::v2i::meta_index_of_value( fun::v2v::component<T,0>()(v) );
00110           p[1] = fun::v2i::meta_index_of_value( fun::v2v::component<T,1>()(v) );
00111           p[2] = fun::v2i::meta_index_of_value( fun::v2v::component<T,2>()(v) );
00112         }
00113       };
00114 
00115     } // end of namespace mln::histo::internal
00116 
00117 
00118     template <typename T>
00119     inline
00120     typename point_from_value<T>::result
00121     point_from_value<T>::operator()(const T& v) const
00122     {
00123       mln_histo_point_type_from(T) p;
00124       internal::point_from_value<mln_dim(T)>::run(v, p);
00125       return p;
00126     }
00127 
00128     template <typename T>
00129     mln_histo_point_type_from(T)
00130     meta_point_from_value(const T& v)
00131     {
00132       point_from_value<T> f;
00133       return f(v);
00134     }
00135 
00136 # endif // ! MLN_INCLUDE_ONLY
00137 
00138   } // end of namespace mln::histo
00139 
00140 } // end of namespace mln
00141 
00142 
00143 #endif // ! MLN_HISTO_POINT_FROM_VALUE_HH

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