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

memcpy_.hh

00001 // Copyright (C) 2007, 2008, 2009 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_DATA_MEMCPY__HH
00027 # define MLN_DATA_MEMCPY__HH
00028 
00034 
00035 # include <cstring>
00036 # include <mln/core/concept/image.hh>
00037 # include <mln/core/pixel.hh>
00038 # include <mln/metal/is_not_const.hh>
00039 # include <mln/opt/element.hh>
00040 
00041 
00042 
00043 namespace mln
00044 {
00045 
00046   namespace data
00047   {
00048 
00064     template <typename Pd, typename Ps>
00065     void memcpy_(Generalized_Pixel<Pd>& dest, const Generalized_Pixel<Ps>& src,
00066                  std::size_t n);
00067 
00068 
00069 # ifndef MLN_INCLUDE_ONLY
00070 
00071     namespace impl
00072     {
00073 
00074       template <typename Pd, typename Ps>
00075       inline
00076       void memcpy__(Pd& dest, const Ps& src, std::size_t n)
00077       {
00078         // trace::entering("data::impl::memcpy__");
00079 
00080         typedef mln_image(Pd) Id;
00081         typedef mln_image(Ps) Is;
00082         if (n == 0)
00083           return; // no-op
00084 
00085         if (n == 1)
00086         {
00087           dest.val() = src.val(); // one assignment
00088           return;
00089         }
00090 
00091         if (sizeof(mln_value(Id)) == 1)
00092         {
00093           std::memcpy((void*) (&dest.val()), // violent casts
00094                       (const void*) (&src.val()),
00095                       n);
00096         }
00097         else
00098         {
00099           mln_value(Id)* p_d = &dest.val();
00100           const mln_value(Is)* p_s = &src.val();
00101           for (std::size_t i = 0; i < n; ++i)
00102             *p_d++ = *p_s++;
00103         }
00104 
00105         // trace::exiting("data::impl::memcpy__");
00106       }
00107 
00108     }
00109 
00110     template <typename Pd, typename Ps>
00111     inline
00112     void memcpy_(Generalized_Pixel<Pd>& dest_,
00113                  const Generalized_Pixel<Ps>& src_,
00114                  std::size_t n)
00115     {
00116       // trace::entering("data::memcpy_");
00117 
00118       typedef mln_image(Pd) Id;
00119       metal::is_not_const<Id>::check();
00120       typedef mln_image(Ps) Is;
00121       Pd& dest = mln::internal::force_exact<Pd>(dest_);
00122       Ps& src  = mln::internal::force_exact<Ps>(src_);
00123 
00124       mln_precondition(sizeof(mln_value(Id)) == sizeof(mln_value(Is)));
00125       mln_precondition(dest.ima().is_valid());
00126       mln_precondition(src.ima().is_valid());
00127 
00128       mln_precondition(&dest.val() >= &opt::element(dest.ima(), 0));
00129       mln_precondition(&dest.val() < &opt::element(dest.ima(), 0) +
00130                        opt::nelements(dest.ima()));
00131 
00132       mln_precondition(&dest.val() + n <= &opt::element(dest.ima(), 0) +
00133                        opt::nelements(dest.ima()));
00134 
00135       mln_precondition(&src.val() >= &opt::element(src.ima(), 0));
00136       mln_precondition(&src.val() < &opt::element(src.ima(), 0) +
00137                        opt::nelements(src.ima()));
00138       mln_precondition(&src.val() + n <= &opt::element(src.ima(), 0) +
00139                        opt::nelements(src.ima()));
00140 
00141       impl::memcpy__(dest, src, n);
00142 
00143       // trace::exiting("data::memcpy_");
00144     }
00145 
00146 # endif // ! MLN_INCLUDE_ONLY
00147 
00148   } // end of namespace mln::data
00149 
00150 } // end of namespace mln
00151 
00152 
00153 #endif // ! MLN_DATA_MEMCPY__HH

Generated on Thu Sep 8 2011 18:32:07 for Milena (Olena) by  doxygen 1.7.1