00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
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 )
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 )
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     } 
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   } 
00158 
00159 } 
00160 
00161 
00162 #endif // ! MLN_OPT_ELEMENT_HH