• 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_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         // Oops...
00108       }
00109 
00110       template <typename I>
00111       void do_fill(I& ima, const mln_value(I)& val)
00112       {
00113         typedef typename I::delegatee D;
00114         do_fill(mln_trait_image_ext_domain(I)(),
00115                 mln_trait_image_ext_value(I)(),
00116                 mln_trait_image_ext_domain(D)(),
00117                 ima, val);
00118       }
00119 
00120 
00121 
00122       // Dispatch.
00123 
00124       template <typename I>
00125       void fill_dispatch(mln::trait::image::ext_domain::none,
00126                          mln::trait::image::ext_io::any,
00127                          I& /* ima */, const mln_value(I)& /* val */)
00128       {
00129         // No-op cause no extension domain, no border.
00130       }
00131 
00132       template <typename I>
00133       void fill_dispatch(mln::trait::image::ext_domain::some,
00134                          mln::trait::image::ext_io::read_only,
00135                          I& ima, const mln_value(I)& val)
00136       {
00137         // No-op for the extension domain, yet:
00138         border::fill(ima, val);
00139       }
00140 
00141       template <typename I>
00142       void fill_dispatch(mln::trait::image::ext_domain::extendable,
00143                          mln::trait::image::ext_io::read_write,
00144                          I& ima, const mln_value(I)& val)
00145       {
00146         // Just fill the border.
00147         border::fill(ima, val);
00148       }
00149 
00150       template <typename I>
00151       void fill_dispatch(mln::trait::image::ext_domain::some,
00152                          mln::trait::image::ext_io::read_write,
00153                          I& ima, const mln_value(I)& val)
00154       {
00155         do_fill(ima, val);
00156       }
00157 
00158       template <typename I>
00159       void fill_dispatch(const Image<I>& ima_, const mln_value(I)& val)
00160       {
00161         I& ima = const_cast<I&>(exact(ima_));
00162         fill_dispatch(mln_trait_image_ext_domain(I)(),
00163                       mln_trait_image_ext_io(I)(),
00164                       ima, val);
00165       }
00166 
00167     } // end of namespace mln::extension::internal
00168 
00169 
00170     // Facade.
00171 
00172     template <typename I>
00173     void fill(const Image<I>& ima, const mln_value(I)& val)
00174     {
00175       trace::entering("extension::fill");
00176 
00177       mln_precondition(exact(ima).is_valid());
00178       internal::fill_dispatch(ima, val);
00179 
00180       trace::exiting("extension::fill");
00181     }
00182 
00183 # endif // ! MLN_INCLUDE_ONLY
00184 
00185   } // end of namespace mln::extension
00186 
00187 } // end of namespace mln
00188 
00189 
00190 #endif // ! MLN_EXTENSION_FILL_HH

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