Milena (Olena)  User documentation 2.0a Id
p_faces.hh
00001 // Copyright (C) 2008, 2009, 2011 EPITA Research and Development
00002 // Laboratory (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
00026 
00027 #ifndef MLN_CORE_SITE_SET_P_FACES_HH
00028 # define MLN_CORE_SITE_SET_P_FACES_HH
00029 
00034 
00035 # include <mln/core/internal/site_set_base.hh>
00036 
00037 # include <mln/topo/complex.hh>
00038 
00039 # include <mln/core/faces_psite.hh>
00040 
00041 // FIXME: Disabled (moved to the attic).
00042 # if 0
00043 #  include <mln/core/site_set/p_faces_piter.hh>
00044 # endif
00045 
00046 # include <mln/core/site_set/p_complex.hh>
00047 
00048 
00049 namespace mln
00050 {
00051 
00052   // Forward declarations.
00053   template <unsigned N, unsigned D, typename P> struct p_faces;
00054 
00055   template <unsigned N, unsigned D, typename P> class p_faces_fwd_piter_;
00056   template <unsigned N, unsigned D, typename P> class p_faces_bkd_piter_;
00057 
00058 
00059   namespace trait
00060   {
00061     template <unsigned N, unsigned D, typename P>
00062     struct site_set_< p_faces<N, D, P> >
00063     {
00064       typedef trait::site_set::nsites::known   nsites;
00065       // FIXME: Depends on P!
00066       typedef trait::site_set::bbox::unknown   bbox;
00067       typedef trait::site_set::contents::fixed contents;
00068       typedef trait::site_set::arity::unique   arity;
00069     };
00070   } // end of namespace mln::trait
00071 
00072 
00077   template <unsigned N, unsigned D, typename P>
00078   struct p_faces
00079     : public internal::site_set_base_< faces_psite<N, D, P>,
00080                                        p_faces<N, D, P> >
00081   {
00082     typedef p_faces<N, D, P> self_;
00083     typedef internal::site_set_base_< faces_psite<N, D, P>, self_ > super_;
00084 
00088     p_faces(const topo::complex<D>& cplx);
00089 
00095     p_faces(const p_complex<D, P>& pc);
00096 
00100     typedef mln_site(super_) element;
00101 
00103     typedef faces_psite<N, D, P> psite;
00104 
00105     // FIXME: Fake.
00107     typedef p_faces_fwd_piter_<N, D, P> fwd_piter;
00108 
00109     // FIXME: Fake.
00111     typedef p_faces_bkd_piter_<N, D, P> bkd_piter;
00112 
00114     typedef fwd_piter piter;
00116 
00123     unsigned nsites() const;
00124 
00126     unsigned nfaces() const;
00127 
00128     // FIXME: This method is probably useless now.
00130     bool is_valid() const;
00131 
00132     bool has(const psite& p) const;
00133 
00134     // FIXME: Dummy.
00135     std::size_t memory_size() const;
00136 
00141     /* FIXME: Move back the const qualifier on this return type (see
00142        comment below on cplx_). */
00143     topo::complex<D>& cplx() const;
00146     topo::complex<D>& cplx();
00148 
00149   private:
00151     /* FIXME: Get rid of this `mutable' qualifier.  This is needed for
00152        compatiblity reasons with face_handle (see p_faces_piter).
00153 
00154        We should either
00155 
00156        - have an additional version of face_handle holding a const
00157          (not mutable) complex;
00158 
00159        - have face_handle and any_face_handle do not hold a reference
00160          on a complex, leading to a design of complexes similar to
00161          graphs, where vertex and edge handles (named `id's) are not
00162          tied to a specific graph.  */
00163     mutable topo::complex<D> cplx_;
00164   };
00165 
00166 
00171   template <unsigned N, unsigned D, typename P>
00172   bool
00173   operator==(const p_faces<N, D, P>& lhs, const p_faces<N, D, P>& rhs);
00174 
00183   template <unsigned N, unsigned D, typename P>
00184   bool
00185   operator<=(const p_faces<N, D, P>& lhs, const p_faces<N, D, P>& rhs);
00186 
00187 
00188 
00189 # ifndef MLN_INCLUDE_ONLY
00190 
00191   template <unsigned N, unsigned D, typename P>
00192   inline
00193   p_faces<N, D, P>::p_faces(const topo::complex<D>& cplx)
00194     : cplx_(cplx)
00195   {
00196     // Ensure N is compatible with D.
00197     metal::bool_< N <= D >::check();
00198   }
00199 
00200   template <unsigned N, unsigned D, typename P>
00201   inline
00202   p_faces<N, D, P>::p_faces(const p_complex<D, P>& pc)
00203     : cplx_(pc.cplx())
00204   {
00205     // Ensure N is compatible with D.
00206     metal::bool_< N <= D >::check();
00207   }
00208 
00209   template <unsigned N, unsigned D, typename P>
00210   inline
00211   unsigned
00212   p_faces<N, D, P>::nsites() const
00213   {
00214     return nfaces();
00215   }
00216 
00217   template <unsigned N, unsigned D, typename P>
00218   inline
00219   unsigned
00220   p_faces<N, D, P>::nfaces() const
00221   {
00222     return cplx_.template nfaces_of_static_dim<N>();
00223   }
00224 
00225   template <unsigned N, unsigned D, typename P>
00226   inline
00227   bool
00228   p_faces<N, D, P>::is_valid() const
00229   {
00230     return true;
00231   }
00232 
00233   template <unsigned N, unsigned D, typename P>
00234   inline
00235   bool
00236   p_faces<N, D, P>::has(const psite& p) const
00237   {
00238     mln_precondition(is_valid());
00239     return
00240       // Check whether P's complex is compatible with this pset's complex.
00241       (p.site_set() == *this) &&
00242       // Check whether P is valid.
00243       (p.is_valid());
00244   }
00245 
00246   template <unsigned N, unsigned D, typename P>
00247   inline
00248   std::size_t
00249   p_faces<N, D, P>::memory_size() const
00250   {
00251     // FIXME: Dummy; implement (see other site sets).
00252     abort();
00253     return 0;
00254   }
00255 
00256   template <unsigned N, unsigned D, typename P>
00257   topo::complex<D>&
00258   p_faces<N, D, P>::cplx() const
00259   {
00260     mln_precondition(is_valid());
00261     return cplx_;
00262   }
00263 
00264   template <unsigned N, unsigned D, typename P>
00265   topo::complex<D>&
00266   p_faces<N, D, P>::cplx()
00267   {
00268     mln_precondition(is_valid());
00269     return cplx_;
00270   }
00271 
00272 
00273   /*--------------.
00274   | Comparisons.  |
00275   `--------------*/
00276 
00277   template <unsigned N, unsigned D, typename P>
00278   bool
00279   operator==(const p_faces<N, D, P>& lhs, const p_faces<N, D, P>& rhs)
00280   {
00281     /* FIXME: When actual location data is attached to a p_faces,
00282        check also the equality w.r.t. to these data.  */
00283     return lhs.cplx() == rhs.cplx();
00284   }
00285 
00286   template <unsigned N, unsigned D, typename P>
00287   bool
00288   operator<=(const p_faces<N, D, P>& lhs, const p_faces<N, D, P>& rhs)
00289   {
00290     /* FIXME: When actual location data is attached to a p_faces,
00291        check also the equality w.r.t. to these data.  */
00292     return lhs == rhs;
00293   }
00294 
00295 # endif // ! MLN_INCLUDE_ONLY
00296 
00297 } // end of mln
00298 
00299 #endif // ! MLN_CORE_SITE_SET_P_FACES_HH
 All Classes Namespaces Functions Variables Typedefs Enumerator