complex_psite.hh 6.84 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of the Olena Library.  This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING.  If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction.  Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License.
// reasons why the executable file might be covered by the GNU General
// Public License.

#ifndef MLN_CORE_COMPLEX_PSITE_HH
# define MLN_CORE_COMPLEX_PSITE_HH

/// \file mln/core/complex_psite.hh
/// \brief Definition of a complex-based point site.

# include <mln/core/concept/point_site.hh>

# include <mln/core/complex.hh>


namespace mln
{
41
  /* FIXME: Get rid of P?  */
42

43
  /// \brief Point site associated to a mln::p_complex.
44
  ///
45
  /// \arg \p D The dimension of the complex this psite belongs to.
46
  /// \arg \p P The type of point associated to this psite.
47
48
  template <unsigned D, typename P>
  class complex_psite : public Point_Site< complex_psite<D, P> >
49
  {
50
    typedef complex_psite<D, P> self_;
51
52
53
54
55
56
57
58
59
60
61
62
    typedef Point_Site<self_> super_;

  public:
    typedef mln_mesh(P) mesh;
    enum { dim = P::dim };
    typedef P point;
    typedef mln_dpoint(P) dpoint;
    typedef mln_coord(P) coord;

    /// Construction and assignment.
    /// \{
    complex_psite();
63
    complex_psite(const any_face_handle<D>& face);
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
    complex_psite(const self_& rhs);
    self_& operator= (const self_& rhs);
    /// \}

    /// Access to psite.
    const self_& to_psite() const;

    /* FIXME: Should be removed as soon as ``point sets'' become
       ``site sets''.  */
    /// Access to point.
    /// \{
    const point& to_point() const;
    coord operator[](unsigned face) const;
    /// \}

79
80
    /// Accessors
    /// \{
81
    /// Return the face handle of this point site.
82
    any_face_handle<D> face() const;
83
84
85
    /// Return the complex on which this site is built.
    const complex<D>& cplx() const;

86
87
88
89
90
91
    /// Return the dimension of the face of this psite.
    unsigned n() const;
    /// Return the id of the face of this psite.
    unsigned face_id() const;
    /// \}

92
93
94
95
96
    /// Is this psite valid?
    bool is_valid() const;

  private:
    /// The handle of the face this psite is pointing towards.
97
    any_face_handle<D> face_;
98
99
100
101
102
103
104
105
106
107
108
109
110
111
    // FIXME: Actually, this is a dummy value!
    point p_;
  };


  /// Comparison of two instances of mln::complex_psite.
  /// \{
  /* FIXME: Shouldn't those comparisons be part of a much general
     mechanism?  */

  /// \brief Is \a lhs equal to \a rhs?
  ///
  /// \pre Arguments \a lhs and \a rhs must belong to the same
  /// mln::complex.
112
  template <unsigned D, typename P>
113
  bool
114
115
  operator==(const complex_psite<D, P>& lhs,
	     const complex_psite<D, P>& rhs);
116
117
118
119
120
121
122

  /// \brief Is \a lhs ``less'' than \a rhs?
  ///
  /// This comparison is required by algorithms sorting psites.
  ///
  /// \pre Arguments \a lhs and \a rhs must belong to the same
  /// mln::complex.
123
  template <unsigned D, typename P>
124
  bool
125
126
  operator< (const complex_psite<D, P>& lhs,
	     const complex_psite<D, P>& rhs);
127
128
129
  /// \}


130
131
132
133
134
135
136
137
138
139
  /* FIXME: This hand-made delegation is painful.  We should rely on
     the general mechanism provided by Point_Site.  But then again, we
     need to refine/adjust the interface of Point_Site w.r.t. the
     mandatory conversions to points.  */
  template <unsigned D, typename P>
  inline
  std::ostream&
  operator<<(std::ostream& ostr, const complex_psite<D, P>& p);


140
141
142

# ifndef MLN_INCLUDE_ONLY

143
  template <unsigned D, typename P>
144
  inline
145
  complex_psite<D, P>::complex_psite()
146
147
148
149
150
151
    : super_(),
      // Dummy initializations.
      face_(), p_()
  {
  }

152
  template <unsigned D, typename P>
153
  inline
154
  complex_psite<D, P>::complex_psite(const any_face_handle<D>& face)
155
156
157
158
159
    : super_(),
      face_(face), p_()
  {
  }

160
  template <unsigned D, typename P>
161
  inline
162
  complex_psite<D, P>::complex_psite(const complex_psite<D, P>& rhs)
163
164
165
166
167
    : super_(rhs),
      face_(rhs.face_), p_()
  {
  }

168
  template <unsigned D, typename P>
169
  inline
170
171
  complex_psite<D, P>&
  complex_psite<D, P>::operator= (const complex_psite<D, P>& rhs)
172
173
174
175
176
177
178
  {
    if (&rhs == this)
      return *this;
    face_ = rhs.face_;
    return *this;
  }

179
  template <unsigned D, typename P>
180
181
  inline
  bool
182
  complex_psite<D, P>::is_valid() const
183
  {
184
    return face_.is_valid();
185
186
  }

187
  template <unsigned D, typename P>
188
  inline
189
190
  const complex_psite<D, P>&
  complex_psite<D, P>::to_psite() const
191
192
193
194
  {
    return *this;
  }

195
  template <unsigned D, typename P>
196
197
  inline
  const P&
198
  complex_psite<D, P>::to_point() const
199
200
201
202
203
  {
    // FIXME: Dummy value.
    return p_;
  }

204
  template <unsigned D, typename P>
205
206
  inline
  mln_coord(P)
207
  complex_psite<D, P>::operator[](unsigned i) const
208
209
210
211
212
  {
    mln_precondition(is_valid());
    return to_point()[i];
  }

213
  template <unsigned D, typename P>
214
  inline
215
216
  any_face_handle<D>
  complex_psite<D, P>::face() const
217
218
219
220
  {
    return face_;
  }

221
  template <unsigned D, typename P>
222
223
  inline
  const complex<D>&
224
  complex_psite<D, P>::cplx() const
225
226
227
228
  {
    return face_.cplx();
  }

229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
  template <unsigned D, typename P>
  inline
  unsigned
  complex_psite<D, P>::n() const
  {
    return face_.n();
  }

  template <unsigned D, typename P>
  inline
  unsigned
  complex_psite<D, P>::face_id() const
  {
    return face_.face_id();
  }

245
246
247
248
  /*--------------.
  | Comparisons.  |
  `--------------*/

249
  template <unsigned D, typename P>
250
  bool
251
252
  operator==(const complex_psite<D, P>& lhs,
	     const complex_psite<D, P>& rhs)
253
254
255
256
257
  {
    mln_precondition(&lhs.cplx() == &rhs.cplx());
    return lhs.face() == rhs.face();
  }

258
  template <unsigned D, typename P>
259
  bool
260
261
  operator< (const complex_psite<D, P>& lhs,
	     const complex_psite<D, P>& rhs)
262
263
264
265
266
  {
    mln_precondition(&lhs.cplx() == &rhs.cplx());
    return lhs.face() < rhs.face();
  }

267
268
269
270
271
272
273
274
275

  template <unsigned D, typename P>
  inline
  std::ostream&
  operator<<(std::ostream& ostr, const complex_psite<D, P>& p)
  {
        return ostr << "(dim = " << p.n() << ", id = " << p.face_id() << ')';
  }

276
277
278
279
280
281
# endif // ! MLN_INCLUDE_ONLY


} // end of mln

#endif // MLN_CORE_COMPLEX_PSITE_HH