• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

p_faces.hh

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

Generated on Tue Oct 4 2011 15:24:15 for Milena (Olena) by  doxygen 1.7.1