$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
p_transformed.hh
1 // Copyright (C) 2009, 2011, 2013 EPITA Research and Development
2 // Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_CORE_SITE_SET_P_TRANSFORMED_HH
28 # define MLN_CORE_SITE_SET_P_TRANSFORMED_HH
29 
34 
35 # include <mln/core/internal/site_set_base.hh>
36 # include <mln/core/concept/function.hh>
37 # include <mln/convert/from_to.hh>
38 
39 namespace mln
40 {
41 
42  // Forward declarations.
43  template <typename S, typename F> class p_transformed;
44  template <typename Pi, typename S, typename F> struct p_transformed_piter;
45 
46 
47  namespace trait
48  {
49 
50  template <typename S, typename F>
51  struct site_set_< p_transformed<S,F> >
52  {
53  typedef trait::site_set::nsites::unknown nsites;
54  typedef trait::site_set::bbox::unknown bbox;
55  typedef trait::site_set::contents::fixed contents;
56  typedef trait::site_set::arity::multiple arity;
57  };
58 
59  } // end of namespace trait
60 
61 
70  //
71  template <typename S, typename F>
72  p_transformed<S, F>
73  ptransform(const Site_Set<S>& s, const Function_v2v<F>& f);
74 
75 
76 
83  //
84  template <typename S, typename F>
86  : public internal::site_set_base_< mln_psite(S), p_transformed<S,F> >,
87  private mlc_converts_to(mln_result(F), mln_psite(S))::check_t
88  {
89  typedef p_transformed<S,F> self_;
91  public:
92 
94  typedef mln_element(S) element;
95 
96 
98  typedef mln_psite(S) psite;
99 
101  typedef p_transformed_piter<mln_fwd_piter(S), S, F> fwd_piter;
102 
104  typedef p_transformed_piter<mln_bkd_piter(S), S, F> bkd_piter;
105 
107  typedef fwd_piter piter;
108 
109 
111  p_transformed(const S& s, const F& f);
112 
114  p_transformed();
115 
116 
118  bool is_valid() const;
119 
120 
122  bool has(const psite& p) const;
123 
124 
126  std::size_t memory_size() const;
127 
129  const S& primary_set() const;
130 
132  const F& function() const;
133 
134  protected:
135 
136  S s_;
137  F f_;
138  };
139 
140 
141 
142 # ifndef MLN_INCLUDE_ONLY
143 
144 
145  template <typename S, typename F>
146  inline
148  ptransform(const Site_Set<S>& s, const Function_v2v<F>& f)
149  {
150  mlc_equal(mln_result(F), mln_psite(S))::check();
151  p_transformed<S, F> tmp(exact(s), exact(f));
152  return tmp;
153  }
154 
155 
156  // p_transformed<S,F>
157 
158  template <typename S, typename F>
159  inline
161  {
162  }
163 
164  template <typename S, typename F>
165  inline
166  p_transformed<S,F>::p_transformed(const S& s, const F& f)
167  : s_(s),
168  f_(f)
169  {
170  }
171 
172  template <typename S, typename F>
173  inline
174  bool
175  p_transformed<S,F>::has(const psite& p) const
176  {
177  mln_argument(F) arg;
178  convert::from_to(p, arg);
179  return s_.has(f_.inverse(arg));
180  }
181 
182  template <typename S, typename F>
183  inline
184  bool
185  p_transformed<S,F>::is_valid() const
186  {
187  return s_.is_valid();
188  }
189 
190  template <typename S, typename F>
191  inline
192  std::size_t
194  {
195  return s_.memory_size() + sizeof(f_);
196  }
197 
198  template <typename S, typename F>
199  inline
200  const S&
202  {
203  return s_;
204  }
205 
206  template <typename S, typename F>
207  inline
208  const F&
210  {
211  return f_;
212  }
213 
214 # endif // ! MLN_INCLUDE_ONLY
215 
216 } // end of namespace mln
217 
218 
219 
220 # include <mln/core/site_set/p_transformed_piter.hh>
221 
222 
223 
224 #endif // ! MLN_CORE_SITE_SET_P_TRANSFORMED_HH