https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Allow non-initialized faces.
* mln/core/face.hh (mln::face_handle<N, D>::face_handle): New ctor.
(mln::face_handle<N, D>::is_valid): New method.
Use it...
(mln::face_handle<N, D>::get): ...here.
Rename as...
(mln::face_handle<N, D>::to_face): ...this.
(mln::face_handle<N, D>::face_id_): Make this attribute private.
(mln::face_handle<N, D>::c_): Likewise.
Turn this reference into a pointer.
(mln::face_handle<N, D>::face_handle)
(mln::face_handle<N, D>::to_face)
(mln::make_face_handle<N, D>):
Adjust.
(mln::faces_set<N, D>::add): Likewise.
Remove spurious FIXME.
(mln::face_handle<N, D>::c, mln::face_handle<N, D>::face_id):
New accessors.
* mln/core/complex.hh (mln::complex<D>::connect_)
(mln::internal::lower_dim_faces_set_mixin<N, D>::print)
(mln::internal::higher_dim_faces_set_mixin<N, D>::print):
Adjust.
complex.hh | 8 ++--
face.hh | 102 +++++++++++++++++++++++++++++++++++++++++++------------------
2 files changed, 76 insertions(+), 34 deletions(-)
Index: mln/core/complex.hh
--- mln/core/complex.hh (revision 2118)
+++ mln/core/complex.hh (working copy)
@@ -288,8 +288,8 @@
// Ensure N is compatible with D.
metal::bool_< N <= D >::check();
- f1.get().connect_higher_dim_face(f2);
- f2.get().connect_lower_dim_face(f1);
+ f1.to_face().connect_higher_dim_face(f2);
+ f2.to_face().connect_lower_dim_face(f1);
}
@@ -424,7 +424,7 @@
{
for (typename std::vector< face_handle<N - 1, D> >::const_iterator l =
f.lower_dim_faces_.begin(); l != f.lower_dim_faces_.end(); ++l)
- ostr << l->face_id_ << " ";
+ ostr << l->face_id() << " ";
}
template <unsigned N, unsigned D>
@@ -434,7 +434,7 @@
{
for (typename std::vector< face_handle<N + 1, D> >::const_iterator h =
f.higher_dim_faces_.begin(); h != f.higher_dim_faces_.end(); ++h)
- ostr << h->face_id_ << " ";
+ ostr << h->face_id() << " ";
}
} // end of namespace mln::internal
Index: mln/core/face.hh
--- mln/core/face.hh (revision 2118)
+++ mln/core/face.hh (working copy)
@@ -31,6 +31,8 @@
/// \file mln/core/face.hh
/// \brief Face of a complex.
+#include <climits>
+
#include <vector>
#include <mln/core/contract.hh>
@@ -129,6 +131,9 @@
template <unsigned N, unsigned D>
struct face_handle
{
+ /// Build a non-initialized face handle.
+ face_handle();
+ /// Build a face handle from \a complex and \a face_id.
face_handle(complex<D>& complex, unsigned face_id);
/// Copy and assignment.
@@ -137,15 +142,26 @@
face_handle<N, D>& operator=(const face_handle<N, D>& rhs);
/// \}
+ /// Is this handle valid?
+ bool is_valid() const;
+
/// Accessors.
/// \{
+ /// Return the complex the face belongs to.
+ complex<D>& c() const;
+ /// Return the id of the face.
+ unsigned face_id() const;
+
/// Return the mln::face pointed by this handle.
- face<N, D>& get() const;
+ face<N, D>& to_face() const;
/// \}
- /* FIXME: Hide data. */
- // A const face_handle can be used to modify a complex.
- mutable complex<D>& c_;
+ private:
+ /// \brief The complex the face belongs to.
+ ///
+ /// A const face_handle can be used to modify a complex.
+ mutable complex<D>* c_;
+ /// \brief The id of the face.
unsigned face_id_;
};
@@ -195,13 +211,42 @@
# ifndef MLN_INCLUDE_ONLY
+ /*--------.
+ | Faces. |
+ `--------*/
+
+ namespace internal
+ {
+ template <unsigned N, unsigned D>
+ void
+ lower_dim_faces_mixin<N, D>::connect_lower_dim_face(const face_handle<N - 1,
D>& f)
+ {
+ lower_dim_faces_.push_back(f);
+ }
+
+ template <unsigned N, unsigned D>
+ void
+ higher_dim_faces_mixin<N, D>::connect_higher_dim_face(const face_handle<N +
1, D>& f)
+ {
+ higher_dim_faces_.push_back(f);
+ }
+
+ } // end of namespace mln::internal
+
+
/*--------------.
| Face handle. |
`--------------*/
template <unsigned N, unsigned D>
+ face_handle<N, D>::face_handle()
+ : c_(0), face_id_(UINT_MAX)
+ {
+ }
+
+ template <unsigned N, unsigned D>
face_handle<N, D>::face_handle(complex<D>& c, unsigned face_id)
- : c_(c), face_id_(face_id)
+ : c_(&c), face_id_(face_id)
{
}
@@ -224,42 +269,42 @@
}
template <unsigned N, unsigned D>
- face<N, D>&
- face_handle<N, D>::get() const
+ bool
+ face_handle<N, D>::is_valid() const
{
- return c_.template face_<N>(face_id_);
+ return c_ != 0 && face_id_ != UINT_MAX;
}
-
template <unsigned N, unsigned D>
- face_handle<N, D>
- make_face_handle(const complex<D>& c, unsigned face_id)
+ complex<D>&
+ face_handle<N, D>::c() const
{
- return face_handle<N, D>(c, face_id);
+ mln_assertion(c_);
+ return *c_;
}
-
- /*--------.
- | Faces. |
- `--------*/
-
- namespace internal
- {
template <unsigned N, unsigned D>
- void
- lower_dim_faces_mixin<N, D>::connect_lower_dim_face(const face_handle<N - 1,
D>& f)
+ unsigned
+ face_handle<N, D>::face_id() const
{
- lower_dim_faces_.push_back(f);
+ return face_id_;
}
template <unsigned N, unsigned D>
- void
- higher_dim_faces_mixin<N, D>::connect_higher_dim_face(const face_handle<N +
1, D>& f)
+ face<N, D>&
+ face_handle<N, D>::to_face() const
{
- higher_dim_faces_.push_back(f);
+ mln_assertion(is_valid());
+ return c_->template face_<N>(face_id_);
}
- } // end of namespace mln::internal
+
+ template <unsigned N, unsigned D>
+ face_handle<N, D>
+ make_face_handle(const complex<D>& c, unsigned face_id)
+ {
+ return face_handle<N, D>(&c, face_id);
+ }
/*---------------.
@@ -272,10 +317,7 @@
{
// Check consistency.
if (!faces_.empty())
- mln_assertion(&faces_.front().c_ == &f.c_);
-
- /* FIXME: This is not thread-proof (these two lines should
- form an atomic section). */
+ mln_assertion(&faces_.front().c() == &f.c());
faces_.push_back (f);
}