2146: Add a missing (disabled) conversion method to mln::any_face_handle.
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Add a missing (disabled) conversion method to mln::any_face_handle. * mln/core/complex.hh: Make mln::any_face_handle a friend of mln::complex. * mln/core/face.hh (mln::any_face_handle<D>::to_face<N>): New method. Exercise it... * tests/core/complex.cc: ...here. Check conversion from handles to face data. mln/core/complex.hh | 1 mln/core/face.hh | 25 ++++++++-------- tests/core/complex.cc | 75 ++++++++++++++++++++++++++++++++------------------ 3 files changed, 61 insertions(+), 40 deletions(-) Index: tests/core/complex.cc --- tests/core/complex.cc (revision 2145) +++ tests/core/complex.cc (working copy) @@ -49,43 +49,64 @@ o-----------o v1----e2----v2 v1 e2 v2 - v = vertex - e = edge - t = triangle + v = vertex (0-face) + e = edge (1-face) + t = triangle (2-face) */ - complex<2> c; + const unsigned D = 2; + + /*-----------------------. + | Complex construction. | + `-----------------------*/ + + complex<D> c; // 0-faces (points). - face_handle<0, 2> v0 = c.add_face(); - face_handle<0, 2> v1 = c.add_face(); - face_handle<0, 2> v2 = c.add_face(); - face_handle<0, 2> v3 = c.add_face(); + face_handle<0, D> v0 = c.add_face(); + face_handle<0, D> v1 = c.add_face(); + face_handle<0, D> v2 = c.add_face(); + face_handle<0, D> v3 = c.add_face(); // 1-faces (segments). - face_handle<1, 2> e0 = c.add_face(v0 + v1); - face_handle<1, 2> e1 = c.add_face(v0 + v2); - face_handle<1, 2> e2 = c.add_face(v1 + v2); - face_handle<1, 2> e3 = c.add_face(v0 + v3); - face_handle<1, 2> e4 = c.add_face(v2 + v3); + face_handle<1, D> e0 = c.add_face(v0 + v1); + face_handle<1, D> e1 = c.add_face(v0 + v2); + face_handle<1, D> e2 = c.add_face(v1 + v2); + face_handle<1, D> e3 = c.add_face(v0 + v3); + face_handle<1, D> e4 = c.add_face(v2 + v3); // 2-faces (triangles). - face_handle<2, 2> t0 = c.add_face(e0 + e1 + e2); - face_handle<2, 2> t1 = c.add_face(e1 + e3 + e4); + face_handle<2, D> t0 = c.add_face(e0 + e1 + e2); + face_handle<2, D> t1 = c.add_face(e1 + e3 + e4); std::cout << c << std::endl; - std::cout << "``Static'' manipulators." << std::endl; - std::cout << " number of 0-faces: " << c.nfaces<0>() << std::endl; - std::cout << " number of 1-faces: " << c.nfaces<1>() << std::endl; - std::cout << " number of 2-faces: " << c.nfaces<2>() << std::endl; - std::cout << " total number of faces: " << c.nfaces() << std::endl; - - std::cout << std::endl; - - std::cout << "``Dynamic'' manipulators." << std::endl; - std::cout << " number of 0-faces: " << c.nfaces(0) << std::endl; - std::cout << " number of 1-faces: " << c.nfaces(1) << std::endl; - std::cout << " number of 2-faces: " << c.nfaces(2) << std::endl; + std::cout + << "Using ``static'' manipulators." << std::endl + << " number of 0-faces: c.nfaces<0>() = " << c.nfaces<0>() << std::endl + << " number of 1-faces: c.nfaces<1>() = " << c.nfaces<1>() << std::endl + << " number of 2-faces: c.nfaces<2>() = " << c.nfaces<2>() << std::endl + << " total number of faces: c.nfaces() = " << c.nfaces() << std::endl + << std::endl; + + std::cout + << "Using ``dynamic'' manipulators." << std::endl + << " number of 0-faces: c.nfaces(0) = " << c.nfaces(0) << std::endl + << " number of 1-faces: c.nfaces(1) = " << c.nfaces(1) << std::endl + << " number of 2-faces: c.nfaces(2) = " << c.nfaces(2) << std::endl; + + /*-------------------. + | Handles and data. | + `-------------------*/ + + // Get the face data from (``static'') face handle E0. + const face<1, D>& face1 = e0.to_face(); + + // Any-face handle. + any_face_handle<D> af(e0); + // Get the face data from (``dynamic'') face handle AF. + const face<1, D>& face2 = af.to_face<1>(); + + mln_assertion(&face1 == &face2); } Index: mln/core/complex.hh --- mln/core/complex.hh (revision 2145) +++ mln/core/complex.hh (working copy) @@ -118,6 +118,7 @@ /// Accessors. /// \{ template <unsigned N, unsigned D_> friend class face_handle; + template <unsigned D_> friend class any_face_handle; template <unsigned N> face<N, D>& face_(unsigned face_id); Index: mln/core/face.hh --- mln/core/face.hh (revision 2145) +++ mln/core/face.hh (working copy) @@ -279,10 +279,9 @@ /// Return the id of the face. unsigned face_id() const; - // FIXME: Implement. -// /// Return the mln::face pointed by this handle. -// template <unsigned N> -// face<N, D>& to_face() const; + /// Return the mln::face pointed by this handle. + template <unsigned N> + face<N, D>& to_face() const; /// \} private: @@ -564,15 +563,15 @@ return face_id_; } -// template <unsigned D> -// template <unsigned n> -// face<N, D>& -// any_face_handle<D>::to_face() const -// { -// // FIXME: Adjust. -// // mln_precondition(is_valid()); -// // return cplx_->template face_<N>(face_id_); -// } + template <unsigned D> + template <unsigned N> + face<N, D>& + any_face_handle<D>::to_face() const + { + mln_precondition(n_ == N); + mln_precondition(is_valid()); + return cplx_->template face_<N>(face_id_); + } template <unsigned D>
participants (1)
-
Roland Levillain