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

fill_with_value.hh

00001 // Copyright (C) 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_FILL_WITH_VALUE_HH
00027 # define MLN_DATA_FILL_WITH_VALUE_HH
00028 
00037 
00038 # include <cstdlib>
00039 
00040 # include <mln/core/concept/image.hh>
00041 
00042 
00043 
00044 // Specializations are in:
00045 # include <mln/data/fill_with_value.spe.hh>
00046 
00047 
00048 namespace mln
00049 {
00050 
00051   namespace data
00052   {
00053 
00062     template <typename I, typename V>
00063     void fill_with_value(Image<I>& ima, const V& val);
00065 
00066 
00067 
00068 # ifndef MLN_INCLUDE_ONLY
00069 
00070     namespace internal
00071     {
00072 
00073       template <typename I, typename V>
00074       inline
00075       void fill_with_value_tests(Image<I>& ima, const V&)
00076       {
00077         mlc_converts_to(mln_exact(V), mln_value(I))::check();
00078         mln_precondition(exact(ima).is_valid());
00079 
00080         // Avoid a warning about an undefined variable when NDEBUG
00081         (void) ima;
00082       }
00083 
00084     } // end of namespace mln::data::internal
00085 
00086 
00087     namespace impl
00088     {
00089 
00090       namespace generic
00091       {
00092 
00100         //
00101         template <typename I, typename V>
00102         void fill_with_value(Image<I>& ima_, const V& val)
00103         {
00104           trace::entering("data::impl::generic::fill_with_value");
00105 
00106           I& ima = exact(ima_);
00107 
00108           internal::fill_with_value_tests(ima, val);
00109           mlc_is(mln_trait_image_pw_io(I),
00110                  trait::image::pw_io::read_write)::check();
00111 
00112           mln_value(I) v = static_cast<mln_value(I)>(exact(val));
00113           mln_piter(I) p(ima.domain());
00114           for_all(p)
00115             ima(p) = v;
00116 
00117           trace::exiting("data::impl::generic::fill_with_value");
00118         }
00119 
00120       } // end if namespace mln::data::impl::generic
00121 
00122     } // end of namespace mln::data::impl
00123 
00124 
00125     // Facade.
00126 
00127     template <typename I, typename V>
00128     inline
00129     void fill_with_value(Image<I>& ima, const V& val)
00130     {
00131       trace::entering("data::fill_with_value");
00132 
00133       internal::fill_with_value_tests(ima, val);
00134       internal::fill_with_value_dispatch(ima, val);
00135 
00136       trace::exiting("data::fill_with_value");
00137     }
00138 
00139 
00140 # endif // ! MLN_INCLUDE_ONLY
00141 
00142   } // end of namespace mln::data
00143 
00144 } // end of namespace mln
00145 
00146 
00147 #endif // ! MLN_DATA_FILL_WITH_VALUE_HH

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