Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
p_transformed.hh
1 // Copyright (C) 2009, 2011 EPITA Research and Development Laboratory
2 // (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 
68  //
69  template <typename S, typename F>
70  p_transformed<S, F>
71  ptransform(const Site_Set<S>& s, const Function_v2v<F>& f);
72 
73 
74 
81  //
82  template <typename S, typename F>
84  : public internal::site_set_base_< mln_psite(S), p_transformed<S,F> >,
85  private mlc_converts_to(mln_result(F), mln_psite(S))::check_t
86  {
87  typedef p_transformed<S,F> self_;
88  typedef internal::site_set_base_<mln_result(F), self_> super_;
89  public:
90 
92  typedef mln_element(S) element;
93 
94 
96  typedef mln_psite(S) psite;
97 
99  typedef p_transformed_piter<mln_fwd_piter(S), S, F> fwd_piter;
100 
102  typedef p_transformed_piter<mln_bkd_piter(S), S, F> bkd_piter;
103 
105  typedef fwd_piter piter;
106 
107 
109  p_transformed(const S& s, const F& f);
110 
112  p_transformed();
113 
114 
116  bool is_valid() const;
117 
118 
120  bool has(const psite& p) const;
121 
122 
124  std::size_t memory_size() const;
125 
127  const S& primary_set() const;
128 
130  const F& function() const;
131 
132  protected:
133 
134  S s_;
135  F f_;
136  };
137 
138 
139 
140 # ifndef MLN_INCLUDE_ONLY
141 
142 
143  template <typename S, typename F>
144  inline
147  {
148  mlc_equal(mln_result(F), mln_psite(S))::check();
149  p_transformed<S, F> tmp(exact(s), exact(f));
150  return tmp;
151  }
152 
153 
154  // p_transformed<S,F>
155 
156  template <typename S, typename F>
157  inline
159  {
160  }
161 
162  template <typename S, typename F>
163  inline
164  p_transformed<S,F>::p_transformed(const S& s, const F& f)
165  : s_(s),
166  f_(f)
167  {
168  }
169 
170  template <typename S, typename F>
171  inline
172  bool
173  p_transformed<S,F>::has(const psite& p) const
174  {
175  mln_argument(F) arg;
176  convert::from_to(p, arg);
177  return s_.has(f_.inverse(arg));
178  }
179 
180  template <typename S, typename F>
181  inline
182  bool
184  {
185  return s_.is_valid();
186  }
187 
188  template <typename S, typename F>
189  inline
190  std::size_t
192  {
193  return s_.memory_size() + sizeof(f_);
194  }
195 
196  template <typename S, typename F>
197  inline
198  const S&
200  {
201  return s_;
202  }
203 
204  template <typename S, typename F>
205  inline
206  const F&
208  {
209  return f_;
210  }
211 
212 # endif // ! MLN_INCLUDE_ONLY
213 
214 } // end of namespace mln
215 
216 
217 
218 # include <mln/core/site_set/p_transformed_piter.hh>
219 
220 
221 
222 #endif // ! MLN_CORE_SITE_SET_P_TRANSFORMED_HH