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

fill.hh

00001 // Copyright (C) 2007, 2008, 2009, 2010 EPITA Research and Development
00002 // Laboratory (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
00026 
00027 #ifndef MLN_DATA_FILL_HH
00028 # define MLN_DATA_FILL_HH
00029 
00035 
00036 # include <mln/core/concept/function.hh>
00037 # include <mln/pw/image.hh>
00038 # include <mln/convert/to_fun.hh>
00039 
00040 # include <mln/data/fill_with_image.hh>
00041 # include <mln/data/fill_with_value.hh>
00042 
00043 
00044 namespace mln
00045 {
00046 
00047   namespace data
00048   {
00049 
00057     template <typename I, typename D>
00058     void fill(Image<I>& ima, const D& data);
00059 
00060 
00061 
00062 # ifndef MLN_INCLUDE_ONLY
00063 
00064     namespace internal
00065     {
00066 
00067       // tests
00068 
00069       template <typename I, typename D>
00070       inline
00071       void fill_tests(Image<I>& ima, const D&)
00072       {
00073         // Avoid a warning about an undefined variable when NDEBUG
00074         // is not defined.
00075         (void) ima;
00076 
00077         mlc_is(mln_trait_image_value_io(I), trait::image::value_io::read_write)::check();
00078         mln_precondition(exact(ima).is_valid());
00079         // FIXME: check for ambiguities...
00080       }
00081 
00082       // dispatch_overload
00083 
00084       template <typename I>
00085       void fill_dispatch_overload(I& ima, const mln_value(I)& v)
00086       {
00087         mln::data::fill_with_value(ima, v);
00088       }
00089 
00090       template <typename I, typename J>
00091       void fill_dispatch_overload(I& ima, const Image<J>& data)
00092       {
00093         mln::data::fill_with_image(ima, data);
00094       }
00095 
00096       template <typename I, typename F>
00097       void fill_dispatch_overload(I& ima, const Function<F>& f)
00098       {
00099         mlc_converts_to(mln_result(F), mln_value(I))::check();
00100         mln::data::fill_with_image(ima,
00101                                     exact(f) | ima.domain());
00102       }
00103 
00104       template <typename I, typename R, typename A>
00105       void fill_dispatch_overload(I& ima, R (*f)(A))
00106       {
00107         mlc_converts_to(R, mln_value(I))::check();
00108         mln::data::fill_with_image(ima,
00109                                     convert::to_fun(f) | ima.domain());
00110       }
00111 
00112       template <typename I, typename V, unsigned N>
00113       void fill_dispatch_overload(I& ima, V (&arr)[N])
00114       {
00115         mlc_converts_to(V, mln_value(I))::check();
00116         mln_precondition(N == ima.nsites());
00117         mln_fwd_piter(I) p(ima.domain());
00118         unsigned i = 0;
00119         for_all(p)
00120           ima(p) = arr[i++];
00121       }
00122 
00123       // dispatch
00124 
00125       template <typename I, typename D>
00126       void fill_dispatch(Image<I>& ima, const D& data)
00127       {
00128         fill_dispatch_overload(exact(ima), exact(data));
00129       }
00130 
00131     } // end of namespace mln::data::internal
00132 
00133 
00134     // Facade.
00135 
00136     template <typename I, typename D>
00137     inline
00138     void fill(Image<I>& ima, const D& data)
00139     {
00140       trace::entering("data::fill");
00141 
00142       internal::fill_tests(ima, data);
00143       internal::fill_dispatch(ima, data);
00144 
00145       trace::exiting("data::fill");
00146     }
00147 
00148 
00149 # endif // ! MLN_INCLUDE_ONLY
00150 
00151   } // end of namespace mln::data
00152 
00153 } // end of namespace mln
00154 
00155 
00156 #endif // ! MLN_DATA_FILL_HH

Generated on Tue Oct 4 2011 15:23:46 for Milena (Olena) by  doxygen 1.7.1