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

fill.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_FILL_HH
00027 # define MLN_DATA_FILL_HH
00028 
00034 
00035 # include <mln/core/concept/function.hh>
00036 # include <mln/pw/image.hh>
00037 # include <mln/convert/to_fun.hh>
00038 
00039 # include <mln/data/fill_with_image.hh>
00040 # include <mln/data/fill_with_value.hh>
00041 
00042 
00043 namespace mln
00044 {
00045 
00046   namespace data
00047   {
00048 
00056     template <typename I, typename D>
00057     void fill(Image<I>& ima, const D& data);
00058 
00059 
00060 
00061 # ifndef MLN_INCLUDE_ONLY
00062 
00063     namespace internal
00064     {
00065 
00066       // tests
00067 
00068       template <typename I, typename D>
00069       inline
00070       void fill_tests(Image<I>& ima, const D&)
00071       {
00072         // Avoid a warning about an undefined variable when NDEBUG
00073         // is not defined.
00074         (void) ima;
00075 
00076         mlc_is(mln_trait_image_value_io(I), trait::image::value_io::read_write)::check();
00077         mln_precondition(exact(ima).is_valid());
00078         // FIXME: check for ambiguities...
00079       }
00080 
00081       // dispatch
00082 
00083       template <typename I, typename D>
00084       void fill_dispatch(Image<I>& ima, const D& data)
00085       {
00086         fill_dispatch_overload(exact(ima), exact(data));
00087       }
00088 
00089       // dispatch_overload
00090 
00091       template <typename I>
00092       void fill_dispatch_overload(I& ima, const mln_value(I)& v)
00093       {
00094         mln::data::fill_with_value(ima, v);
00095       }
00096 
00097       template <typename I, typename J>
00098       void fill_dispatch_overload(I& ima, const Image<J>& data)
00099       {
00100         mln::data::fill_with_image(ima, data);
00101       }
00102 
00103       template <typename I, typename F>
00104       void fill_dispatch_overload(I& ima, const Function<F>& f)
00105       {
00106         mlc_converts_to(mln_result(F), mln_value(I))::check();
00107         mln::data::fill_with_image(ima,
00108                                     exact(f) | ima.domain());
00109       }
00110 
00111       template <typename I, typename R, typename A>
00112       void fill_dispatch_overload(I& ima, R (*f)(A))
00113       {
00114         mlc_converts_to(R, mln_value(I))::check();
00115         mln::data::fill_with_image(ima,
00116                                     convert::to_fun(f) | ima.domain());
00117       }
00118 
00119       template <typename I, typename V, unsigned N>
00120       void fill_dispatch_overload(I& ima, V (&arr)[N])
00121       {
00122         mlc_converts_to(V, mln_value(I))::check();
00123         mln_precondition(N == ima.nsites());
00124         mln_fwd_piter(I) p(ima.domain());
00125         unsigned i = 0;
00126         for_all(p)
00127           ima(p) = arr[i++];
00128       }
00129 
00130     } // end of namespace mln::data::internal
00131 
00132 
00133     // Facade.
00134 
00135     template <typename I, typename D>
00136     inline
00137     void fill(Image<I>& ima, const D& data)
00138     {
00139       trace::entering("data::fill");
00140 
00141       internal::fill_tests(ima, data);
00142       internal::fill_dispatch(ima, data);
00143 
00144       trace::exiting("data::fill");
00145     }
00146 
00147 
00148 # endif // ! MLN_INCLUDE_ONLY
00149 
00150   } // end of namespace mln::data
00151 
00152 } // end of namespace mln
00153 
00154 
00155 #endif // ! MLN_DATA_FILL_HH

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