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

element.hh

00001 // Copyright (C) 2009, 2010 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_OPT_ELEMENT_HH
00027 # define MLN_OPT_ELEMENT_HH
00028 
00032 
00033 # include <mln/core/concept/image.hh>
00034 # include <mln/trait/images.hh>
00035 
00036 namespace mln
00037 {
00038 
00039   namespace opt
00040   {
00041 
00042     template <typename I>
00043     inline
00044     mln_rvalue(I) element(const Image<I>& ima, unsigned index);
00045 
00046     template <typename I>
00047     inline
00048     mln_lvalue(I) element(Image<I>& ima, unsigned index);
00049 
00050     template <typename I>
00051     inline
00052     unsigned nelements(const Image<I>& ima);
00053 
00054 
00055 # ifndef MLN_INCLUDE_ONLY
00056 
00057     namespace impl
00058     {
00059 
00060       template <typename I>
00061       inline
00062       mln_rvalue(I) element_impl(trait::image::category::domain_morpher,
00063                                  const Image<I>& ima, unsigned /* index */)
00064       {
00065         return element(*exact(ima).delegatee_());
00066       }
00067 
00068       template <typename I>
00069       inline
00070       mln_rvalue(I) element_impl(trait::image::category::any,
00071                                  const Image<I>& ima, unsigned index)
00072       {
00073         mlc_and(mlc_is(mln_trait_image_value_storage(I),
00074                        trait::image::value_storage::one_block),
00075                 mlc_is(mln_trait_image_value_access(I),
00076                        trait::image::value_access::direct))::check();
00077 
00078         return exact(ima).element(index);
00079       }
00080 
00081 
00082       template <typename I>
00083       inline
00084       mln_lvalue(I) element_impl(trait::image::category::domain_morpher,
00085                                  Image<I>& ima, unsigned /* index */)
00086       {
00087         return element(*exact(ima).delegatee_());
00088       }
00089 
00090       template <typename I>
00091       inline
00092       mln_lvalue(I) element_impl(trait::image::category::any,
00093                                  Image<I>& ima, unsigned index)
00094       {
00095         mlc_and(mlc_is(mln_trait_image_value_storage(I),
00096                        trait::image::value_storage::one_block),
00097                 mlc_is(mln_trait_image_value_access(I),
00098                        trait::image::value_access::direct))::check();
00099 
00100         return exact(ima).element(index);
00101       }
00102 
00103 
00104 
00105 
00106       template <typename I>
00107       inline
00108       unsigned nelements_impl(trait::image::category::domain_morpher,
00109                               const Image<I>& ima)
00110       {
00111         return nelements(*exact(ima).delegatee_());
00112       }
00113 
00114       template <typename I>
00115       inline
00116       unsigned nelements_impl(trait::image::category::any,
00117                               const Image<I>& ima)
00118       {
00119         mlc_is(mln_trait_image_value_storage(I),
00120                trait::image::value_storage::one_block)::check();
00121 
00122         return exact(ima).nelements();
00123       }
00124 
00125 
00126 
00127 
00128 
00129 
00130     } // end of namespace mln::opt::impl
00131 
00132 
00133     template <typename I>
00134     inline
00135     mln_rvalue(I) element(const Image<I>& ima, unsigned index)
00136     {
00137       return impl::element_impl(mln_trait_image_category(I)(), ima, index);
00138     }
00139 
00140     template <typename I>
00141     inline
00142     mln_lvalue(I) element(Image<I>& ima, unsigned index)
00143     {
00144       return impl::element_impl(mln_trait_image_category(I)(), ima, index);
00145     }
00146 
00147 
00148     template <typename I>
00149     inline
00150     unsigned nelements(const Image<I>& ima)
00151     {
00152       return impl::nelements_impl(mln_trait_image_category(I)(), ima);
00153     }
00154 
00155 # endif // ! MLN_INCLUDE_ONLY
00156 
00157   } // end of namespace mln::opt
00158 
00159 } // end of namespace mln
00160 
00161 
00162 #endif // ! MLN_OPT_ELEMENT_HH

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