Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
image_identity.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_CORE_INTERNAL_IMAGE_IDENTITY_HH
27 # define MLN_CORE_INTERNAL_IMAGE_IDENTITY_HH
28 
35 
36 # include <mln/core/internal/image_morpher.hh>
37 
38 
39 namespace mln
40 {
41 
42  namespace internal
43  {
44 
45 
46  // Fastest.
47 
48  template <typename trait_speed, typename I, typename E>
49  struct image_identity_impl__fastest
50  {
51  // Nothing.
52  };
53 
54  template <typename I, typename E>
55  struct image_identity_impl__fastest< mln::trait::image::speed::fastest, I, E >
56  {
57  private:
58 
59  mlc_const(I)& del_() const
60  {
61  return * internal::force_exact<const E>(*this).delegatee_();
62  }
63 
64  I& del_()
65  {
66  return * internal::force_exact<E>(*this).delegatee_();
67  }
68 
69  public:
70 
71  int delta_index(const mln_deduce(I, psite, delta)& dp) const
72  {
73  return del_().delta_index(dp);
74  }
75 
76  mln_site(I) point_at_index(unsigned i) const
77  {
78  return del_().point_at_index(i);
79  }
80 
81  unsigned border() const
82  {
83  return del_().border();
84  }
85 
86  mln_qlf_value(I)* buffer()
87  {
88  return del_().buffer();
89  }
90 
91  const mln_value(I)* buffer() const
92  {
93  return del_().buffer();
94  }
95 
96  mln_rvalue(I) element(unsigned i) const
97  {
98  return del_().element(i);
99  }
100 
101  mln_lvalue(I) element(unsigned i)
102  {
103  return del_().element(i);
104  }
105 
106  unsigned nelements() const
107  {
108  return del_().nelements();
109  }
110  };
111 
112  // Facade.
113 
114  template <typename I, typename E>
115  struct image_identity_impl
116  : image_identity_impl__fastest< mln_trait_image_speed(E), I, E >
117  {
118  };
119 
120 
121 
126  template <typename I, typename S, typename E>
127  class image_identity
128  : public image_identity_impl<I, E>,
129  public image_morpher<I, mln_value(I), S, E>
130  {
131  public:
132 
134  typedef mln_value(I) value;
135 
137  typedef mln_rvalue(I) rvalue;
138 
140  typedef mln_morpher_lvalue(I) lvalue;
141 
143  rvalue operator()(const mln_psite(S)& p) const;
144 
146  lvalue operator()(const mln_psite(S)& p);
147 
148  // FIXME Matthieu: Doc! Cf. core/concept/doc/image
149  const mln_domain(I)& domain() const;
150  bool has(const mln_psite(I)& p) const;
151 
152  protected:
153 
155  image_identity();
156  };
157 
158 
159 
160 # ifndef MLN_INCLUDE_ONLY
161 
162  template <typename I, typename S, typename E>
163  inline
164  image_identity<I, S, E>::image_identity()
165  {
166  }
167 
168  template <typename I, typename S, typename E>
169  inline
170  mln_rvalue(I)
171  image_identity<I, S, E>::operator()(const mln_psite(S)& p) const
172  {
173  mln_precondition(this->delegatee_() != 0);
174  return this->delegatee_()->operator()(p);
175  }
176 
177  template <typename I, typename S, typename E>
178  inline
179  typename image_identity<I, S, E>::lvalue
180  image_identity<I, S, E>::operator()(const mln_psite(S)& p)
181  {
182  mln_precondition(this->delegatee_() != 0);
183  return this->delegatee_()->operator()(p);
184  }
185 
186  template <typename I, typename S, typename E>
187  inline
188  const mln_domain(I)&
189  image_identity<I, S, E>::domain() const
190  {
191  mln_precondition(this->delegatee_() != 0);
192  return this->delegatee_()->domain();
193  }
194 
195  template <typename I, typename S, typename E>
196  inline
197  bool
198  image_identity<I, S, E>::has(const mln_psite(I)& p) const
199  {
200  mln_precondition(this->delegatee_() != 0);
201  return this->delegatee_()->has(p);
202  }
203 
204 # endif // ! MLN_INCLUDE_ONLY
205 
206  } // end of namespace mln::internal
207 
208 } // end of namespace mln
209 
210 
211 #endif // ! MLN_CORE_INTERNAL_IMAGE_IDENTITY_HH