Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
extension/fill.hh
1 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_EXTENSION_FILL_HH
27 # define MLN_EXTENSION_FILL_HH
28 
35 
36 # include <mln/core/concept/image.hh>
37 # include <mln/trait/image/props.hh>
38 # include <mln/border/fill.hh>
39 # include <mln/data/fill_with_value.hh>
40 
41 
42 namespace mln
43 {
44 
45  namespace extension
46  {
47 
58  template <typename I>
59  void fill(const Image<I>& ima, const mln_value(I)& val);
60 
61 
62 # ifndef MLN_INCLUDE_ONLY
63 
64 
65  namespace internal
66  {
67 
68  // Do it.
69 
70  template <typename I>
71  void do_fill(I& ima, const mln_value(I)& val); // Entry point.
72 
73  template <typename I>
74  void do_fill(mln::trait::image::ext_domain::some,
75  mln::trait::image::ext_value::single,
76  mln::trait::image::ext_domain::none,
77  I& ima, const mln_value(I)& val)
78  {
79  ima.change_extension(val);
80  }
81 
82  template <typename I>
83  void do_fill(mln::trait::image::ext_domain::some,
84  mln::trait::image::ext_value::multiple,
85  mln::trait::image::ext_domain::none,
86  I& ima, const mln_value(I)& val)
87  {
88  border::fill(ima, val);
89  ima.change_extension(val);
90  }
91 
92  template <typename I>
93  void do_fill(mln::trait::image::ext_domain::some,
94  mln::trait::image::ext_value::any,
95  mln::trait::image::ext_domain::some,
96  I& ima, const mln_value(I)& val)
97  {
98  mln::extension::fill(ima.unmorph_(), val);
99  }
100 
101  template <typename I>
102  void do_fill(mln::trait::image::ext_domain::none,
103  mln::trait::image::ext_value::any,
104  mln::trait::image::ext_domain::any,
105  I& ima, const mln_value(I)& val)
106  {
107  (void) ima;
108  (void) val;
109  // Oops...
110  }
111 
112  template <typename I>
113  void do_fill(I& ima, const mln_value(I)& val)
114  {
115  typedef typename I::delegatee D;
116  do_fill(mln_trait_image_ext_domain(I)(),
117  mln_trait_image_ext_value(I)(),
118  mln_trait_image_ext_domain(D)(),
119  ima, val);
120  }
121 
122 
123 
124  // Dispatch.
125 
126  template <typename I>
127  void fill_dispatch(mln::trait::image::ext_domain::none,
128  mln::trait::image::ext_io::any,
129  I& /* ima */, const mln_value(I)& /* val */)
130  {
131  // No-op cause no extension domain, no border.
132  }
133 
134  template <typename I>
135  void fill_dispatch(mln::trait::image::ext_domain::some,
136  mln::trait::image::ext_io::read_only,
137  I& ima, const mln_value(I)& val)
138  {
139  // No-op for the extension domain, yet:
140  border::fill(ima, val);
141  }
142 
143  template <typename I>
144  void fill_dispatch(mln::trait::image::ext_domain::extendable,
145  mln::trait::image::ext_io::read_write,
146  I& ima, const mln_value(I)& val)
147  {
148  // Just fill the border.
149  border::fill(ima, val);
150  }
151 
152  template <typename I>
153  void fill_dispatch(mln::trait::image::ext_domain::some,
154  mln::trait::image::ext_io::read_write,
155  I& ima, const mln_value(I)& val)
156  {
157  do_fill(ima, val);
158  }
159 
160  template <typename I>
161  void fill_dispatch(const Image<I>& ima_, const mln_value(I)& val)
162  {
163  I& ima = const_cast<I&>(exact(ima_));
164  fill_dispatch(mln_trait_image_ext_domain(I)(),
165  mln_trait_image_ext_io(I)(),
166  ima, val);
167  }
168 
169  } // end of namespace mln::extension::internal
170 
171 
172  // Facade.
173 
174  template <typename I>
175  void fill(const Image<I>& ima, const mln_value(I)& val)
176  {
177  trace::entering("extension::fill");
178 
179  mln_precondition(exact(ima).is_valid());
180  internal::fill_dispatch(ima, val);
181 
182  trace::exiting("extension::fill");
183  }
184 
185 # endif // ! MLN_INCLUDE_ONLY
186 
187  } // end of namespace mln::extension
188 
189 } // end of namespace mln
190 
191 
192 #endif // ! MLN_EXTENSION_FILL_HH