Milena (Olena)  User documentation 2.0a Id
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_EXTENSION_FILL_HH
00027 # define MLN_EXTENSION_FILL_HH
00028 
00035 
00036 # include <mln/core/concept/image.hh>
00037 # include <mln/trait/image/props.hh>
00038 # include <mln/border/fill.hh>
00039 # include <mln/data/fill_with_value.hh>
00040 
00041 
00042 namespace mln
00043 {
00044 
00045   namespace extension
00046   {
00047 
00058     template <typename I>
00059     void fill(const Image<I>& ima, const mln_value(I)& val);
00060 
00061 
00062 # ifndef MLN_INCLUDE_ONLY
00063 
00064 
00065     namespace internal
00066     {
00067 
00068       // Do it.
00069 
00070       template <typename I>
00071       void do_fill(I& ima, const mln_value(I)& val); // Entry point.
00072 
00073       template <typename I>
00074       void do_fill(mln::trait::image::ext_domain::some,
00075                    mln::trait::image::ext_value::single,
00076                    mln::trait::image::ext_domain::none,
00077                    I& ima, const mln_value(I)& val)
00078       {
00079         ima.change_extension(val);
00080       }
00081 
00082       template <typename I>
00083       void do_fill(mln::trait::image::ext_domain::some,
00084                    mln::trait::image::ext_value::multiple,
00085                    mln::trait::image::ext_domain::none,
00086                    I& ima, const mln_value(I)& val)
00087       {
00088         border::fill(ima, val);
00089         ima.change_extension(val);
00090       }
00091 
00092       template <typename I>
00093       void do_fill(mln::trait::image::ext_domain::some,
00094                    mln::trait::image::ext_value::any,
00095                    mln::trait::image::ext_domain::some,
00096                    I& ima, const mln_value(I)& val)
00097       {
00098         mln::extension::fill(ima.unmorph_(), val);
00099       }
00100 
00101       template <typename I>
00102       void do_fill(mln::trait::image::ext_domain::none,
00103                    mln::trait::image::ext_value::any,
00104                    mln::trait::image::ext_domain::any,
00105                    I& ima, const mln_value(I)& val)
00106       {
00107         (void) ima;
00108         (void) val;
00109         // Oops...
00110       }
00111 
00112       template <typename I>
00113       void do_fill(I& ima, const mln_value(I)& val)
00114       {
00115         typedef typename I::delegatee D;
00116         do_fill(mln_trait_image_ext_domain(I)(),
00117                 mln_trait_image_ext_value(I)(),
00118                 mln_trait_image_ext_domain(D)(),
00119                 ima, val);
00120       }
00121 
00122 
00123 
00124       // Dispatch.
00125 
00126       template <typename I>
00127       void fill_dispatch(mln::trait::image::ext_domain::none,
00128                          mln::trait::image::ext_io::any,
00129                          I& /* ima */, const mln_value(I)& /* val */)
00130       {
00131         // No-op cause no extension domain, no border.
00132       }
00133 
00134       template <typename I>
00135       void fill_dispatch(mln::trait::image::ext_domain::some,
00136                          mln::trait::image::ext_io::read_only,
00137                          I& ima, const mln_value(I)& val)
00138       {
00139         // No-op for the extension domain, yet:
00140         border::fill(ima, val);
00141       }
00142 
00143       template <typename I>
00144       void fill_dispatch(mln::trait::image::ext_domain::extendable,
00145                          mln::trait::image::ext_io::read_write,
00146                          I& ima, const mln_value(I)& val)
00147       {
00148         // Just fill the border.
00149         border::fill(ima, val);
00150       }
00151 
00152       template <typename I>
00153       void fill_dispatch(mln::trait::image::ext_domain::some,
00154                          mln::trait::image::ext_io::read_write,
00155                          I& ima, const mln_value(I)& val)
00156       {
00157         do_fill(ima, val);
00158       }
00159 
00160       template <typename I>
00161       void fill_dispatch(const Image<I>& ima_, const mln_value(I)& val)
00162       {
00163         I& ima = const_cast<I&>(exact(ima_));
00164         fill_dispatch(mln_trait_image_ext_domain(I)(),
00165                       mln_trait_image_ext_io(I)(),
00166                       ima, val);
00167       }
00168 
00169     } // end of namespace mln::extension::internal
00170 
00171 
00172     // Facade.
00173 
00174     template <typename I>
00175     void fill(const Image<I>& ima, const mln_value(I)& val)
00176     {
00177       trace::entering("extension::fill");
00178 
00179       mln_precondition(exact(ima).is_valid());
00180       internal::fill_dispatch(ima, val);
00181 
00182       trace::exiting("extension::fill");
00183     }
00184 
00185 # endif // ! MLN_INCLUDE_ONLY
00186 
00187   } // end of namespace mln::extension
00188 
00189 } // end of namespace mln
00190 
00191 
00192 #endif // ! MLN_EXTENSION_FILL_HH
 All Classes Namespaces Functions Variables Typedefs Enumerator