* mln/topo/face.hh, mln/topo/n_face.hh
(mln::face<D>::cplx_, mln::n_face<N, D>::cplx_):
Change type from mutable complex<D>* to mutable complex<D>.
(mln::face<D>::face, mln::n_face<N, D>::n_face): Adjust ctors.
(mln::face<D>::is_valid, mln::face<D>::data)
(mln::n_face<N, D>::is_valid, mln::n_face<N, D>::data):
Adjust.
(mln::complex<D>::cplx, mln::complex<D>::set_cplx): Don't
manipulate complexes by pointers, use plain objects instead.
(operator<<(std::ostream&, const face<D>&)): Adjust.
* mln/topo/n_faces_set.hh
(mln::topo::n_faces_set<N, D>::add(const n_face<N, D>&)): Adjust.
---
milena/ChangeLog | 18 ++++++++++++++++++
milena/mln/topo/face.hh | 30 +++++++++++++++---------------
milena/mln/topo/n_face.hh | 26 +++++++++++++-------------
milena/mln/topo/n_faces_set.hh | 2 +-
4 files changed, 47 insertions(+), 29 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 43214ce..7bda463 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,23 @@
2008-10-16 Roland Levillain <roland(a)lrde.epita.fr>
+ Manipulate complexes as plain objects (instead of pointers) in
+ face handles.
+
+ * mln/topo/face.hh, mln/topo/n_face.hh
+ (mln::face<D>::cplx_, mln::n_face<N, D>::cplx_):
+ Change type from mutable complex<D>* to mutable complex<D>.
+ (mln::face<D>::face, mln::n_face<N, D>::n_face): Adjust ctors.
+ (mln::face<D>::is_valid, mln::face<D>::data)
+ (mln::n_face<N, D>::is_valid, mln::n_face<N, D>::data):
+ Adjust.
+ (mln::complex<D>::cplx, mln::complex<D>::set_cplx): Don't
+ manipulate complexes by pointers, use plain objects instead.
+ (operator<<(std::ostream&, const face<D>&)): Adjust.
+ * mln/topo/n_faces_set.hh
+ (mln::topo::n_faces_set<N, D>::add(const n_face<N, D>&)): Adjust.
+
+2008-10-16 Roland Levillain <roland(a)lrde.epita.fr>
+
Fix a precondition in complex construction (add_face).
* mln/topo/complex.hh
diff --git a/milena/mln/topo/face.hh b/milena/mln/topo/face.hh
index bd2c3cd..371cf21 100644
--- a/milena/mln/topo/face.hh
+++ b/milena/mln/topo/face.hh
@@ -32,9 +32,11 @@
/// \brief Face of a complex.
#include <limits>
+#include <vector>
#include <mln/core/contract.hh>
+
namespace mln
{
@@ -78,7 +80,7 @@ namespace mln
/// Accessors.
/// \{
/// Return the complex the face belongs to.
- complex<D>& cplx() const;
+ complex<D> cplx() const;
/// Return the dimension of the face.
// FIXME: Rename as `dim'?
unsigned n() const;
@@ -87,7 +89,7 @@ namespace mln
unsigned face_id() const;
/// Set the complex the face belongs to.
- void set_cplx(complex<D>& cplx);
+ void set_cplx(const complex<D>& cplx);
/// Set the dimension of the face.
void set_n(unsigned n);
@@ -108,7 +110,6 @@ namespace mln
face_data<N, D>& data() const;
// FIXME: To be overhauled.
- // FIXME: Why no `const' here?
/// Return an array of face handles pointing to adjacent (n-1)-faces.
std::vector< face<D> > lower_dim_adj_faces() const;
/// Return an array of face handles pointing to adjacent (n+1)-faces.
@@ -119,7 +120,7 @@ namespace mln
/// \brief The complex the face belongs to.
///
/// A const face can be used to modify a complex.
- mutable complex<D>* cplx_;
+ mutable complex<D> cplx_;
/// The dimension of the face.
// FIXME: Rename as `dim_'?
unsigned n_;
@@ -171,7 +172,7 @@ namespace mln
template <unsigned D>
inline
face<D>::face()
- : cplx_(0),
+ : cplx_(),
n_(std::numeric_limits<unsigned>::max()),
face_id_(std::numeric_limits<unsigned>::max())
{
@@ -180,7 +181,7 @@ namespace mln
template <unsigned D>
inline
face<D>::face(complex<D>& c, unsigned n, unsigned face_id)
- : cplx_(&c), n_(n), face_id_(face_id)
+ : cplx_(c), n_(n), face_id_(face_id)
{
// Ensure N is compatible with D.
mln_precondition(n <= D);
@@ -190,7 +191,7 @@ namespace mln
template <unsigned N>
inline
face<D>::face(const n_face<N, D>& f)
- : cplx_(&f.cplx()), n_(N), face_id_(f.face_id())
+ : cplx_(f.cplx()), n_(N), face_id_(f.face_id())
{
// Ensure N is compatible with D.
metal::bool_< N <= D >::check();
@@ -202,7 +203,7 @@ namespace mln
bool
face<D>::is_valid() const
{
- return cplx_ != 0 && n_ <= D && face_id_ <
cplx_->nfaces(n_);
+ return n_ <= D && face_id_ < cplx_.nfaces(n_);
}
template <unsigned D>
@@ -216,11 +217,10 @@ namespace mln
template <unsigned D>
inline
- complex<D>&
+ complex<D>
face<D>::cplx() const
{
- mln_precondition(cplx_);
- return *cplx_;
+ return cplx_;
}
template <unsigned D>
@@ -242,9 +242,9 @@ namespace mln
template <unsigned D>
inline
void
- face<D>::set_cplx(complex<D>& cplx)
+ face<D>::set_cplx(const complex<D>& cplx)
{
- cplx_ = &cplx;
+ cplx_ = cplx;
}
template <unsigned D>
@@ -303,7 +303,7 @@ namespace mln
{
mln_precondition(n_ == N);
mln_precondition(is_valid());
- return cplx_->template face_data_<N>(face_id_);
+ return cplx_.template face_data_<N>(face_id_);
}
@@ -461,7 +461,7 @@ namespace mln
std::ostream&
operator<<(std::ostream& ostr, const face<D>& f)
{
- return ostr << "(cplx = " << &f.cplx() << ",
dim = " << f.n()
+ return ostr << "(cplx = " << f.cplx().addr() << ",
dim = " << f.n()
<< ", id = " << f.face_id() << ')';
}
diff --git a/milena/mln/topo/n_face.hh b/milena/mln/topo/n_face.hh
index f0a7277..534df69 100644
--- a/milena/mln/topo/n_face.hh
+++ b/milena/mln/topo/n_face.hh
@@ -74,13 +74,13 @@ namespace mln
/// Accessors.
/// \{
/// Return the complex the face belongs to.
- complex<D>& cplx() const;
+ complex<D> cplx() const;
/// Return the id of the face.
// FIXME: Rename as `id'?
unsigned face_id() const;
/// Set the complex the face belongs to.
- void set_cplx(complex<D>& cplx);
+ void set_cplx(const complex<D>& cplx);
/// Return the dimension of the face.
// FIXME: Rename as `dim'?
unsigned n() const;
@@ -99,7 +99,7 @@ namespace mln
/// \brief The complex the face belongs to.
///
/// A const mln::topo::n_face can be used to modify a complex.
- mutable complex<D>* cplx_;
+ mutable complex<D> cplx_;
/// \brief The id of the face.
// FIXME: Rename as `id_'?
unsigned face_id_;
@@ -153,16 +153,17 @@ namespace mln
template <unsigned N, unsigned D>
inline
n_face<N, D>::n_face()
- : cplx_(0), face_id_(std::numeric_limits<unsigned>::max())
+ : cplx_(), face_id_(std::numeric_limits<unsigned>::max())
{
// Ensure N is compatible with D.
metal::bool_< N <= D >::check();
+ mln_postcondition(!is_valid());
}
template <unsigned N, unsigned D>
inline
n_face<N, D>::n_face(complex<D>& c, unsigned face_id)
- : cplx_(&c), face_id_(face_id)
+ : cplx_(c), face_id_(face_id)
{
// Ensure N is compatible with D.
metal::bool_< N <= D >::check();
@@ -173,7 +174,7 @@ namespace mln
bool
n_face<N, D>::is_valid() const
{
- return cplx_ != 0 && face_id_ < cplx_->template nfaces<N>();
+ return face_id_ < cplx_.template nfaces<N>();
}
template <unsigned N, unsigned D>
@@ -186,11 +187,10 @@ namespace mln
template <unsigned N, unsigned D>
inline
- complex<D>&
+ complex<D>
n_face<N, D>::cplx() const
{
- mln_precondition(cplx_);
- return *cplx_;
+ return cplx_;
}
template <unsigned N, unsigned D>
@@ -212,9 +212,9 @@ namespace mln
template <unsigned N, unsigned D>
inline
void
- n_face<N, D>::set_cplx(complex<D>& cplx)
+ n_face<N, D>::set_cplx(const complex<D>& cplx)
{
- cplx_ = &cplx;
+ cplx_ = cplx;
}
template <unsigned N, unsigned D>
@@ -247,7 +247,7 @@ namespace mln
n_face<N, D>::data() const
{
mln_precondition(is_valid());
- return cplx_->template face_data_<N>(face_id_);
+ return cplx_.template face_data_<N>(face_id_);
}
@@ -296,7 +296,7 @@ namespace mln
std::ostream&
operator<<(std::ostream& ostr, const n_face<N, D>& f)
{
- return ostr << "(cplx = " << &f.cplx() << ",
dim = " << f.n()
+ return ostr << "(cplx = " << f.cplx().addr() << ",
dim = " << f.n()
<< ", id = " << f.face_id() << ')';
}
diff --git a/milena/mln/topo/n_faces_set.hh b/milena/mln/topo/n_faces_set.hh
index f0b3615..9b853ba 100644
--- a/milena/mln/topo/n_faces_set.hh
+++ b/milena/mln/topo/n_faces_set.hh
@@ -95,7 +95,7 @@ namespace mln
{
// Check consistency.
if (!faces_.empty())
- mln_precondition(&faces_.front().cplx() == &f.cplx());
+ mln_precondition(faces_.front().cplx() == f.cplx());
faces_.push_back(f);
}
--
1.6.0.1