Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
p_faces.hh
1 // Copyright (C) 2008, 2009, 2011 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_FACES_HH
28 # define MLN_CORE_SITE_SET_P_FACES_HH
29 
34 
35 # include <mln/core/internal/site_set_base.hh>
36 
37 # include <mln/topo/complex.hh>
38 
39 # include <mln/core/faces_psite.hh>
40 
41 // FIXME: Disabled (moved to the attic).
42 # if 0
43 # include <mln/core/site_set/p_faces_piter.hh>
44 # endif
45 
46 # include <mln/core/site_set/p_complex.hh>
47 
48 
49 namespace mln
50 {
51 
52  // Forward declarations.
53  template <unsigned N, unsigned D, typename P> struct p_faces;
54 
55  template <unsigned N, unsigned D, typename P> class p_faces_fwd_piter_;
56  template <unsigned N, unsigned D, typename P> class p_faces_bkd_piter_;
57 
58 
59  namespace trait
60  {
61  template <unsigned N, unsigned D, typename P>
62  struct site_set_< p_faces<N, D, P> >
63  {
64  typedef trait::site_set::nsites::known nsites;
65  // FIXME: Depends on P!
66  typedef trait::site_set::bbox::unknown bbox;
67  typedef trait::site_set::contents::fixed contents;
68  typedef trait::site_set::arity::unique arity;
69  };
70  } // end of namespace mln::trait
71 
72 
77  template <unsigned N, unsigned D, typename P>
78  struct p_faces
79  : public internal::site_set_base_< faces_psite<N, D, P>,
80  p_faces<N, D, P> >
81  {
82  typedef p_faces<N, D, P> self_;
83  typedef internal::site_set_base_< faces_psite<N, D, P>, self_ > super_;
84 
89 
95  p_faces(const p_complex<D, P>& pc);
96 
100  typedef mln_site(super_) element;
101 
103  typedef faces_psite<N, D, P> psite;
104 
105  // FIXME: Fake.
107  typedef p_faces_fwd_piter_<N, D, P> fwd_piter;
108 
109  // FIXME: Fake.
111  typedef p_faces_bkd_piter_<N, D, P> bkd_piter;
112 
114  typedef fwd_piter piter;
116 
123  unsigned nsites() const;
124 
126  unsigned nfaces() const;
127 
128  // FIXME: This method is probably useless now.
130  bool is_valid() const;
131 
132  bool has(const psite& p) const;
133 
134  // FIXME: Dummy.
135  std::size_t memory_size() const;
136 
141  /* FIXME: Move back the const qualifier on this return type (see
142  comment below on cplx_). */
143  topo::complex<D>& cplx() const;
146  topo::complex<D>& cplx();
148 
149  private:
151  /* FIXME: Get rid of this `mutable' qualifier. This is needed for
152  compatiblity reasons with face_handle (see p_faces_piter).
153 
154  We should either
155 
156  - have an additional version of face_handle holding a const
157  (not mutable) complex;
158 
159  - have face_handle and any_face_handle do not hold a reference
160  on a complex, leading to a design of complexes similar to
161  graphs, where vertex and edge handles (named `id's) are not
162  tied to a specific graph. */
163  mutable topo::complex<D> cplx_;
164  };
165 
166 
171  template <unsigned N, unsigned D, typename P>
172  bool
173  operator==(const p_faces<N, D, P>& lhs, const p_faces<N, D, P>& rhs);
174 
183  template <unsigned N, unsigned D, typename P>
184  bool
185  operator<=(const p_faces<N, D, P>& lhs, const p_faces<N, D, P>& rhs);
186 
187 
188 
189 # ifndef MLN_INCLUDE_ONLY
190 
191  template <unsigned N, unsigned D, typename P>
192  inline
194  : cplx_(cplx)
195  {
196  // Ensure N is compatible with D.
197  metal::bool_< N <= D >::check();
198  }
199 
200  template <unsigned N, unsigned D, typename P>
201  inline
203  : cplx_(pc.cplx())
204  {
205  // Ensure N is compatible with D.
206  metal::bool_< N <= D >::check();
207  }
208 
209  template <unsigned N, unsigned D, typename P>
210  inline
211  unsigned
213  {
214  return nfaces();
215  }
216 
217  template <unsigned N, unsigned D, typename P>
218  inline
219  unsigned
221  {
222  return cplx_.template nfaces_of_static_dim<N>();
223  }
224 
225  template <unsigned N, unsigned D, typename P>
226  inline
227  bool
229  {
230  return true;
231  }
232 
233  template <unsigned N, unsigned D, typename P>
234  inline
235  bool
236  p_faces<N, D, P>::has(const psite& p) const
237  {
238  mln_precondition(is_valid());
239  return
240  // Check whether P's complex is compatible with this pset's complex.
241  (p.site_set() == *this) &&
242  // Check whether P is valid.
243  (p.is_valid());
244  }
245 
246  template <unsigned N, unsigned D, typename P>
247  inline
248  std::size_t
249  p_faces<N, D, P>::memory_size() const
250  {
251  // FIXME: Dummy; implement (see other site sets).
252  abort();
253  return 0;
254  }
255 
256  template <unsigned N, unsigned D, typename P>
257  topo::complex<D>&
259  {
260  mln_precondition(is_valid());
261  return cplx_;
262  }
263 
264  template <unsigned N, unsigned D, typename P>
267  {
268  mln_precondition(is_valid());
269  return cplx_;
270  }
271 
272 
273  /*--------------.
274  | Comparisons. |
275  `--------------*/
276 
277  template <unsigned N, unsigned D, typename P>
278  bool
279  operator==(const p_faces<N, D, P>& lhs, const p_faces<N, D, P>& rhs)
280  {
281  /* FIXME: When actual location data is attached to a p_faces,
282  check also the equality w.r.t. to these data. */
283  return lhs.cplx() == rhs.cplx();
284  }
285 
286  template <unsigned N, unsigned D, typename P>
287  bool
288  operator<=(const p_faces<N, D, P>& lhs, const p_faces<N, D, P>& rhs)
289  {
290  /* FIXME: When actual location data is attached to a p_faces,
291  check also the equality w.r.t. to these data. */
292  return lhs == rhs;
293  }
294 
295 # endif // ! MLN_INCLUDE_ONLY
296 
297 } // end of mln
298 
299 #endif // ! MLN_CORE_SITE_SET_P_FACES_HH