Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
paste.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_DATA_PASTE_HH
27 # define MLN_DATA_PASTE_HH
28 
32 
33 # include <mln/core/concept/image.hh>
34 
35 // Specializations are in:
36 # include <mln/data/paste.spe.hh>
37 
38 
39 
40 namespace mln
41 {
42 
43  namespace data
44  {
45 
62  template <typename I, typename J>
63  void paste(const Image<I>& input, Image<J>& output);
64 
65 
66 
67 # ifndef MLN_INCLUDE_ONLY
68 
69  namespace internal
70  {
71 
77  //
78  template <typename I, typename J>
79  inline
80  void paste_tests(const Image<I>& input, Image<J>& output)
81  {
82  mlc_is(mln_trait_image_pw_io(J), trait::image::pw_io::read_write)::
83  check();
84  mlc_converts_to(mln_value(I), mln_value(J))::check();
85 
86  mln_precondition(exact(input).is_valid());
87  mln_precondition(exact(input).domain() <= exact(output).domain());
88 
89  // Avoid warning when compiling with NDEBUG
90  (void)input;
91  (void)output;
92  }
93 
94  } // end of namespace mln::data::internal
95 
96 
97  namespace impl
98  {
99 
100  namespace generic
101  {
102 
108  //
109  template <typename I, typename J>
110  inline
111  void paste(const Image<I>& input_, Image<J>& output_)
112  {
113  trace::entering("data::impl::generic::paste");
114 
115  data::internal::paste_tests(input_, output_);
116 
117  const I& input = exact(input_);
118  J& output = exact(output_);
119 
120 
121  mln_piter(I) p(input.domain());
122  for_all(p)
123  output(p) = static_cast<mln_value(J)>(input(p));
124 
125  trace::exiting("data::impl::generic::paste");
126  }
127 
128  } // end of namespace mln::data::impl::generic
129 
130  } // end of namespace mln::data::impl
131 
132 
133  // Facade.
134 
135  template <typename I, typename J>
136  inline
137  void paste(const Image<I>& input, Image<J>& output)
138  {
139  trace::entering("data::paste");
140 
141  mlc_converts_to(mln_value(I), mln_value(J))::check();
142 
143  internal::paste_tests(input, output);
144  internal::paste_dispatch(input, output);
145 
146  trace::exiting("data::paste");
147  }
148 
149 # endif // ! MLN_INCLUDE_ONLY
150 
151  } // end of namespace mln::data
152 
153 } // end of namespace mln
154 
155 
156 
157 #endif // ! MLN_DATA_PASTE_HH