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

memset_.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_MEMSET__HH
00027 # define MLN_DATA_MEMSET__HH
00028 
00032 
00033 # include <cstring>
00034 
00035 # include <mln/core/concept/image.hh>
00036 # include <mln/core/pixel.hh>
00037 # include <mln/metal/is_not_const.hh>
00038 # include <mln/opt/element.hh>
00039 
00040 
00041 
00042 namespace mln
00043 {
00044 
00045   namespace data
00046   {
00047 
00058     template <typename P>
00059     void memset_(Generalized_Pixel<P>& pix,
00060                  const mln_value(P)& v, std::size_t n);
00061 
00074     template <typename I>
00075     void memset_(I& input, const mln_psite(I)& p,
00076                  const mln_value(I)& v, std::size_t n);
00077 
00078 
00079 # ifndef MLN_INCLUDE_ONLY
00080 
00081     namespace impl
00082     {
00083 
00084       template <typename P>
00085       inline
00086       void memset__(P& pix, const mln_value(P)& v, std::size_t n)
00087       {
00088         trace::entering("data::impl::memset_");
00089 
00090         typedef mln_image(P) I;
00091         if (n == 0)
00092           {
00093             return; // no-op
00094           }
00095 
00096         if (n == 1)
00097           {
00098             pix.val() = v; // one assignment
00099             return;
00100           }
00101 
00102         if (sizeof(mln_value(I)) == 1)
00103           {
00104             std::memset((void*)(& pix.val()),
00105                         *(const int*)(&v), // violent cast
00106                         n);
00107           }
00108         else
00109           {
00110             mln_value(I)* ptr = & pix.val();
00111             for (std::size_t i = 0; i < n; ++i)
00112               *ptr++ = v;
00113           }
00114 
00115         trace::exiting("data::impl::memset_");
00116       }
00117 
00118     } // end of namespace mln::data::impl
00119 
00120 
00121     template <typename P>
00122     inline
00123     void memset_(Generalized_Pixel<P>& pix_,
00124                  const mln_value(P)& v, std::size_t n)
00125     {
00126       trace::entering("data::memset_");
00127 
00128       typedef mln_image(P) I;
00129       metal::is_not_const<I>::check();
00130 
00131       P& pix = mln::internal::force_exact<P>(pix_);
00132       mln_precondition(pix.ima().is_valid());
00133       mln_precondition(& pix.val() >= & pix.ima()[0]);
00134       mln_precondition(& pix.val() < & pix.ima()[0] +
00135                        opt::nelements(pix.ima()));
00136       mln_precondition(& pix.val() + n <= & pix.ima()[0] +
00137                        opt::nelements(pix.ima()));
00138 
00139       impl::memset__(pix, v, n);
00140 
00141       trace::exiting("data::memset_");
00142     }
00143 
00144     template <typename I>
00145     inline
00146     void memset_(I& input, const mln_psite(I)& p,
00147                  const mln_value(I)& v, std::size_t n)
00148     {
00149       trace::entering("data::memset_");
00150 
00151       mlc_is(mln_trait_image_speed(I), trait::image::speed::fastest)::check();
00152 
00153       mln_precondition(input.is_valid());
00154       mln_precondition(input.has(p));
00155       mln_precondition(input.index_of_point(p) + n <= opt::nelements(input));
00156 
00157       pixel<I> pix(input, p);
00158       impl::memset__(pix, v, n);
00159 
00160       trace::exiting("data::memset_");
00161     }
00162 
00163 # endif // ! MLN_INCLUDE_ONLY
00164 
00165   } // end of namespace mln::data
00166 
00167 } // end of namespace mln
00168 
00169 
00170 #endif // ! MLN_DATA_MEMSET__HH

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