27 #ifndef MLN_DATA_MEMCPY__HH
28 # define MLN_DATA_MEMCPY__HH
37 # include <mln/core/concept/image.hh>
38 # include <mln/core/pixel.hh>
39 # include <mln/metal/is_not_const.hh>
40 # include <mln/opt/element.hh>
65 template <
typename Pd,
typename Ps>
66 void memcpy_(Generalized_Pixel<Pd>& dest,
const Generalized_Pixel<Ps>& src,
70 # ifndef MLN_INCLUDE_ONLY
75 template <
typename Pd,
typename Ps>
77 void memcpy__(Pd& dest,
const Ps& src, std::size_t n)
81 typedef mln_image(Pd) Id;
82 typedef mln_image(Ps) Is;
88 dest.val() = src.val();
103 if (
sizeof(mln_value(Id)) == 1)
105 std::memcpy((
void*) (&dest.val()),
106 (
const void*) (&src.val()),
111 mln_value(Id)* p_d = &dest.val();
112 const mln_value(Is)* p_s = &src.val();
113 for (std::size_t i = 0; i < n; ++i)
122 template <
typename Pd,
typename Ps>
124 void memcpy_(Generalized_Pixel<Pd>& dest_,
125 const Generalized_Pixel<Ps>& src_,
130 typedef mln_image(Pd) Id;
131 metal::is_not_const<Id>::check();
132 typedef mln_image(Ps) Is;
133 Pd& dest = mln::internal::force_exact<Pd>(dest_);
134 Ps& src = mln::internal::force_exact<Ps>(src_);
136 mln_precondition(sizeof(mln_value(Id)) == sizeof(mln_value(Is)));
137 mln_precondition(dest.ima().is_valid());
138 mln_precondition(src.ima().is_valid());
140 mln_precondition(&dest.val() >= &opt::element(dest.ima(), 0));
141 mln_precondition(&dest.val() < &opt::element(dest.ima(), 0) +
142 opt::nelements(dest.ima()));
144 mln_precondition(&dest.val() + n <= &opt::element(dest.ima(), 0) +
145 opt::nelements(dest.ima()));
147 mln_precondition(&src.val() >= &opt::element(src.ima(), 0));
148 mln_precondition(&src.val() < &opt::element(src.ima(), 0) +
149 opt::nelements(src.ima()));
150 mln_precondition(&src.val() + n <= &opt::element(src.ima(), 0) +
151 opt::nelements(src.ima()));
153 impl::memcpy__(dest, src, n);
158 # endif // ! MLN_INCLUDE_ONLY
165 #endif // ! MLN_DATA_MEMCPY__HH