
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Factor complex and face implementation. * mln/core/face.hh (mln::internal::lower_dim_faces_mixin<N, D>) (mln::internal::higher_dim_faces_mixin<N, D>): New classes. Use them... (mln::face<N, D>): ...here, as mixins. (mln::face<N, D>::connect_lower_dim_face) (mln::face<N, D>::connect_higher_dim_face) (mln::face<D, D>::connect_lower_dim_face) (mln::face<0, D>::connect_higher_dim_face): Remove, and turn into... (mln::internal::lower_dim_faces_mixin<N, D>::connect_lower_dim_face) (mln::internal::higher_dim_faces_mixin<N, D>::connect_higher_dim_face): ...these (new methods). * mln/core/complex.hh (mln::internal::lower_dim_faces_set_mixin<N, D>) (mln::internal::higher_dim_faces_set_mixin<N, D>): New classes. Use them... (mln::internal::faces_set_mixin<N, D>): ...here, as mixins, and (mln::internal::faces_set_mixin<N, D>::print): Factor using these mixins. complex.hh | 126 ++++++++++++++++++++++++++++++++++++++----------------------- face.hh | 112 +++++++++++++++++++++++++++--------------------------- 2 files changed, 136 insertions(+), 102 deletions(-) Index: mln/core/complex.hh --- mln/core/complex.hh (revision 2117) +++ mln/core/complex.hh (working copy) @@ -110,7 +110,6 @@ }; - // FIXME: Move and renamed as mln::debug::println? /// Pretty print a complex. template <unsigned D> std::ostream& @@ -126,51 +125,67 @@ namespace internal { - // FIXME: Factor common things here. + // Forward declarations. + template <unsigned N, unsigned D> struct lower_dim_faces_set_mixin; + template <unsigned N, unsigned D> struct higher_dim_faces_set_mixin; + + + /*---------------------------------. + | mln::internal::faces_set_mixin. | + `---------------------------------*/ /// \brief Recursive mixins of set of faces. /// \{ - template <unsigned N, unsigned D> - struct faces_set_mixin : faces_set_mixin<N - 1, D> + template <unsigned N, unsigned D> struct faces_set_mixin; + + /// Faces of highest dimension (\p D). + template <unsigned D> + struct faces_set_mixin<D, D> : faces_set_mixin<D - 1, D>, + lower_dim_faces_set_mixin<D, D> { - std::vector< face<N, D> > faces_; + std::vector< face<D, D> > faces_; /// Pretty-printing. /// \{ - /// Print the faces of dimension \p N. + /// Print the faces of dimension \p D. void print(std::ostream& ostr) const; - /// Recursively print the faces of dimensions 0 to \p N - /// (in ascending dimension). void print_rec_asc(std::ostream& ostr) const; /// \} }; - template <unsigned D> - struct faces_set_mixin<0u, D> + /// Faces of intermediate dimension (greater than 0, lower than \p D). + template <unsigned N, unsigned D> + struct faces_set_mixin : faces_set_mixin<N - 1, D>, + lower_dim_faces_set_mixin<N, D>, + higher_dim_faces_set_mixin<N, D> { - std::vector< face<0u, D> > faces_; + std::vector< face<N, D> > faces_; /// Pretty-printing. /// \{ - /// Print the faces of dimension 0. + /// Print the faces of dimension \p N. void print(std::ostream& ostr) const; + /// Recursively print the faces of dimensions 0 to \p N + /// (in ascending dimension). void print_rec_asc(std::ostream& ostr) const; /// \} }; + /// Faces of lowest dimension (0). template <unsigned D> - struct faces_set_mixin<D, D> : faces_set_mixin<D - 1, D> + struct faces_set_mixin<0u, D> : higher_dim_faces_set_mixin<0u, D> { - std::vector< face<D, D> > faces_; + std::vector< face<0u, D> > faces_; /// Pretty-printing. /// \{ - /// Print the faces of dimension \p D. + /// Print the faces of dimension 0. void print(std::ostream& ostr) const; void print_rec_asc(std::ostream& ostr) const; /// \} }; + /// Faces of a 0-complex. template <> struct faces_set_mixin<0u, 0u> { @@ -185,6 +200,27 @@ }; /// \} + + /*--------------------------------------------. + | mln::internal::lower_dim_faces_set_mixin. | + | mln::internal::higher_dim_faces_set_mixin. | + `--------------------------------------------*/ + + /// Mixins of mixin mln::faces_set_mixin. + /// \{ + template <unsigned N, unsigned D> + struct lower_dim_faces_set_mixin + { + void print(std::ostream& ostr, const face<N, D>& f) const; + }; + + template <unsigned N, unsigned D> + struct higher_dim_faces_set_mixin + { + void print(std::ostream& ostr, const face<N, D>& f) const; + }; + /// \} + } // end of namespace mln::internal @@ -291,8 +327,6 @@ namespace internal { - // FIXME: Factor common things here. - template <unsigned N, unsigned D> void faces_set_mixin<N, D>::print_rec_asc(std::ostream& ostr) const @@ -322,6 +356,7 @@ print(ostr); } + template <unsigned N, unsigned D> void faces_set_mixin<N, D>::print(std::ostream& ostr) const @@ -333,19 +368,10 @@ for (unsigned f = 0; f < faces_.size(); ++f) { ostr << " " << f << ": dim " << N - 1 << ": { "; - for (typename std::vector< face_handle<N - 1, D> >::const_iterator l = - faces_[f].lower_dim_faces_.begin(); - l != faces_[f].lower_dim_faces_.end(); - ++l) - ostr << l->face_id_ << " "; + lower_dim_faces_set_mixin<N, D>::print(ostr, faces_[f]); ostr << "}, dim " << N + 1 << ": { "; - for (typename std::vector< face_handle<N + 1, D> >::const_iterator h = - faces_[f].higher_dim_faces_.begin(); - h != faces_[f].higher_dim_faces_.end(); - ++h) - ostr << h->face_id_ << " "; - ostr << "}"; - ostr << std::endl; + higher_dim_faces_set_mixin<N, D>::print(ostr, faces_[f]); + ostr << "}" << std::endl; } } @@ -353,7 +379,6 @@ void faces_set_mixin<0u, D>::print(std::ostream& ostr) const { - // FIXME: Much could be factored with the previous routine. const unsigned N = 0u; ostr << "Faces of dimension " << N << " and their ajacent faces of dimension " @@ -361,13 +386,8 @@ for (unsigned f = 0; f < faces_.size(); ++f) { ostr << " " << f << ": dim " << N + 1 << ": { "; - for (typename std::vector< face_handle<N + 1, D> >::const_iterator h = - faces_[f].higher_dim_faces_.begin(); - h != faces_[f].higher_dim_faces_.end(); - ++h) - ostr << h->face_id_ << " "; - ostr << "}"; - ostr << std::endl; + higher_dim_faces_set_mixin<N, D>::print(ostr, faces_[f]); + ostr << "}" << std::endl; } } @@ -375,7 +395,6 @@ void faces_set_mixin<D, D>::print(std::ostream& ostr) const { - // FIXME: Much could be factored with the previous routines. const unsigned N = D; ostr << "Faces of dimension " << N << " and their ajacent faces of dimension " @@ -383,26 +402,41 @@ for (unsigned f = 0; f < faces_.size(); ++f) { ostr << " " << f << ": dim " << N - 1 << ": { "; - for (typename std::vector< face_handle<N - 1, D> >::const_iterator l = - faces_[f].lower_dim_faces_.begin(); - l != faces_[f].lower_dim_faces_.end(); - ++l) - ostr << l->face_id_ << " "; - ostr << "}"; - ostr << std::endl; + lower_dim_faces_set_mixin<N, D>::print(ostr, faces_[f]); + ostr << "}" << std::endl; } } void faces_set_mixin<0u, 0u>::print(std::ostream& ostr) const { - // FIXME: Much could be factored with the previous routines. const unsigned N = 0u; ostr << "Faces of dimension " << N << std::endl; for (unsigned f = 0; f < faces_.size(); ++f) ostr << " " << f << std::endl; } + + template <unsigned N, unsigned D> + void + lower_dim_faces_set_mixin<N, D>::print(std::ostream& ostr, + const face<N, D>& f) const + { + 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_ << " "; + } + + template <unsigned N, unsigned D> + void + higher_dim_faces_set_mixin<N, D>::print(std::ostream& ostr, + const face<N, D>& f) const + { + 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_ << " "; + } + } // end of namespace mln::internal # endif // ! MLN_INCLUDE_ONLY Index: mln/core/face.hh --- mln/core/face.hh (revision 2117) +++ mln/core/face.hh (working copy) @@ -30,8 +30,6 @@ /// \file mln/core/face.hh /// \brief Face of a complex. -/// -/// FIXME: More. #include <vector> @@ -41,13 +39,20 @@ namespace mln { - // Forward declarations. + // Forward declarations (external). template <unsigned D> class complex; + namespace internal + { + template <unsigned N, unsigned D> struct lower_dim_faces_set_mixin; + template <unsigned N, unsigned D> struct higher_dim_faces_set_mixin; + } + + // Forward declarations (internal). template <unsigned N, unsigned D> class face_handle; namespace internal { - template <unsigned N, unsigned D> - struct faces_set_mixin; + template <unsigned N, unsigned D> class lower_dim_faces_mixin; + template <unsigned N, unsigned D> class higher_dim_faces_mixin; } @@ -55,60 +60,65 @@ | Face. | `-------*/ - /* FIXME: we might want to factor connect_{higher,lower}_dim_cell - and {higher,lower_dim_faces_} as member of super classes. */ + /// \p N-face of a \p D-complex. + template <unsigned N, unsigned D> class face; - template <unsigned N, unsigned D> - class face - { - public: - void connect_higher_dim_face(const face_handle<N + 1, D>& f); - void connect_lower_dim_face (const face_handle<N - 1, D>& f); - private: - friend class mln::internal::faces_set_mixin<N, D>; + // Specialization for the faces of highest dimension (D). + template <unsigned D> + class face<D, D> : public internal::lower_dim_faces_mixin<D, D> + { + }; - // FIXME: Provide accessors instead of using `friend' if there are - // clients other than mln::internal::faces_set_mixin<N, D>. - std::vector< face_handle<N + 1, D> > higher_dim_faces_; - std::vector< face_handle<N - 1, D> > lower_dim_faces_; + // Specialization for the faces of intermediate dimension (greater + // than 0, lower than \p D). + template <unsigned N, unsigned D> + class face : public internal::lower_dim_faces_mixin<N, D>, + public internal::higher_dim_faces_mixin<N, D> + { }; // Specialization for the faces of lowest dimension (0). template <unsigned D> - class face<0u, D> + class face<0u, D> : public internal::higher_dim_faces_mixin<0u, D> { - public: - void connect_higher_dim_face(const face_handle<1u, D>& f); - - private: - friend class mln::internal::faces_set_mixin<0, D>; + }; - // FIXME: Provide accessors instead of using `friend; if there are - // clients other than mln::internal::faces_set_mixin<0, D>. - std::vector< face_handle<1u, D> > higher_dim_faces_; + // Specialization for the case of a 0-complex. + template <> + class face<0u, 0u> + { }; - // Specialization for the faces of highest dimension (D). - template <unsigned D> - class face<D, D> + + namespace internal { - public: - void connect_lower_dim_face(const face_handle<1u, D>& f); + /// Factored implementation of faces. + /// \{ + template <unsigned N, unsigned D> + class lower_dim_faces_mixin + { + public: + void connect_lower_dim_face (const face_handle<N - 1, D>& f); private: - friend class mln::internal::faces_set_mixin<D, D>; - - // FIXME: Provide accessors instead of using `friend; if there are - // clients other than mln::internal::faces_set_mixin<0, D>. - std::vector< face_handle<1u, D> > lower_dim_faces_; + friend class mln::internal::lower_dim_faces_set_mixin<N, D>; + std::vector< face_handle<N - 1, D> > lower_dim_faces_; }; - // Specialization for the case of a 0-complex. - template <> - class face<0u, 0u> + template <unsigned N, unsigned D> + class higher_dim_faces_mixin { + public: + void connect_higher_dim_face(const face_handle<N + 1, D>& f); + private: + friend class mln::internal::higher_dim_faces_set_mixin<N, D>; + std::vector< face_handle<N + 1, D> > higher_dim_faces_; }; + /// \} + + } // end of namespace mln::internal + /*--------------. @@ -233,33 +243,23 @@ | Faces. | `--------*/ - template <unsigned N, unsigned D> - void - face<N, D>::connect_higher_dim_face(const face_handle<N + 1, D>& f) + namespace internal { - higher_dim_faces_.push_back(f); - } - template <unsigned N, unsigned D> void - face<N, D>::connect_lower_dim_face(const face_handle<N - 1, D>& f) + 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 D> + template <unsigned N, unsigned D> void - face<0u, D>::connect_higher_dim_face(const face_handle<1u, D>& f) + higher_dim_faces_mixin<N, D>::connect_higher_dim_face(const face_handle<N + 1, D>& f) { higher_dim_faces_.push_back(f); } - template <unsigned D> - void - face<D, D>::connect_lower_dim_face(const face_handle<1u, D>& f) - { - lower_dim_faces_.push_back(f); - } + } // end of namespace mln::internal /*---------------.