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