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_DATA_MEMCPY__HH
00028 # define MLN_DATA_MEMCPY__HH
00029
00035
00036 # include <cstring>
00037 # include <mln/core/concept/image.hh>
00038 # include <mln/core/pixel.hh>
00039 # include <mln/metal/is_not_const.hh>
00040 # include <mln/opt/element.hh>
00041
00042
00043
00044 namespace mln
00045 {
00046
00047 namespace data
00048 {
00049
00065 template <typename Pd, typename Ps>
00066 void memcpy_(Generalized_Pixel<Pd>& dest, const Generalized_Pixel<Ps>& src,
00067 std::size_t n);
00068
00069
00070 # ifndef MLN_INCLUDE_ONLY
00071
00072 namespace impl
00073 {
00074
00075 template <typename Pd, typename Ps>
00076 inline
00077 void memcpy__(Pd& dest, const Ps& src, std::size_t n)
00078 {
00079
00080
00081 typedef mln_image(Pd) Id;
00082 typedef mln_image(Ps) Is;
00083 if (n == 0)
00084 return;
00085
00086 if (n == 1)
00087 {
00088 dest.val() = src.val();
00089 return;
00090 }
00091
00092
00093
00094
00095
00096
00097 #if defined(__GNUC__) && defined(__GNUC_MINOR__)
00098 # if __GNUC__ == 4 && __GNUC_MINOR__ == 2
00099 # warning The code generated by g++ 4.2 on Debian GNU/Linux 5.0 for IA-32 for this function might be wrong.
00100 # endif
00101 #endif
00102 if (sizeof(mln_value(Id)) == 1)
00103 {
00104 std::memcpy((void*) (&dest.val()),
00105 (const void*) (&src.val()),
00106 n);
00107 }
00108 else
00109 {
00110 mln_value(Id)* p_d = &dest.val();
00111 const mln_value(Is)* p_s = &src.val();
00112 for (std::size_t i = 0; i < n; ++i)
00113 *p_d++ = *p_s++;
00114 }
00115
00116
00117 }
00118
00119 }
00120
00121 template <typename Pd, typename Ps>
00122 inline
00123 void memcpy_(Generalized_Pixel<Pd>& dest_,
00124 const Generalized_Pixel<Ps>& src_,
00125 std::size_t n)
00126 {
00127
00128
00129 typedef mln_image(Pd) Id;
00130 metal::is_not_const<Id>::check();
00131 typedef mln_image(Ps) Is;
00132 Pd& dest = mln::internal::force_exact<Pd>(dest_);
00133 Ps& src = mln::internal::force_exact<Ps>(src_);
00134
00135 mln_precondition(sizeof(mln_value(Id)) == sizeof(mln_value(Is)));
00136 mln_precondition(dest.ima().is_valid());
00137 mln_precondition(src.ima().is_valid());
00138
00139 mln_precondition(&dest.val() >= &opt::element(dest.ima(), 0));
00140 mln_precondition(&dest.val() < &opt::element(dest.ima(), 0) +
00141 opt::nelements(dest.ima()));
00142
00143 mln_precondition(&dest.val() + n <= &opt::element(dest.ima(), 0) +
00144 opt::nelements(dest.ima()));
00145
00146 mln_precondition(&src.val() >= &opt::element(src.ima(), 0));
00147 mln_precondition(&src.val() < &opt::element(src.ima(), 0) +
00148 opt::nelements(src.ima()));
00149 mln_precondition(&src.val() + n <= &opt::element(src.ima(), 0) +
00150 opt::nelements(src.ima()));
00151
00152 impl::memcpy__(dest, src, n);
00153
00154
00155 }
00156
00157 # endif // ! MLN_INCLUDE_ONLY
00158
00159 }
00160
00161 }
00162
00163
00164 #endif // ! MLN_DATA_MEMCPY__HH